From 5e4da5b3ac6a535676102d21d406ceea03b70687 Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Sun, 6 Dec 2020 19:57:28 -0800 Subject: [PATCH] Fix WinBar menus in GUI, and off-by-one error when adding new menus Fix WinBar menus to not create menu items in the main menu bar. Also, fix an off-by-one error when adding new menu items to the main menu when adding the menus using priorities to insert them in the middle. This also allowed adding a menu (when using index 0) that goes before the main "MacVim" app menu which is quite wrong as the app menu should always be the first one. Fix #918 --- src/MacVim/MMVimController.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 7309a428f7..6ae432acac 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -42,6 +42,7 @@ static NSString * const MMToolbarMenuName = @"ToolBar"; static NSString * const MMTouchbarMenuName = @"TouchBar"; +static NSString * const MMWinBarMenuName = @"WinBar"; static NSString * const MMPopUpMenuPrefix = @"PopUp"; static NSString * const MMUserPopUpMenuPrefix = @"]"; @@ -1242,6 +1243,11 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx return; } + if ([rootName isEqual:MMWinBarMenuName]) { + // WinBar menus are completed handled within Vim windows. No need for GUI to do anything. + return; + } + // This is either a main menu item or a popup menu item. NSString *title = [desc lastObject]; NSMenuItem *item = [[NSMenuItem alloc] init]; @@ -1261,7 +1267,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx } else { // If descriptor has no parent and its not a popup (or toolbar) menu, // then it must belong to main menu. - if (!parent) parent = mainMenu; + if (!parent) { + parent = mainMenu; + idx += 1; // Main menu already has the application menu as the first item, so everything else must be shifted by one. + } if ([parent numberOfItems] <= idx) { [parent addItem:item]; @@ -1311,6 +1320,11 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc #endif return; } + if ([rootName isEqual:MMWinBarMenuName]) { + // WinBar menus are completed handled within Vim windows. No need for GUI to do anything. + return; + } + NSMenu *parent = [self parentMenuForDescriptor:desc]; if (!parent) { ASLogWarn(@"Menu item '%@' has no parent",