Re: Responding to menu items
Re: Responding to menu items
- Subject: Re: Responding to menu items
- From: Chris Hanson <email@hidden>
- Date: Tue, 23 Sep 2003 19:35:38 -0500
On Tuesday, September 23, 2003, at 04:19 PM, Darrin Cardani wrote:
What I've done is create an AppController class, and added that to
MainMenu.nib. It receives the openMovie message, then uses the shared
document controller to get the current document and forwards the
message to it. Is this the standard way of doing things? Is there a
more direct way to do things? Am I going to need an AppController in
most of my applications, which will do this sort of message > forwarding?
That's one way to do it, but the general Cocoa way to do this is to
wire that menu item (in MainMenu.nib) to the First Responder. This is
actually a representation of the nil target; you can edit what action
messages it responds to in a given nib file just by double-clicking its
icon in Interface Builder and then using the Actions tab of the
resulting inspector.
When you select the menu item in your running application, since it has
a nil target its action will be passed on down the current responder
chain until some object is found that can respond to it. Since the
current document (if any) is in the responder chain, it'll wind up
being sent the message. The responder chain is also used like this for
menu item validation. You can see this in that if you don't have a
document frontmost, nothing in the responder chain will respond to your
-openMovie: action, and the menu item will be dimmed.
You'll still probably want an AppController class in most of your
applications, to manage other things like startup and shutdown
behavior, AppleScript commands if you implement scripting support, etc.
But it's not necessary for forwarding messages around.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.