Re: Adding menus to main menu
Re: Adding menus to main menu
- Subject: Re: Adding menus to main menu
- From: Rosyna <email@hidden>
- Date: Fri, 16 Sep 2005 08:23:50 -0700
NSMenuItem* menuItem=[[NSMenuItem alloc]
initWithTitle:@"Item" action:@selector(foo:) keyEquivalent:@""];
[menuItem setSubmenu:theMenu];
NSMenu* mainMenu=[NSApp mainMenu];
[mainMenu addItem:menuItem];
[menuItem release];
NSLog(@"Main Menu Before:%@", [mainMenu description]);
[mainMenu removeItem:menuItem];
NSLog(@"Main Menu After:%@", [mainMenu description]);
Ack, at 9/16/05, Bruce Truax said:
When a particular editing window opens in my application I would like to add
a new menu to the main menu bar. The items contained in this menu will be
the same items which are in a contextual menu that is used within the
editor. I would like to know how to programmatically add a menu to the main
menu. I can get the main menu object as follows:
NSApplication *thisApp = [NSApplication sharedApplication];
//Now get the main menu object
NSMenu *theMainMenu = [thisApp mainMenu];
My problem is that the documentation for NSMenu tells how to add an
NSMenuItem using the addItem and insertItem methods. My understanding is
that these will let you add another item (NSMenuItem) to an existing drop
down menu but they will not let you add a new drop down menu which is an
NSMenu.
Another option would be to use the validateMenuItem method but that only
allows menu items to be greyed out and I would like the entire menu not only
be disabled but to be removed or made invisible.
Part of my problem is that I am also somewhat confused as to the structure
of the main menu bar. From my MainMenu.nib I see that the entire menu bar
is an NSMenu and so are each of the drop down menus in the main menu bar. I
assume that the entire menu bar can be build programmatically but I have not
been able to find how this is done anywhere in the Apple documentation.
Thanks.
Bruce
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden