On Feb 24, 2010, at 12:58, David Blanton wrote:

> What I was really getting at is how to set the target / action for when the 
> item is selected.  Here is what I did,  so if this is way off base please let 
> me know.
> 
> I sub-classed NSMenuItem and set the Preferences menu item to this class.
> 
> In the awakeFromNib I set the target and action.
> 
> Am I doing too much?  Is there a 'less code' approach?

Maybe I'm missing a detail of your requirements, but this seems like the hard 
way.

Simply set the Preferences menu item target to First Responder (i.e. nil) and 
its action to a method name of your choosing. Implement that method in your 
application delegate. The action travels up the responder chain to the 
application and then finally to the application delegate, where your method 
will be found.

Your application delegate can then do whatever is necessary to display the 
preferences (such as creating a window controller the first time, and telling 
it to display the window).

Note: Paul suggested a slightly different way, connecting the action to 
something in the NIB file. That works fine too, but the drawback with such an 
approach is that you have to load up your main menu NIB file with additional 
windows and views. It seems cleaner to me to put the preferences window in a 
separate NIB and have the app delegate create the window controller that loads 
the separate NIB.


_______________________________________________

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

Reply via email to