Getting Items From MainMenu
Getting Items From MainMenu
- Subject: Getting Items From MainMenu
- From: Oliver Cameron <email@hidden>
- Date: Sat, 5 Jun 2004 21:23:52 +0100
Hey guys,
In Interface Builder, I have a menu laid out for my MainMenu.nib. In
one menu in the MainMenu, I have another submenu. What I am wanting to
do, is programatically add items to the submenu in the other menu item.
So I first realized I needed to get the MainMenu, which is easy:
NSMenu *mainMenu = [NSApp mainMenu];
That works fine, I then realized I needed to get the NSMenu of the
actual item inside the MainMenu. I looked inside the NSMenu docs, but
only found a way of getting NSMenuItem's (itemWithTitle:).
Right now my code is:
- (void)setupCompletionMenu
{
NSMenu *mainMenu = [NSApp mainMenu];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Auto
Complete" action:nil keyEquivalent:@""];
[mainMenu insertItem:item atIndex:4];
NSMenu *completionModesMenu = [[NSMenu alloc] initWithTitle:@"Auto
Complete"];
int i;
for (i = 0; i < [[docTextView availableCompletionModes] count]; i++)
{
[completionModesMenu addItemWithTitle:[[docTextView
availableCompletionModes]objectAtIndex:i]action:
@selector(changeCompletionMode:) keyEquivalent:@""];
}
[mainMenu setSubmenu:completionModesMenu forItem:item];
[completionModesMenu release];
}
And this successfully inserts a menu called Auto Complete into the
MainMenu, so basically, I want to take this code, and transfer it so it
enters the above data into another menu inside another menu. This
probably doesn't make sense, so I uploaded a picture of what the menu
looks like:
http://www.talacia.com/junk/menu.jpg
Hope someone can help,
Oliver
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.