Skip to content

Commit 2faa285

Browse files
committed
Fix MMTouchBarButton warning when calling "desc" function
Refactor the code so that the relevant class is in header and can be called. Also fix different places where I call NSClassFromString to use @available check instead, as I believe that's the recommended method and more efficient as well (due to it being native to the compiler).
1 parent cd32577 commit 2faa285

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/MacVim/MMVimController.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
@class MMTouchBarInfo;
1616

1717

18+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
19+
/// Button used for Touch Bar support, with an additional metadata to store the
20+
/// Vim command it should send.
21+
@interface MMTouchBarButton : NSButton {
22+
NSArray *_desc;
23+
}
24+
- (NSArray *)desc;
25+
- (void)setDesc:(NSArray *)desc;
26+
@end
27+
#endif
1828

1929
@interface MMVimController : NSObject<
2030
NSToolbarDelegate

src/MacVim/MMVimController.m

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ - (id)initWithItem:(NSTouchBarItem *)item label:(NSString *)label;
102102
- (void)setTouchBarItem:(NSTouchBarItem *)item;
103103
- (void)makeChildTouchBar;
104104
@end
105-
106-
@interface MMTouchBarButton : NSButton {
107-
NSArray *_desc;
108-
}
109-
- (NSArray *)desc;
110-
- (void)setDesc:(NSArray *)desc;
111-
@end
112105
#endif
113106

114107
@interface MMVimController (Private)
@@ -183,7 +176,7 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
183176
popupMenuItems = [[NSMutableArray alloc] init];
184177
toolbarItemDict = [[NSMutableDictionary alloc] init];
185178
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
186-
if (NSClassFromString(@"NSTouchBar")) {
179+
if (@available(macos 10.12.2, *)) {
187180
touchbarInfo = [[MMTouchBarInfo alloc] init];
188181
}
189182
#endif
@@ -1221,7 +1214,7 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
12211214

12221215
if ([rootName isEqual:MMTouchbarMenuName]) {
12231216
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1224-
if (NSClassFromString(@"NSTouchBar")) {
1217+
if (@available(macos 10.12.2, *)) {
12251218
if ([desc count] < 2) // Cannot be 1, as we need at least TouchBar.<menu_name>
12261219
return;
12271220
if ([desc count] >= 3) // Unfortunately currently Apple does not support nested popover's so we can only do one level nesting
@@ -1305,7 +1298,7 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
13051298
if ([desc count] >= 4) // Unfortunately currently Apple does not support nested popover's so we can only do one level nesting
13061299
return;
13071300

1308-
if (NSClassFromString(@"NSTouchBar")) {
1301+
if (@available(macos 10.12.2, *)) {
13091302
MMTouchBarInfo *submenuTouchbar = nil;
13101303
if (![self touchBarItemForDescriptor:desc touchBar:&submenuTouchbar touchBarItem:nil]) {
13111304
return;
@@ -1388,7 +1381,7 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc
13881381
}
13891382
if ([rootName isEqual:MMTouchbarMenuName]){
13901383
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1391-
if (NSClassFromString(@"NSTouchBar")) {
1384+
if (@available(macos 10.12.2, *)) {
13921385
MMTouchBarInfo *submenuTouchbar = nil;
13931386
if (![self touchBarItemForDescriptor:desc touchBar:&submenuTouchbar touchBarItem:nil]) {
13941387
return;
@@ -1442,7 +1435,7 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on
14421435

14431436
if ([rootName isEqual:MMTouchbarMenuName]) {
14441437
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1445-
if (NSClassFromString(@"NSTouchBar")) {
1438+
if (@available(macos 10.12.2, *)) {
14461439
MMTouchBarItemInfo *touchbarItem = nil;
14471440
if (![self touchBarItemForDescriptor:desc touchBar:nil touchBarItem:&touchbarItem]) {
14481441
return;
@@ -1481,7 +1474,7 @@ - (void)updateMenuItemTooltipWithDescriptor:(NSArray *)desc
14811474

14821475
if ([rootName isEqual:MMTouchbarMenuName]) {
14831476
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1484-
if (NSClassFromString(@"NSTouchBar")) {
1477+
if (@available(macos 10.12.2, *)) {
14851478
MMTouchBarItemInfo *touchbarItem = nil;
14861479
if (![self touchBarItemForDescriptor:desc touchBar:nil touchBarItem:&touchbarItem]) {
14871480
return;

src/MacVim/MMWindowController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,8 @@ - (IBAction)vimToolbarItemAction:(id)sender
11141114
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
11151115
- (IBAction)vimTouchbarItemAction:(id)sender
11161116
{
1117-
NSArray *desc = [sender desc];
1117+
MMTouchBarButton *button = (MMTouchBarButton*)sender;
1118+
NSArray *desc = [button desc];
11181119
NSDictionary *attrs = [NSDictionary dictionaryWithObject:desc
11191120
forKey:@"descriptor"];
11201121
[vimController sendMessage:ExecuteMenuMsgID data:[attrs dictionaryAsData]];

0 commit comments

Comments
 (0)