Touch Bar add submenu/title/emoji picker support

Can now specify submenus. E.g. TouchBar.Debugger.Run. When trying to
create a submenu it will first create a popover item and then only
create the NSButton at the leaf.

- Unfortunatley macOS currently can't do multiple levels of submenus (the
  API will allow it, but it doesn't really work), presumably for
  usability concerns. Limit it to only one level of nesting for now.

Add ability to set a title on a Touch Bar button, using `tmenu`. This
allows us to override the displayed button name, and when an icon is
specified the override name will still be shown alongside the icon.

Add emoji picker support, and add it to the list of default Touch Bar
menus. Only enable it in modes where the user is typing (insert,
command, terminal, etc).

Fixed up the internal implementation of Touch Bar management so it's
easier to add metadata to it now.

Also, add documentation.

TODO:

- Using `tmenu` after `amenu` doesn't really work (unless it's specified
  in vimrc). This is because MacVim hasn't implemented
  `gui_mch_menu_set_tip`. Should fix it by adding support for it. For
  now, the user can just call `tmenu` before `amenu`.
- Disabling menus currently just hides the menu. Since the user can
  already do `aunmenu` to hide, should change the disable behavior to
  show the button but disabled instead, similar to how toolbars and
  normal menus work.
This commit is contained in:
Yee Cheng Chin
2020-09-08 02:35:53 -07:00
parent a9f6bac901
commit e13d237836
7 changed files with 299 additions and 81 deletions
+36 -8
View File
@@ -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"<CR>
<
You can also create submenus. Due to macOS restrictions, submenus can only be
one level deep: >
:an TouchBar.Navigate.Next :next<CR>
:an TouchBar.Navigate.Prev :prev<CR>
<
*macvim-touchbar-separator*
The separators work similar to how toolbars work: >
:an TouchBar.-Sep- <Nop>
:an TouchBar.-space1- <Nop>
@@ -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 <Nop>
:an icon=NSTouchBarListViewTemplate TouchBar.ShowList :ls<CR>
<
*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 <Nop>
: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- <Nop>
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*
+7
View File
@@ -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()*
+14 -6
View File
@@ -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<CR>
tln icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen <C-W>:set fullscreen<CR>
an icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen<CR>
tln icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen <C-W>:set fullscreen<CR>
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<CR>
tln icon=NSTouchBarExitFullScreenTemplate 1.10 TouchBar.ExitFullScreen <C-W>:set nofullscreen<CR>
an icon=NSTouchBarExitFullScreenTemplate 1.20 TouchBar.ExitFullScreen :set nofullscreen<CR>
tln icon=NSTouchBarExitFullScreenTemplate 1.20 TouchBar.ExitFullScreen <C-W>:set nofullscreen<CR>
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<CR>
tln icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen <C-W>:set fullscreen<CR>
an icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen :set fullscreen<CR>
tln icon=NSTouchBarEnterFullScreenTemplate 1.20 TouchBar.EnterFullScreen <C-W>:set fullscreen<CR>
endif
let s:touchbar_fullscreen = 0
endif
@@ -1360,6 +1360,14 @@ if has("touchbar")
au!
au VimEnter,VimResized * call <SID>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- <Nop>
cnoremenu 1.40 TouchBar.-characterpicker- <Nop>
tlnoremenu 1.40 TouchBar.-characterpicker- <Nop>
endif
endif
" vim: set sw=2 :
+2 -4
View File
@@ -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;
+230 -61
View File
@@ -80,6 +80,38 @@ static BOOL isUnsafeMessage(int msgid);
@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 @@ static BOOL isUnsafeMessage(int msgid);
- (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 @@ static BOOL isUnsafeMessage(int msgid);
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 @@ static BOOL isUnsafeMessage(int msgid);
[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 @@ static BOOL isUnsafeMessage(int msgid);
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
#endif
@end // MMVimController
@implementation MMVimController (Private)
@@ -1178,8 +1206,32 @@ static BOOL isUnsafeMessage(int msgid);
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.<menu_name>
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=<icon_path>" 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 @@ static BOOL isUnsafeMessage(int msgid);
}
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 @@ static BOOL isUnsafeMessage(int msgid);
#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 @@ static BOOL isUnsafeMessage(int msgid);
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 @@ static BOOL isUnsafeMessage(int msgid);
}
#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 @@ static BOOL isUnsafeMessage(int msgid);
}
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 @@ static BOOL isUnsafeMessage(int msgid);
@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
+1 -1
View File
@@ -1083,7 +1083,7 @@
#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]];
+9 -1
View File
@@ -788,7 +788,15 @@ gui_mch_add_menu_item(vimmenu_T *menu, int idx)
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