diff --git a/ChangeLog b/ChangeLog index 6d379b205..888ba655b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-11-11 Fred Kiefer + + * Headers/AppKit/NSMenu.h + * Source/NSMenu.m (-setMain:): New internal method to set the main + menu of an application. Uses code from [NSApplication + setMainMenu:] plus a display call for the new main menu. + * Source/NSApplication.m (-setMainMenu:): Use the new method on + NSMenu to flag a menu as main and cleaned up the logic. + 2004-11-11 15:08 Alexander Malmberg * Source/NSCell.m (-_setupTextWithFrame:inView:editor:): Reduce the diff --git a/Headers/AppKit/NSMenu.h b/Headers/AppKit/NSMenu.h index 4dca163c4..9304638b2 100644 --- a/Headers/AppKit/NSMenu.h +++ b/Headers/AppKit/NSMenu.h @@ -589,6 +589,13 @@ The displayed menus on the screen have the following structure: */ - (NSWindow*) window; +/** + Flag this menu to be the main menu of the application, + when isMain is YES. Flag it as no longer being the main + menu when NO is handed in. + */ +- (void) setMain: (BOOL)isMain; + /* Shows the menu window on screen */ /** Show menu on the screen. This method can/should be used by diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 56199c817..0eb303bc1 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -2278,19 +2278,22 @@ image. */ - (void) setMainMenu: (NSMenu*)aMenu { - if (_main_menu != nil && _main_menu != aMenu) + if (_main_menu == aMenu) { - [_main_menu close]; - [[_main_menu window] setLevel: NSSubmenuWindowLevel]; + return; + } + + if (_main_menu != nil) + { + [_main_menu setMain: NO]; } ASSIGN(_main_menu, aMenu); - // Set the title of the window. - // This wont be displayed, but the window manager may need it. - [[_main_menu window] setTitle: [[NSProcessInfo processInfo] processName]]; - [[_main_menu window] setLevel: NSMainMenuWindowLevel]; - [_main_menu setGeometry]; + if (_main_menu != nil) + { + [_main_menu setMain: YES]; + } } - (void) rightMouseDown: (NSEvent*)theEvent diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 419b76348..6867c3496 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -1431,6 +1431,28 @@ static NSNotificationCenter *nc; return (NSWindow *)_aWindow; } +- (void) setMain: (BOOL)isMain +{ + if (isMain) + { + // Set the title of the window. + // This wont be displayed, but the window manager may need it. + [[self window] setTitle: [[NSProcessInfo processInfo] processName]]; + [[self window] setLevel: NSMainMenuWindowLevel]; + [self setGeometry]; + + if ([NSApp isActive]) + { + [self display]; + } + } + else + { + [self close]; + [[self window] setLevel: NSSubmenuWindowLevel]; + } +} + /** Set the frame origin of the receiver to aPoint. If a submenu of the receiver is attached. The frame origin of the submenu is set