Skip to content

Commit 0d62189

Browse files
committed
MacVim Touch Bar
- addressed review feedbacks - documentations
1 parent 8fc7276 commit 0d62189

5 files changed

Lines changed: 63 additions & 57 deletions

File tree

runtime/doc/eval.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9415,6 +9415,7 @@ tgetent Compiled with tgetent support, able to use a termcap
94159415
timers Compiled with |timer_start()| support.
94169416
title Compiled with window title support |'title'|.
94179417
toolbar Compiled with support for |gui-toolbar|.
9418+
touchbar Compiled with support for Touch Bar in MacVim.
94189419
transparency Compiled with 'transparency' support.
94199420
ttyin input is a terminal (tty)
94209421
ttyout output is a terminal (tty)

runtime/doc/gui_mac.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ associated: a title, a key equivalent and an action message. When a menu is
345345
displayed the title is shown on the left and the key equivalent (if any) is
346346
shown on the right. Key equivalents enable you to access a menu item using
347347
the keyboard instead of having to use the mouse. When a menu item is clicked
348-
it will send it's associated action message. Actions can be used to instruct
348+
it will send its associated action message. Actions can be used to instruct
349349
MacVim to paste some text (paste:), open a new window (newWindow:), etc.
350350
Certain actions are standard throughout OS X which is why MacVim must be able
351351
to set these for each menu item. (E.g. the menu item "Edit.Paste" must be

src/MacVim/MMVimController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
// TODO: Move all toolbar code to window controller?
2929
NSToolbar *toolbar;
3030
NSMutableDictionary *toolbarItemDict;
31-
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
31+
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
3232
NSTouchBar *touchbar;
3333
NSMutableDictionary *touchbarItemDict;
3434
NSMutableArray *touchbarItemOrder;
35-
#endif
35+
#endif
3636

3737
int pid;
3838
NSString *serverName;

src/MacVim/MMVimController.m

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
static NSString *MMDefaultToolbarImageName = @"Attention";
4141
static int MMAlertTextFieldHeight = 22;
4242

43+
static const NSString * const MMToolbarMenuName = @"ToolBar";
44+
static const NSString * const MMTouchbarMenuName = @"TouchBar";
45+
4346
// NOTE: By default a message sent to the backend will be dropped if it cannot
4447
// be delivered instantly; otherwise there is a possibility that MacVim will
4548
// 'beachball' while waiting to deliver DO messages to an unresponsive Vim
@@ -129,11 +132,11 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
129132
[[MMWindowController alloc] initWithVimController:self];
130133
backendProxy = [backend retain];
131134
popupMenuItems = [[NSMutableArray alloc] init];
132-
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
135+
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
133136
toolbarItemDict = [[NSMutableDictionary alloc] init];
134137
touchbarItemDict = [[NSMutableDictionary alloc] init];
135138
touchbarItemOrder = [[NSMutableArray alloc] init];
136-
#endif
139+
#endif
137140
pid = processIdentifier;
138141
creationDate = [[NSDate alloc] init];
139142

@@ -182,11 +185,11 @@ - (void)dealloc
182185

183186
[toolbarItemDict release]; toolbarItemDict = nil;
184187
[toolbar release]; toolbar = nil;
185-
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
188+
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
186189
[touchbarItemDict release]; touchbarItemDict = nil;
187190
[touchbarItemOrder release]; touchbarItemOrder = nil;
188191
[touchbar release]; touchbar = nil;
189-
#endif
192+
#endif
190193
[popupMenuItems release]; popupMenuItems = nil;
191194
[windowController release]; windowController = nil;
192195

@@ -500,10 +503,10 @@ - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)theToolbar
500503
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
501504
- (NSTouchBar *)makeTouchBar
502505
{
503-
touchbar = [[NSTouchBar alloc] init];
504-
touchbar.delegate = self;
505-
touchbar.defaultItemIdentifiers = [NSArray arrayWithArray: touchbarItemOrder];
506-
return touchbar;
506+
touchbar = [[NSTouchBar alloc] init];
507+
touchbar.delegate = self;
508+
touchbar.defaultItemIdentifiers = [NSArray arrayWithArray: touchbarItemOrder];
509+
return touchbar;
507510
}
508511

509512
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)itemId
@@ -1095,7 +1098,7 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
10951098
if (!(desc && [desc count] > 0 && idx >= 0)) return;
10961099

