Creating the app menu from scratch
Creating the app menu from scratch
- Subject: Creating the app menu from scratch
- From: "Jim Crafton" <email@hidden>
- Date: Sun, 13 Jul 2008 17:01:10 -0400
I'd like to be able to create an application's menu from scratch,
without a nib file. I'm having problems doing so, I've looked around
and seen some different code samples but nothing seems to work
correctly.
The simplest case:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApplication* app = [NSApplication sharedApplication];
NSMenu* appMenu = [[NSMenu alloc] initWithTitle:@"My App"];
[appMenu addItemWithTitle:@"Item 1" action:nil keyEquivalent:@""];
NSMenu* menu = [[NSMenu alloc] initWithTitle: @""];
NSMenuItem* mi = [menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
[mi setSubmenu:appMenu];
//[NSApp performSelector:NSSelectorFromString(@"setAppleMenu:")
withObject:menu];
//[app setAppleMenu:menu];
[app setMainMenu:menu];
[[NSApplication sharedApplication] run];
[pool release];
return 0;
}
Assuming my project is called "test7", this sort of works. It ends up
creating a menu item and a sub menu, but there's *still* a "test7"
menu item, just before the Apple menu item on the menu bar. Is there
something I'm missing? If I try and call setAppleMenu, that does
nothing. Is this even possible? Some of the code sample's I saw (from
several years ago) made references to functions in the NSMenu class
that don't seem to exist anymore, i.e. :
[self setMainMenu: [NSMenu menuWithTitle: @"" submenus: [NSArray
arrayWithObjects:
[self applicationMenu],
[self editMenu],
[self windowMenu],
[self helpMenu],
nil]]];
There doesn't seem to be a menuWithTitle static class function
anymore, or at least it's not documented.
I tried searching the mailing list but the searches kept failing, so
I'm emailing the list directly.
Thanks
Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden