On Mon, Jan 31, 2011 at 5:25 PM, Bruce Cresanta <cresa...@me.com> wrote: > > I've been scouring through the docs trying to figure out how to get a > reference to the main menu in an NSDocument based app. I need to make > programmatic changes to the menu depending on which NSDocument is key. > Would you please help me find a pointer to the main menu?
What kind of changes? In general, adding and removing menu items is discouraged in Mac apps. Disabling menu items that don't apply to the current document and/or selection is the preferred approach, and for that you don't need a pointer to the menu. The current document is in the responder chain, so if it doesn't respond to a menu item's action message, that menu item will be disabled automatically. For more detailed control, for example to disable a menu item based on the current selection in a document, one can write a -validateMenuItem: method to decide whether the given menu item should be enabled or not. I'm not trying to give you the "HIG lecture," I'm just saying - depending on what you want to do, there might be an easier way to do it that doesn't actually need a pointer to the main menu. On the other hand, there are certainly reasons to alter the main menu in other ways that *do* require such a pointer. So, if you do need it, there's NSApplications's mainMenu method, which you can call using the NSApp global, as in: NSMenu *menu = [NSApp mainMenu]; sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net _______________________________________________ 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 arch...@mail-archive.com