Re: Creating the app menu from scratch
Re: Creating the app menu from scratch
- Subject: Re: Creating the app menu from scratch
- From: "Jim Crafton" <email@hidden>
- Date: Sun, 13 Jul 2008 23:16:15 -0400
Thanks, that looks pretty much exactly what I'm after. The only
question I had was that this seems to be specific to the 10.5 Obj
runtime, is there a way to do this on 10.4 or even 10.3.9? Also is
this "safe", exchanging class methods like this seems pretty wild,
I've not seen something like this before in other languages.
Cheers
Jim
On Sun, Jul 13, 2008 at 6:19 PM, Jeff Johnson
<email@hidden> wrote:
> Jim,
>
> I wrote a series of 6 posts on my blog exploring this subject.
>
> http://lapcatsoftware.com/blog/?s=working+without+a+nib
>
> There are code samples for both Tiger and Leopard.
>
> -Jeff
>
>
> On Jul 13, 2008, at 4:01 PM, Jim Crafton wrote:
>
>> 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