-
-
Notifications
You must be signed in to change notification settings - Fork 685
MBP Touchbar Support #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MBP Touchbar Support #568
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
|
||
@interface MMVimController : NSObject<NSToolbarDelegate, | ||
NSOpenSavePanelDelegate> | ||
NSOpenSavePanelDelegate, NSTouchBarDelegate> | ||
{ | ||
unsigned identifier; | ||
BOOL isInitialized; | ||
|
@@ -28,6 +28,11 @@ | |
// TODO: Move all toolbar code to window controller? | ||
NSToolbar *toolbar; | ||
NSMutableDictionary *toolbarItemDict; | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indenting on this preprocessor line (and the corresponding |
||
NSTouchBar *touchbar; | ||
NSMutableDictionary *touchbarItemDict; | ||
NSMutableArray *touchbarItemOrder; | ||
#endif | ||
|
||
int pid; | ||
NSString *serverName; | ||
|
@@ -65,4 +70,7 @@ | |
- (id)evaluateVimExpressionCocoa:(NSString *)expr | ||
errorString:(NSString **)errstr; | ||
- (void)processInputQueue:(NSArray *)queue; | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
- (NSTouchBar *)makeTouchBar; | ||
#endif | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,11 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier | |
[[MMWindowController alloc] initWithVimController:self]; | ||
backendProxy = [backend retain]; | ||
popupMenuItems = [[NSMutableArray alloc] init]; | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indent on this |
||
toolbarItemDict = [[NSMutableDictionary alloc] init]; | ||
touchbarItemDict = [[NSMutableDictionary alloc] init]; | ||
touchbarItemOrder = [[NSMutableArray alloc] init]; | ||
#endif | ||
pid = processIdentifier; | ||
creationDate = [[NSDate alloc] init]; | ||
|
||
|
@@ -178,6 +182,11 @@ - (void)dealloc | |
|
||
[toolbarItemDict release]; toolbarItemDict = nil; | ||
[toolbar release]; toolbar = nil; | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indent on this |
||
[touchbarItemDict release]; touchbarItemDict = nil; | ||
[touchbarItemOrder release]; touchbarItemOrder = nil; | ||
[touchbar release]; touchbar = nil; | ||
#endif | ||
[popupMenuItems release]; popupMenuItems = nil; | ||
[windowController release]; windowController = nil; | ||
|
||
|
@@ -488,7 +497,25 @@ - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)theToolbar | |
{ | ||
return nil; | ||
} | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
- (NSTouchBar *)makeTouchBar | ||
{ | ||
touchbar = [[NSTouchBar alloc] init]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 503 - 506 have mixed tab/space indenting and are too far in. |
||
touchbar.delegate = self; | ||
touchbar.defaultItemIdentifiers = [NSArray arrayWithArray: touchbarItemOrder]; | ||
return touchbar; | ||
} | ||
|
||
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)itemId | ||
{ | ||
NSTouchBarItem *item = [touchbarItemDict objectForKey:itemId]; | ||
if (!item) { | ||
ASLogWarn(@"No touchbar item with id '%@'", itemId); | ||
} | ||
|
||
return item; | ||
} | ||
#endif | ||
@end // MMVimController | ||
|
||
|
||
|
@@ -1081,7 +1108,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx | |
|
||
return; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indent of this |
||
if ([rootName isEqual:@"TouchBar"]) | ||
return; | ||
#endif | ||
// This is either a main menu item or a popup menu item. | ||
NSString *title = [desc lastObject]; | ||
NSMenuItem *item = [[NSMenuItem alloc] init]; | ||
|
@@ -1132,7 +1162,13 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc | |
[self addToolbarItemWithLabel:title tip:tip icon:icon atIndex:idx]; | ||
return; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
if ([rootName isEqual:@"TouchBar"]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point it might be worth writing |
||
if (toolbar && [desc count] == 2) | ||
[self addTouchbarItemWithLabel:title icon:icon atIndex:idx]; | ||
return; | ||
} | ||
#endif | ||
NSMenu *parent = [self parentMenuForDescriptor:desc]; | ||
if (!parent) { | ||
ASLogWarn(@"Menu item '%@' has no parent", | ||
|
@@ -1195,7 +1231,16 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc | |
} | ||
return; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
if ([rootName isEqual:@"TouchBar"]){ | ||
if ([desc count] == 2) { | ||
[touchbarItemOrder removeObject:title]; | ||
[touchbarItemDict removeObjectForKey:title]; | ||
[windowController setTouchBar:nil]; | ||
} | ||
return; | ||
} | ||
#endif | ||
NSMenuItem *item = [self menuItemForDescriptor:desc]; | ||
if (!item) { | ||
ASLogWarn(@"Failed to remove menu item, descriptor not found: %@", | ||
|
@@ -1228,7 +1273,11 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on | |
NSString *title = [desc lastObject]; | ||
[[toolbar itemWithItemIdentifier:title] setEnabled:on]; | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity, this should be written in a way that doesn't inject the preprocessor check between the
|
||
} else | ||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
if (![rootName isEqual:@"TouchBar"]) | ||
#endif | ||
{ | ||
// Use tag to set whether item is enabled or disabled instead of | ||
// calling setEnabled:. This way the menus can autoenable themselves | ||
// but at the same time Vim can set if a menu is enabled whenever it | ||
|
@@ -1306,7 +1355,53 @@ - (void)addToolbarItemWithLabel:(NSString *)label | |
|
||
[toolbar insertItemWithItemIdentifier:label atIndex:idx]; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
- (void)addTouchbarItemWithLabel:(NSString *)label | ||
icon:(NSString *)icon | ||
atIndex:(int)idx | ||
{ | ||
// Check for separator items. | ||
if (!label) { | ||
label = NSTouchBarItemIdentifierFixedSpaceLarge; | ||
} else if ([label length] >= 2 && [label hasPrefix:@"-"] | ||
&& [label hasSuffix:@"-"]) { | ||
// 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; | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole |
||
NSButton* button = [NSButton buttonWithTitle:label target:windowController action:@selector(vimTouchbarItemAction:)]; | ||
NSCustomTouchBarItem *item = | ||
[[NSCustomTouchBarItem alloc] initWithIdentifier:label]; | ||
NSImage *img = [NSImage imageNamed:icon]; | ||
|
||
if (!img) { | ||
img = [[[NSImage alloc] initByReferencingFile:icon] autorelease]; | ||
if (!(img && [img isValid])) | ||
img = nil; | ||
} | ||
if (img) { | ||
[button setImage: img]; | ||
//[button setImagePosition:NSImageLeft]; | ||
[button setImagePosition:NSImageOnly]; | ||
} | ||
|
||
[item setView:button]; | ||
[touchbarItemDict setObject:item forKey:label]; | ||
} | ||
|
||
int maxIdx = [touchbarItemOrder count]; | ||
if (maxIdx < idx) idx = maxIdx; | ||
[touchbarItemOrder insertObject:label atIndex:idx]; | ||
|
||
[windowController setTouchBar:nil]; | ||
} | ||
#endif | ||
- (void)popupMenuWithDescriptor:(NSArray *)desc | ||
atRow:(NSNumber *)row | ||
column:(NSNumber *)col | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -893,6 +893,16 @@ - (IBAction)vimToolbarItemAction:(id)sender | |
[vimController sendMessage:ExecuteMenuMsgID data:[attrs dictionaryAsData]]; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
- (IBAction)vimTouchbarItemAction:(id)sender | ||
{ | ||
NSArray *desc = [NSArray arrayWithObjects:@"TouchBar", [sender title], nil]; | ||
NSDictionary *attrs = [NSDictionary dictionaryWithObject:desc | ||
forKey:@"descriptor"]; | ||
[vimController sendMessage:ExecuteMenuMsgID data:[attrs dictionaryAsData]]; | ||
} | ||
|
||
#endif | ||
- (IBAction)fontSizeUp:(id)sender | ||
{ | ||
[[NSFontManager sharedFontManager] modifyFont: | ||
|
@@ -1332,6 +1342,13 @@ - (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block | |
[afterWindowPresentedQueue addObject:[block copy]]; | ||
} | ||
|
||
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12 | ||
- (NSTouchBar *)makeTouchBar | ||
{ | ||
return [vimController makeTouchBar]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A tab is used to indent here instead of spaces. |
||
} | ||
|
||
#endif | ||
@end // MMWindowController | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better place to do this setup? I'm specifically thinking that customizing the Touch Bar items will likely be something people will want to do quite a lot, and that having to first go through and delete these menu items is somewhat tedious. It might be better if the initial setup of the Touch Bar menu could be deferred somewhere so users could set a global variable in their vimrc to suppress default menu generation and instead generate the items themselves.