@@ -132,11 +132,13 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
132132 [[MMWindowController alloc ] initWithVimController: self ];
133133 backendProxy = [backend retain ];
134134 popupMenuItems = [[NSMutableArray alloc ] init ];
135- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
136135 toolbarItemDict = [[NSMutableDictionary alloc ] init ];
137- touchbarItemDict = [[NSMutableDictionary alloc ] init ];
138- touchbarItemOrder = [[NSMutableArray alloc ] init ];
139- touchbarDisabledItems = [[NSMutableSet alloc ] init ];
136+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
137+ if (NSClassFromString (@" NSTouchBar" )) {
138+ touchbarItemDict = [[NSMutableDictionary alloc ] init ];
139+ touchbarItemOrder = [[NSMutableArray alloc ] init ];
140+ touchbarDisabledItems = [[NSMutableSet alloc ] init ];
141+ }
140142#endif
141143 pid = processIdentifier;
142144 creationDate = [[NSDate alloc ] init ];
@@ -186,7 +188,7 @@ - (void)dealloc
186188
187189 [toolbarItemDict release ]; toolbarItemDict = nil ;
188190 [toolbar release ]; toolbar = nil ;
189- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
191+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
190192 [touchbarItemDict release ]; touchbarItemDict = nil ;
191193 [touchbarItemOrder release ]; touchbarItemOrder = nil ;
192194 [touchbarDisabledItems release ]; touchbarDisabledItems = nil ;
@@ -502,7 +504,7 @@ - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)theToolbar
502504{
503505 return nil ;
504506}
505- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
507+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
506508- (NSTouchBar *)makeTouchBar
507509{
508510 touchbar = [[NSTouchBar alloc ] init ];
@@ -1140,10 +1142,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
11401142
11411143 return ;
11421144 }
1143- # if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1145+
11441146 if ([rootName isEqual: MMTouchbarMenuName])
11451147 return ;
1146- # endif
1148+
11471149 // This is either a main menu item or a popup menu item.
11481150 NSString *title = [desc lastObject ];
11491151 NSMenuItem *item = [[NSMenuItem alloc ] init ];
@@ -1194,13 +1196,15 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
11941196 [self addToolbarItemWithLabel: title tip: tip icon: icon atIndex: idx];
11951197 return ;
11961198 }
1197- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
11981199 if ([rootName isEqual: MMTouchbarMenuName]) {
1199- if ([desc count ] == 2 )
1200- [self addTouchbarItemWithLabel: title icon: icon atIndex: idx];
1200+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1201+ if (NSClassFromString (@" NSTouchBar" )) {
1202+ if ([desc count ] == 2 )
1203+ [self addTouchbarItemWithLabel: title icon: icon atIndex: idx];
1204+ }
1205+ #endif
12011206 return ;
12021207 }
1203- #endif
12041208 NSMenu *parent = [self parentMenuForDescriptor: desc];
12051209 if (!parent) {
12061210 ASLogWarn (@" Menu item '%@ ' has no parent" ,
@@ -1263,17 +1267,19 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc
12631267 }
12641268 return ;
12651269 }
1266- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
12671270 if ([rootName isEqual: MMTouchbarMenuName]){
1268- if ([desc count ] == 2 ) {
1269- [touchbarItemOrder removeObject: title];
1270- [touchbarItemDict removeObjectForKey: title];
1271- [touchbarDisabledItems removeObject: title];
1272- [windowController setTouchBar: nil ];
1271+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1272+ if (NSClassFromString (@" NSTouchBar" )) {
1273+ if ([desc count ] == 2 ) {
1274+ [touchbarItemOrder removeObject: title];
1275+ [touchbarItemDict removeObjectForKey: title];
1276+ [touchbarDisabledItems removeObject: title];
1277+ [windowController setTouchBar: nil ];
1278+ }
12731279 }
1280+ #endif
12741281 return ;
12751282 }
1276- #endif
12771283 NSMenuItem *item = [self menuItemForDescriptor: desc];
12781284 if (!item) {
12791285 ASLogWarn (@" Failed to remove menu item, descriptor not found: %@ " ,
@@ -1308,19 +1314,22 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on
13081314 }
13091315 return ;
13101316 }
1311- # if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1317+
13121318 if ([rootName isEqual: MMTouchbarMenuName]) {
1313- if ([desc count ] == 2 ) {
1314- NSString *title = [desc lastObject ];
1315- if (on)
1316- [touchbarDisabledItems removeObject: title];
1317- else
1318- [touchbarDisabledItems addObject: title];
1319- [windowController setTouchBar: nil ];
1319+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
1320+ if (NSClassFromString (@" NSTouchBar" )) {
1321+ if ([desc count ] == 2 ) {
1322+ NSString *title = [desc lastObject ];
1323+ if (on)
1324+ [touchbarDisabledItems removeObject: title];
1325+ else
1326+ [touchbarDisabledItems addObject: title];
1327+ [windowController setTouchBar: nil ];
1328+ }
13201329 }
1330+ #endif
13211331 return ;
13221332 }
1323- #endif
13241333
13251334 // Use tag to set whether item is enabled or disabled instead of
13261335 // calling setEnabled:. This way the menus can autoenable themselves
@@ -1398,7 +1407,7 @@ - (void)addToolbarItemWithLabel:(NSString *)label
13981407
13991408 [toolbar insertItemWithItemIdentifier: label atIndex: idx];
14001409}
1401- #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1410+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
14021411- (void )addTouchbarItemWithLabel:(NSString *)label
14031412 icon:(NSString *)icon
14041413 atIndex:(int )idx
0 commit comments