Good call Etienne on loadNibNamed. This let me get it done. I've edited your 
code snippet a bit more to show what I do.


To achieve a near-nibless application, I just needed to set up a very simple 
dummy xib file using basically the IB defaults with the "main menu" template. I 
edited the menu slightly to have my app's name. I also made one connection, 
from the application's "menu" outlet to the main menu itself. Saved as XIB, 
patched it into the app. Had to set up my mainmenu.nib on the properties tab 
for my application's target in XCode, which makes the right nib name show up in 
Info.plist. Could have probably skipped that if I hardwired the name into the 
code below.

In the flow below, I do the sharedApplication the instant the app starts.  I do 
some initial initialization, including creating and destroying an undisplayed  
window to verify the frame size. After loading the bundle, I do a lot of 
initialization. 

That initialization includes grabbing the [NSApp mainMenu], tearing the app 
menu off the front, inserting it onto the front of a (subclassed NSMenu) menu 
I've built by other means, and then [NSApp setMainMenu:myTweakedMenu].  That 
works fine. I've played around with a few variants, you can mess with the 
mainmenu quite a bit. It's possible that if you build the right entire mainMenu 
(ie by reverse-engineering a system-supplied one), you could just create your 
own without the nib at all (WITHOUT setAppleMenu). From what I've seen, I don't 
think the NIB-reading is doing anything magical, I wouldn't expect it to.

After you've built your main menu, you can then reach in and edit it to 
activate the About and Preferences items to do what you want. (I still have to 
adjust Quit and disable services but shouldn't be a problem.)

Finally I get around to calling [NSApp run] when the app is all ready to go.

I don't use any post-load sorts of notifications from nib-reading for 
initialization, not needed. The flow fits in very cleanly with the usual kind 
of startup code you have for other windowing APIs, it goes into a standard int 
main(int argc, ...). (Same for termination, for that matter)

This all runs on 64-bit btw. Thanks for the help.


----- Original Message ----
From: Etienne Guérard 
To: Russ ; cocoa-dev@lists.apple.com
Sent: Wednesday, November 12, 2008 1:52:25 PM
Subject: RE: Setting up a main menu in a NIB(XIB)?

NSApplicationMain basically does the following:

localPool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
... a little init here ...
[NSBundle loadNibNamed:[[NSBundle mainBundle] 
objectForInfoDictionaryKey:@"NSMainNibFile"] owner:NSApp];
.... here I do really a lot of other initialization ....
[NSApp run];

EG

--




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to