10971100
NSString *rootName = [desc objectAtIndex:0];
1098-
if ([rootName isEqual:@"ToolBar"]) {
1101+
if ([rootName isEqual:MMToolbarMenuName]) {
10991102
// The toolbar only has one menu, we take this as a hint to create a
11001103
// toolbar, then we return.
11011104
if (!toolbar) {
@@ -1114,10 +1117,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
11141117

11151118
return;
11161119
}
1117-
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1118-
if ([rootName isEqual:@"TouchBar"])
1120+
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1121+
if ([rootName isEqual:MMTouchbarMenuName])
11191122
return;
1120-
#endif
1123+
#endif
11211124
// This is either a main menu item or a popup menu item.
11221125
NSString *title = [desc lastObject];
11231126
NSMenuItem *item = [[NSMenuItem alloc] init];
@@ -1163,13 +1166,13 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
11631166
NSString *title = [desc lastObject];
11641167
NSString *rootName = [desc objectAtIndex:0];
11651168

1166-
if ([rootName isEqual:@"ToolBar"]) {
1169+
if ([rootName isEqual:MMToolbarMenuName]) {
11671170
if (toolbar && [desc count] == 2)
11681171
[self addToolbarItemWithLabel:title tip:tip icon:icon atIndex:idx];
11691172
return;
11701173
}
11711174
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1172-
if ([rootName isEqual:@"TouchBar"]) {
1175+
if ([rootName isEqual:MMTouchbarMenuName]) {
11731176
if (toolbar && [desc count] == 2)
11741177
[self addTouchbarItemWithLabel:title icon:icon atIndex:idx];
11751178
return;
@@ -1225,7 +1228,7 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc
12251228

12261229
NSString *title = [desc lastObject];
12271230
NSString *rootName = [desc objectAtIndex:0];
1228-
if ([rootName isEqual:@"ToolBar"]) {
1231+
if ([rootName isEqual:MMToolbarMenuName]) {
12291232
if (toolbar) {
12301233
// Only remove toolbar items, never actually remove the toolbar
12311234
// itself or strange things may happen.
@@ -1238,14 +1241,14 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc
12381241
return;
12391242
}
12401243
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1241-
if ([rootName isEqual:@"TouchBar"]){
1242-
if ([desc count] == 2) {
1243-
[touchbarItemOrder removeObject:title];
1244-
[touchbarItemDict removeObjectForKey:title];
1245-
[windowController setTouchBar:nil];
1246-
}
1247-
return;
1248-
}
1244+
if ([rootName isEqual:MMTouchbarMenuName]){
1245+
if ([desc count] == 2) {
1246+
[touchbarItemOrder removeObject:title];
1247+
[touchbarItemDict removeObjectForKey:title];
1248+
[windowController setTouchBar:nil];
1249+
}
1250+
return;
1251+
}
12491252
#endif
12501253
NSMenuItem *item = [self menuItemForDescriptor:desc];
12511254
if (!item) {
@@ -1274,22 +1277,24 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on
12741277
if (!(desc && [desc count] > 0)) return;
12751278

12761279
NSString *rootName = [desc objectAtIndex:0];
1277-
if ([rootName isEqual:@"ToolBar"]) {
1280+
if ([rootName isEqual:MMToolbarMenuName]) {
12781281
if (toolbar && [desc count] == 2) {
12791282
NSString *title = [desc lastObject];
12801283
[[toolbar itemWithItemIdentifier:title] setEnabled:on];
12811284
}
1282-
} else
1285+
return;
1286+
}
12831287
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
1284-
if (![rootName isEqual:@"TouchBar"])
1285-
#endif
1286-
{
1287-
// Use tag to set whether item is enabled or disabled instead of
1288-
// calling setEnabled:. This way the menus can autoenable themselves
1289-
// but at the same time Vim can set if a menu is enabled whenever it
1290-
// wants to.
1291-
[[self menuItemForDescriptor:desc] setTag:on];
1288+
if ([rootName isEqual:MMTouchbarMenuName]) {
1289+
return;
12921290
}
1291+
#endif
1292+
1293+
// Use tag to set whether item is enabled or disabled instead of
1294+
// calling setEnabled:. This way the menus can autoenable themselves
1295+
// but at the same time Vim can set if a menu is enabled whenever it
1296+
// wants to.
1297+
[[self menuItemForDescriptor:desc] setTag:on];
12931298
}
12941299

12951300
- (void)addToolbarItemToDictionaryWithLabel:(NSString *)title
@@ -1381,30 +1386,30 @@ - (void)addTouchbarItemWithLabel:(NSString *)label
13811386
label = NSTouchBarItemIdentifierFixedSpaceLarge;
13821387
}
13831388
} else {
1384-
NSButton* button = [NSButton buttonWithTitle:label target:windowController action:@selector(vimTouchbarItemAction:)];
1385-
NSCustomTouchBarItem *item =
1386-
[[NSCustomTouchBarItem alloc] initWithIdentifier:label];
1387-
NSImage *img = [NSImage imageNamed:icon];
1388-
1389-
if (!img) {
1390-
img = [[[NSImage alloc] initByReferencingFile:icon] autorelease];
1391-
if (!(img && [img isValid]))
1392-
img = nil;
1393-
}
1394-
if (img) {
1395-
[button setImage: img];
1396-
//[button setImagePosition:NSImageLeft];
1397-
[button setImagePosition:NSImageOnly];
1398-
}
1399-
1400-
[item setView:button];
1401-
[touchbarItemDict setObject:item forKey:label];
1389+
NSButton* button = [NSButton buttonWithTitle:label target:windowController action:@selector(vimTouchbarItemAction:)];
1390+
NSCustomTouchBarItem *item =
1391+
[[NSCustomTouchBarItem alloc] initWithIdentifier:label];
1392+
NSImage *img = [NSImage imageNamed:icon];
1393+
1394+
if (!img) {
1395+
img = [[[NSImage alloc] initByReferencingFile:icon] autorelease];
1396+
if (!(img && [img isValid]))
1397+
img = nil;
1398+
}
1399+
if (img) {
1400+
[button setImage: img];
1401+
//[button setImagePosition:NSImageLeft];
1402+
[button setImagePosition:NSImageOnly];
1403+
}
1404+
1405+
[item setView:button];
1406+
[touchbarItemDict setObject:item forKey:label];
14021407
}
1403-
1408+
14041409
int maxIdx = [touchbarItemOrder count];
14051410
if (maxIdx < idx) idx = maxIdx;
14061411
[touchbarItemOrder insertObject:label atIndex:idx];
1407-
1412+
14081413
[windowController setTouchBar:nil];
14091414
}
14101415
#endif

src/MacVim/MMWindowController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ - (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block
13611361
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
13621362
- (NSTouchBar *)makeTouchBar
13631363
{
1364-
return [vimController makeTouchBar];
1364+
return [vimController makeTouchBar];
13651365
}
13661366

13671367
#endif

0 commit comments

Comments
 (0)