diff --git a/runtime/doc/gui_mac.txt b/runtime/doc/gui_mac.txt index be74081c98..494812130b 100644 --- a/runtime/doc/gui_mac.txt +++ b/runtime/doc/gui_mac.txt @@ -514,10 +514,17 @@ icon can be found a warning triangle is displayed instead. ============================================================================== 8. Touch Bar *macvim-touchbar* -Touch Bar in MacVim works similar to the toolbar (see |macvim-toolbar|). The -difference is that you use the special menu "TouchBar" instead of "ToolBar": > +Touch Bar in MacVim is configurable, and works similar to the toolbar (see +|macvim-toolbar|). The difference is that you use the special menu "TouchBar" +instead of "ToolBar": > :an TouchBar.Hello :echo "Hello" - +< +You can also create submenus. Due to macOS restrictions, submenus can only be +one level deep: > + :an TouchBar.Navigate.Next :next + :an TouchBar.Navigate.Prev :prev +< + *macvim-touchbar-separator* The separators work similar to how toolbars work: > :an TouchBar.-Sep- :an TouchBar.-space1- @@ -530,24 +537,45 @@ separator and are specified by names that begin with "-space" and ends with that items after it will be right-aligned, and is specified by names that begin with "-flexspace" and ends with "-". + *macvim-touchbar-icon* You can specify icons for Touch Bar buttons the same way for toolbar icons. Touch Bar icons should ideally be 36x36 pixels, and no larger than 44x44 pixels. You can also use default template icons provided by Apple by using their template names. An example: > - :an icon=NSTouchBarListViewTemplate TouchBar.ShowList + :an icon=NSTouchBarListViewTemplate TouchBar.ShowList :ls +< + *macvim-touchbar-title* +By default, the TouchBar buttons will use the menu names as the title. If an +icon is specified, the title will not be shown. You can override this by using +|tmenu| to set a tooltip. The tooltip will be displayed as the title of the +button. If an icon is specified, the tooltip override will be shown alongside +the icion. Example: > + :an icon=NSTouchBarAddTemplate TouchBar.AddItem + :tmenu TouchBar.AddItem Add an Item +< + *macvim-touchbar-characterpicker* *macvim-touchbar-emoji* +You can also insert emojis by adding a character picker button (specified by +using a name that begin wtih "-characterpicker" and ends with "-"): > + :inoremenu TouchBar.-characterpicker- This feature only works on Mac devices that come with Touch Bars. On the ones that don't, nothing will show up. - *macvim-touchbar-defaults* + *macvim-touchbar-defaults* Here is a list of default Touch Bar buttons that MacVim sets up: - *macvim-touchbar-fullscreen* + *macvim-touchbar-fullscreen* *g:macvim_default_touchbar_fullscreen* EnterFullScreen Touch Bar buttons that allow you to toggle -ExitFullScreen |'fullscreen'| mode. To disable the button, add the - following to your vimrc file: > +ExitFullScreen |'fullscreen'| mode. To disable, add the following to + your vimrc file: > let g:macvim_default_touchbar_fullscreen=0 +< + *g:macvim_default_touchbar_characterpicker* +-characterpicker- Character picker that lets you add special characters + and emojis in insert and terminal modes. To disable, + add the following to your vimrc file: > + let g:macvim_default_touchbar_characterpicker=0 ============================================================================== 9. Dialogs *macvim-dialogs* diff --git a/runtime/doc/tags b/runtime/doc/tags index 3401f3043b..cd7e803195 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -6801,6 +6801,7 @@ g:html_use_encoding syntax.txt /*g:html_use_encoding* g:html_use_input_for_pc syntax.txt /*g:html_use_input_for_pc* g:html_use_xhtml syntax.txt /*g:html_use_xhtml* g:html_whole_filler syntax.txt /*g:html_whole_filler* +g:macvim_default_touchbar_characterpicker gui_mac.txt /*g:macvim_default_touchbar_characterpicker* g:macvim_default_touchbar_fullscreen gui_mac.txt /*g:macvim_default_touchbar_fullscreen* g:netrw_altfile pi_netrw.txt /*g:netrw_altfile* g:netrw_alto pi_netrw.txt /*g:netrw_alto* @@ -7803,8 +7804,13 @@ macvim-tablabel gui_mac.txt /*macvim-tablabel* macvim-todo gui_mac.txt /*macvim-todo* macvim-toolbar gui_mac.txt /*macvim-toolbar* macvim-touchbar gui_mac.txt /*macvim-touchbar* +macvim-touchbar-characterpicker gui_mac.txt /*macvim-touchbar-characterpicker* macvim-touchbar-defaults gui_mac.txt /*macvim-touchbar-defaults* +macvim-touchbar-emoji gui_mac.txt /*macvim-touchbar-emoji* macvim-touchbar-fullscreen gui_mac.txt /*macvim-touchbar-fullscreen* +macvim-touchbar-icon gui_mac.txt /*macvim-touchbar-icon* +macvim-touchbar-separator gui_mac.txt /*macvim-touchbar-separator* +macvim-touchbar-title gui_mac.txt /*macvim-touchbar-title* macvim-url-handler gui_mac.txt /*macvim-url-handler* macvim-user-defaults gui_mac.txt /*macvim-user-defaults* macvim-window-title gui_mac.txt /*macvim-window-title* @@ -8618,6 +8624,7 @@ progname-variable eval.txt /*progname-variable* progpath-variable eval.txt /*progpath-variable* progress.vim syntax.txt /*progress.vim* prompt-buffer channel.txt /*prompt-buffer* +prompt_getprompt() eval.txt /*prompt_getprompt()* prompt_setcallback() eval.txt /*prompt_setcallback()* prompt_setinterrupt() eval.txt /*prompt_setinterrupt()* prompt_setprompt() eval.txt /*prompt_setprompt()* diff --git a/runtime/menu.vim b/runtime/menu.vim index 05e0254a05..8520c4f385 100644 --- a/runtime/menu.vim +++ b/runtime/menu.vim @@ -1332,8 +1332,8 @@ if has("touchbar") " 1. Smart fullscreen icon that toggles between going full screen or not. if !exists("g:macvim_default_touchbar_fullscreen") || g:macvim_default_touchbar_fullscreen - an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen - tln icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen + an icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen + tln icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen endif let s:touchbar_fullscreen=0 @@ -1342,16 +1342,16 @@ if has("touchbar") silent! aun TouchBar.EnterFullScreen silent! tlun TouchBar.EnterFullScreen if !exists("g:macvim_default_touchbar_fullscreen") || g:macvim_default_touchbar_fullscreen - an icon=NSTouchBarExitFullScreenTemplate 1.10 TouchBar.ExitFullScreen :set nofullscreen - tln icon=NSTouchBarExitFullScreenTemplate 1.10 TouchBar.ExitFullScreen :set nofullscreen + an icon=NSTouchBarExitFullScreenTemplate 1.20 TouchBar.ExitFullScreen :set nofullscreen + tln icon=NSTouchBarExitFullScreenTemplate 1.20 TouchBar.ExitFullScreen :set nofullscreen endif let s:touchbar_fullscreen = 1 elseif !&fullscreen && s:touchbar_fullscreen != 0 silent! aun TouchBar.ExitFullScreen silent! tlun TouchBar.ExitFullScreen if !exists("g:macvim_default_touchbar_fullscreen") || g:macvim_default_touchbar_fullscreen - an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen - tln icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen + an icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen + tln icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen endif let s:touchbar_fullscreen = 0 endif @@ -1360,6 +1360,14 @@ if has("touchbar") au! au VimEnter,VimResized * call SetupFullScreenTouchBar() aug END + + " 2. Character (i.e. emojis) picker. Only in modes where user is actively + " entering text. + if !exists("g:macvim_default_touchbar_characterpicker") || g:macvim_default_touchbar_characterpicker + inoremenu 1.40 TouchBar.-characterpicker- + cnoremenu 1.40 TouchBar.-characterpicker- + tlnoremenu 1.40 TouchBar.-characterpicker- + endif endif " vim: set sw=2 : diff --git a/src/MacVim/MMVimController.h b/src/MacVim/MMVimController.h index b93295ae44..7a0fc4cd46 100644 --- a/src/MacVim/MMVimController.h +++ b/src/MacVim/MMVimController.h @@ -12,6 +12,7 @@ @class MMWindowController; +@class MMTouchBarInfo; @@ -34,10 +35,7 @@ NSToolbar *toolbar; NSMutableDictionary *toolbarItemDict; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 - NSTouchBar *touchbar; - NSMutableDictionary *touchbarItemDict; - NSMutableArray *touchbarItemOrder; - NSMutableSet *touchbarDisabledItems; + MMTouchBarInfo *touchbarInfo; #endif int pid; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index e36acc520d..11bec5c500 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -80,6 +80,38 @@ - (void)beginSheetModalForWindow:(NSWindow *)window @end +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 +@interface MMTouchBarInfo : NSObject; + +@property (readonly) NSTouchBar *touchbar; +@property (readonly) NSMutableDictionary *itemDict; +@property (readonly) NSMutableArray *itemOrder; + +- (id)initWithVimController:(MMVimController *)controller; + +@end + +@interface MMTouchBarItemInfo : NSObject; + +@property (readonly) NSTouchBarItem *touchbarItem; +@property (readwrite) BOOL enabled; +@property (readonly) NSString *label; + +@property (readonly) MMTouchBarInfo *childTouchbar; // Set when this is a submenu + +- (id)initWithItem:(NSTouchBarItem *)item label:(NSString *)label; +- (void)setTouchBarItem:(NSTouchBarItem *)item; +- (void)makeChildTouchBar; +@end + +@interface MMTouchBarButton : NSButton { + NSArray *_desc; +} +- (NSArray *)desc; +- (void)setDesc:(NSArray *)desc; +@end +#endif + @interface MMVimController (Private) - (void)doProcessInputQueue:(NSArray *)queue; - (void)handleMessage:(int)msgid data:(NSData *)data; @@ -105,6 +137,13 @@ - (void)addToolbarItemToDictionaryWithLabel:(NSString *)title - (void)addToolbarItemWithLabel:(NSString *)label tip:(NSString *)tip icon:(NSString *)icon atIndex:(int)idx; +- (void)addTouchbarItemWithLabel:(NSString *)label + icon:(NSString *)icon + tip:(NSString *)tip + atIndex:(int)idx + isSubMenu:(BOOL)submenu + desc:(NSArray *)desc + atTouchBar:(MMTouchBarInfo *)touchbarInfo; - (void)popupMenuWithDescriptor:(NSArray *)desc atRow:(NSNumber *)row column:(NSNumber *)col; @@ -137,9 +176,7 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier toolbarItemDict = [[NSMutableDictionary alloc] init]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 if (NSClassFromString(@"NSTouchBar")) { - touchbarItemDict = [[NSMutableDictionary alloc] init]; - touchbarItemOrder = [[NSMutableArray alloc] init]; - touchbarDisabledItems = [[NSMutableSet alloc] init]; + touchbarInfo = [[MMTouchBarInfo alloc] init]; } #endif pid = processIdentifier; @@ -195,10 +232,7 @@ - (void)dealloc [toolbarItemDict release]; toolbarItemDict = nil; [toolbar release]; toolbar = nil; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 - [touchbarItemDict release]; touchbarItemDict = nil; - [touchbarItemOrder release]; touchbarItemOrder = nil; - [touchbarDisabledItems release]; touchbarDisabledItems = nil; - [touchbar release]; touchbar = nil; + [touchbarInfo release]; touchbarInfo = nil; #endif [popupMenuItems release]; popupMenuItems = nil; [windowController release]; windowController = nil; @@ -535,47 +569,41 @@ - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)theToolbar return nil; } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 -- (NSTouchBar *)makeTouchBar +- (NSTouchBar *)makeTouchBarOn:(MMTouchBarInfo *)touchbarInfo { - touchbar = [[NSTouchBar alloc] init]; - touchbar.delegate = self; - NSMutableArray *filteredTouchbarItemOrder = [NSMutableArray array]; - for (NSString *label in touchbarItemOrder) { - if (![touchbarDisabledItems containsObject:label]) { - if ([touchbarItemDict objectForKey:label] == nil) { - // The label begins and ends with '-'; decided which kind of separator - // item it is by looking at the prefix. - if ([label hasPrefix:@"-space"]) { - label = NSTouchBarItemIdentifierFixedSpaceSmall; - } else if ([label hasPrefix:@"-flexspace"]) { - label = NSTouchBarItemIdentifierFlexibleSpace; - } else { - label = NSTouchBarItemIdentifierFixedSpaceLarge; + NSMutableSet *filteredItems = [NSMutableSet set]; + for (NSString *label in touchbarInfo.itemOrder) { + MMTouchBarItemInfo *itemInfo = [touchbarInfo.itemDict objectForKey:label]; + if ([itemInfo enabled]) { + [filteredTouchbarItemOrder addObject:[itemInfo label]]; + + if ([itemInfo touchbarItem]) { + if ([itemInfo childTouchbar]) { + NSTouchBar *childTouchbar = [self makeTouchBarOn:[itemInfo childTouchbar]]; + NSPopoverTouchBarItem *popoverItem = (NSPopoverTouchBarItem *)[itemInfo touchbarItem]; + [popoverItem setPopoverTouchBar:childTouchbar]; } - } - [filteredTouchbarItemOrder addObject:label]; + [filteredItems addObject:itemInfo.touchbarItem]; + } } } [filteredTouchbarItemOrder addObject:NSTouchBarItemIdentifierOtherItemsProxy]; - - touchbar.defaultItemIdentifiers = filteredTouchbarItemOrder; - return touchbar; + + touchbarInfo.touchbar.defaultItemIdentifiers = filteredTouchbarItemOrder; + touchbarInfo.touchbar.templateItems = filteredItems; + return touchbarInfo.touchbar; } -- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)itemId +- (NSTouchBar *)makeTouchBar { - NSTouchBarItem *item = [touchbarItemDict objectForKey:itemId]; - if (!item) { - ASLogWarn(@"No touchbar item with id '%@'", itemId); - } - - return item; + return [self makeTouchBarOn:touchbarInfo]; } + #endif -@end // MMVimController +@end // MMVimController @implementation MMVimController (Private) @@ -1178,8 +1206,32 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx return; } - if ([rootName isEqual:MMTouchbarMenuName]) + if ([rootName isEqual:MMTouchbarMenuName]) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 + if (NSClassFromString(@"NSTouchBar")) { + if ([desc count] < 2) // Cannot be 1, as we need at least TouchBar. + return; + if ([desc count] >= 3) // Unfortunately currently Apple does not support nested popover's so we can only do one level nesting + return; + + MMTouchBarInfo *submenuTouchbar = touchbarInfo; + for (int i = 1; i < [desc count] - 1; i++) { + NSString *submenuName = [desc objectAtIndex:i]; + MMTouchBarItemInfo *submenu = [[submenuTouchbar itemDict] objectForKey:submenuName]; + if ([submenu childTouchbar]) { + submenuTouchbar = [submenu childTouchbar]; + } else { + ASLogWarn(@"No Touch Bar submenu with id '%@'", submenuName); + return; + } + } + // Icon is not supported for Touch Bar submenu for now, as "amenu" does not have a way of specifying "icon=" for submenus. + NSString *title = [desc lastObject]; + [self addTouchbarItemWithLabel:title icon:nil tip:nil atIndex:idx isSubMenu:YES desc:desc atTouchBar:submenuTouchbar]; + } +#endif return; + } // This is either a main menu item or a popup menu item. NSString *title = [desc lastObject]; @@ -1233,9 +1285,22 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc } if ([rootName isEqual:MMTouchbarMenuName]) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 + if ([desc count] >= 4) // Unfortunately currently Apple does not support nested popover's so we can only do one level nesting + return; + if (NSClassFromString(@"NSTouchBar")) { - if ([desc count] == 2) - [self addTouchbarItemWithLabel:title icon:icon atIndex:idx]; + MMTouchBarInfo *submenuTouchbar = touchbarInfo; + for (int i = 1; i < [desc count] - 1; i++) { + NSString *submenuName = [desc objectAtIndex:i]; + MMTouchBarItemInfo *submenu = [[submenuTouchbar itemDict] objectForKey:submenuName]; + if ([submenu childTouchbar]) { + submenuTouchbar = [submenu childTouchbar]; + } else { + ASLogWarn(@"No Touch Bar submenu with id '%@'", submenuName); + return; + } + } + [self addTouchbarItemWithLabel:title icon:icon tip:tip atIndex:idx isSubMenu:NO desc:desc atTouchBar:submenuTouchbar]; } #endif return; @@ -1306,9 +1371,8 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 if (NSClassFromString(@"NSTouchBar")) { if ([desc count] == 2) { - [touchbarItemOrder removeObject:title]; - [touchbarItemDict removeObjectForKey:title]; - [touchbarDisabledItems removeObject:title]; + [[touchbarInfo itemOrder] removeObject:title]; + [[touchbarInfo itemDict] removeObjectForKey:title]; [windowController setTouchBar:nil]; } } @@ -1355,10 +1419,7 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on if (NSClassFromString(@"NSTouchBar")) { if ([desc count] == 2) { NSString *title = [desc lastObject]; - if (on) - [touchbarDisabledItems removeObject:title]; - else - [touchbarDisabledItems addObject:title]; + [[touchbarInfo.itemDict objectForKey:title] setEnabled:on]; [windowController setTouchBar:nil]; } } @@ -1444,19 +1505,43 @@ - (void)addToolbarItemWithLabel:(NSString *)label } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 - (void)addTouchbarItemWithLabel:(NSString *)label - icon:(NSString *)icon - atIndex:(int)idx + icon:(NSString *)icon + tip:(NSString *)tip + atIndex:(int)idx + isSubMenu:(BOOL)submenu + desc:(NSArray *)desc + atTouchBar:(MMTouchBarInfo *)touchbarInfo { - // Check for separator items. - if (!label) { - label = NSTouchBarItemIdentifierFixedSpaceLarge; - } else if ([label length] >= 2 && [label hasPrefix:@"-"] - && [label hasSuffix:@"-"]) { - // These will be converted to fixed/flexible space identifiers later, when "makeTouchBar" is called. + NSString *touchbarLabel = label; + NSTouchBarItem *touchbarItem = nil; + + // Check for separator / special items first + if ([label length] >= 2 && [label hasPrefix:@"-"] + && [label hasSuffix:@"-"]) { + // The label begins and ends with '-'; decided which kind of separator + // or special item it is by looking at the prefix. + if ([label hasPrefix:@"-characterpicker"]) { + touchbarLabel = NSTouchBarItemIdentifierCharacterPicker; + } + else if ([label hasPrefix:@"-space"]) { + touchbarLabel = NSTouchBarItemIdentifierFixedSpaceSmall; + } else if ([label hasPrefix:@"-flexspace"]) { + touchbarLabel = NSTouchBarItemIdentifierFlexibleSpace; + } else { + touchbarLabel = NSTouchBarItemIdentifierFixedSpaceLarge; + } + } else if (submenu) { + NSPopoverTouchBarItem *item = [[[NSPopoverTouchBarItem alloc] initWithIdentifier:label] autorelease]; + // Icons not supported for now until we find a way to send the information in from Vim + [item setCollapsedRepresentationLabel:label]; + touchbarItem = item; } else { - NSButton* button = [NSButton buttonWithTitle:label target:windowController action:@selector(vimTouchbarItemAction:)]; + BOOL useTip = tip && [tip length] != 0; + NSString *buttonTitle = useTip ? tip : label; + MMTouchBarButton* button = [MMTouchBarButton buttonWithTitle:buttonTitle target:windowController action:@selector(vimTouchbarItemAction:)]; + [button setDesc:desc]; NSCustomTouchBarItem *item = - [[NSCustomTouchBarItem alloc] initWithIdentifier:label]; + [[[NSCustomTouchBarItem alloc] initWithIdentifier:label] autorelease]; NSImage *img = [NSImage imageNamed:icon]; if (!img) { @@ -1466,17 +1551,27 @@ - (void)addTouchbarItemWithLabel:(NSString *)label } if (img) { [button setImage: img]; - //[button setImagePosition:NSImageLeft]; - [button setImagePosition:NSImageOnly]; + if (useTip) { + // If the user has set a tooltip as label that means they always want to see it, so show both image and tooltip + [button setImagePosition:NSImageLeft]; + } else { + [button setImagePosition:NSImageOnly]; + } } [item setView:button]; - [touchbarItemDict setObject:item forKey:label]; + touchbarItem = item; + } + + MMTouchBarItemInfo *touchbarItemInfo = [[MMTouchBarItemInfo alloc] initWithItem:touchbarItem label:touchbarLabel]; + if (submenu) { + [touchbarItemInfo makeChildTouchBar]; } + [touchbarInfo.itemDict setObject:touchbarItemInfo forKey:label]; - int maxIdx = [touchbarItemOrder count]; + int maxIdx = [touchbarInfo.itemOrder count]; if (maxIdx < idx) idx = maxIdx; - [touchbarItemOrder insertObject:label atIndex:idx]; + [touchbarInfo.itemOrder insertObject:label atIndex:idx]; [windowController setTouchBar:nil]; } @@ -1793,7 +1888,81 @@ - (void)beginSheetModalForWindow:(NSWindow *)window @end // MMAlert +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 + +@implementation MMTouchBarInfo + +- (id)init +{ + _touchbar = [[NSTouchBar alloc] init]; + + _itemDict = [[NSMutableDictionary alloc] init]; + _itemOrder = [[NSMutableArray alloc] init]; + return self; +} + +- (void)dealloc +{ + [_touchbar release]; _touchbar = nil; + + [_itemDict release]; _itemDict = nil; + [_itemOrder release]; _itemOrder = nil; + [super dealloc]; +} + +@end // MMTouchBarInfo +@implementation MMTouchBarItemInfo + +- (void)dealloc +{ + [_touchbarItem release]; _touchbarItem = nil; + [_label release]; _label = nil; + [_childTouchbar release]; _childTouchbar = nil; + [super dealloc]; +} + +- (id)initWithItem:(NSTouchBarItem *)item label:(NSString *)label +{ + _touchbarItem = [item retain]; + _enabled = YES; + _label = [label retain]; + return self; +} + +- (void)setTouchBarItem:(NSTouchBarItem *)item +{ + _touchbarItem = item; +} + +- (void)makeChildTouchBar +{ + _childTouchbar = [[MMTouchBarInfo alloc] init]; +} + +@end // MMTouchBarItemInfo + +@implementation MMTouchBarButton + +- (void)dealloc +{ + [_desc release]; _desc = nil; + [super dealloc]; +} + +- (NSArray *)desc +{ + return _desc; +} + +- (void)setDesc:(NSArray *)desc +{ + _desc = [desc retain]; +} + +@end // MMTouchBarButton + +#endif static BOOL diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 46545be4fd..3bb1ff0cf4 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -1083,7 +1083,7 @@ - (IBAction)vimToolbarItemAction:(id)sender #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2 - (IBAction)vimTouchbarItemAction:(id)sender { - NSArray *desc = [NSArray arrayWithObjects:@"TouchBar", [sender title], nil]; + NSArray *desc = [sender desc]; NSDictionary *attrs = [NSDictionary dictionaryWithObject:desc forKey:@"descriptor"]; [vimController sendMessage:ExecuteMenuMsgID data:[attrs dictionaryAsData]]; diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 2c1086a282..4c388afc4d 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -788,7 +788,15 @@ int modifierMask = vimModMaskToEventModifierFlags(menu->mac_mods); char_u *icon = NULL; - if (menu_is_toolbar(menu->parent->name)) { + vimmenu_T *rootMenu = menu; + while (rootMenu->parent) { + rootMenu = rootMenu->parent; + } + if (menu_is_toolbar(rootMenu->name)) { + // + // Find out what file to load for the icon. This is only relevant for the + // toolbar and TouchBar. + // char_u fname[MAXPATHL]; // Try to use the icon=.. argument