Skip to content
Browse files

Ensure "Services" menu is empty when creating new main menu

MMVimController uses a copy of the "MacVim" menu that is defined inside
MainMenu.nib instead of getting it from the default main menu.  This
ensures that the "Services" menu is initially empty for each new
MMVimController.  Without this the setKeyEquivalent: call would fail if
the key equivalent already was in a "Services" menu item (e.g. <D-F> and
<D-L> would fail).
  • Loading branch information...
1 parent 2ac28f8 commit 7752431b822b5b3309afba4436346e1162bcb10d @b4winckler committed Jun 6, 2008
Showing with 21 additions and 4 deletions.
  1. +2 −0 src/MacVim/MMAppController.h
  2. +14 −0 src/MacVim/MMAppController.m
  3. +5 −4 src/MacVim/MMVimController.m
View
2 src/MacVim/MMAppController.h
@@ -22,11 +22,13 @@
ATSFontContainerRef fontContainerRef;
NSMutableDictionary *pidArguments;
NSMenu *defaultMainMenu;
+ NSMenuItem *appMenuItemTemplate;
NSMenuItem *recentFilesMenuItem;
}
+ (MMAppController *)sharedInstance;
- (NSMenu *)defaultMainMenu;
+- (NSMenuItem *)appMenuItemTemplate;
- (void)removeVimController:(id)controller;
- (void)windowControllerWillOpen:(MMWindowController *)windowController;
- (void)setMainMenu:(NSMenu *)mainMenu;
View
14 src/MacVim/MMAppController.m
@@ -201,6 +201,7 @@ - (void)dealloc
[openSelectionString release]; openSelectionString = nil;
[recentFilesMenuItem release]; recentFilesMenuItem = nil;
[defaultMainMenu release]; defaultMainMenu = nil;
+ [appMenuItemTemplate release]; appMenuItemTemplate = nil;
[super dealloc];
}
@@ -211,6 +212,14 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
// all editor windows.
defaultMainMenu = [[NSApp mainMenu] retain];
+ // Store a copy of the default app menu so we can use this as a template
+ // for all other menus. We make a copy here because the "Services" menu
+ // will not yet have been populated at this time. If we don't we get
+ // problems trying to set key equivalents later on because they might clash
+ // with items on the "Services" menu.
+ appMenuItemTemplate = [defaultMainMenu itemAtIndex:0];
+ appMenuItemTemplate = [appMenuItemTemplate copy];
+
// Set up the "Open Recent" menu. See
// http://lapcatsoftware.com/blog/2007/07/10/
// working-without-a-nib-part-5-open-recent-menu/
@@ -543,6 +552,11 @@ - (NSMenu *)defaultMainMenu
return defaultMainMenu;
}
+- (NSMenuItem *)appMenuItemTemplate
+{
+ return appMenuItemTemplate;
+}
+
- (void)removeVimController:(id)controller
{
//NSLog(@"%s%@", _cmd, controller);
View
9 src/MacVim/MMVimController.m
@@ -122,11 +122,12 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
selector:@selector(connectionDidDie:)
name:NSConnectionDidDieNotification object:connection];
- // Copy the "MacVim menu" from the default main menu (we assume that it
- // is the first item on the default main menu).
+ // Set up a main menu with only a "MacVim" menu (copied from a template
+ // which itself is set up in MainMenu.nib). The main menu is populated
+ // by Vim later on.
mainMenu = [[NSMenu alloc] initWithTitle:@"MainMenu"];
- NSMenuItem *appMenuItem = [[[MMAppController sharedInstance]
- defaultMainMenu] itemAtIndex:0];
+ NSMenuItem *appMenuItem = [[MMAppController sharedInstance]
+ appMenuItemTemplate];
appMenuItem = [[appMenuItem copy] autorelease];
// Note: If the title of the application menu is anything but what

0 comments on commit 7752431

Please sign in to comment.
Something went wrong with that request. Please try again.