f



How to set Action for First Responder?

Hi, I have a Cocoa Document-based application, and I edited the 
main menu (added a new entry).  Now I'd like the new menu entry to 
invoke the action newUser: in the responder chain (actually, I 
want it to be sent to the current key-window MyDocument instance, 
but the responder chain should work for that).

I added the action as IBAction to MyDocument.h and dragged it into 
Interface Builder.  When I now try to set the action for the menu 
entry with target FirstResponder, my action doesn't show up :(

Is there any way to set an arbitrary action in Interface Builder? 
  If not, how do I set the action for a menu item (yes, I could 
look that up I guess), and most of all, *where* would I put that 
init code?

-- 
By claiming a patent [...], I'm saying that you are not permitted 
to use your own knowledge to further your ends. By what right?
	Roderick T. Long
0
Ulrich
7/8/2005 4:11:48 PM
comp.sys.mac.programmer.help 4653 articles. 2 followers. Post Follow

2 Replies
2106 Views

Similar Articles

[PageSpeed] 41

In article <3j7mu5Fos6ihU1@individual.net>,
 Ulrich Hobelmann <u.hobelmann@web.de> wrote:

> Hi, I have a Cocoa Document-based application, and I edited the 
> main menu (added a new entry).  Now I'd like the new menu entry to 
> invoke the action newUser: in the responder chain (actually, I 
> want it to be sent to the current key-window MyDocument instance, 
> but the responder chain should work for that).
> 
> I added the action as IBAction to MyDocument.h and dragged it into 
> Interface Builder.  When I now try to set the action for the menu 
> entry with target FirstResponder, my action doesn't show up :(
> 
> Is there any way to set an arbitrary action in Interface Builder? 
>   If not, how do I set the action for a menu item (yes, I could 
> look that up I guess), and most of all, *where* would I put that 
> init code?

Yes. Select the First Responder "numeral one" instance. Then switch the 
current pane of that window to "Classes". The class "First Responder" 
should be selected. If it isn't, select it. Then, use the Contextual 
menu by <Control>Clicking on "First Responder". Choose "Add Action". 
That will bring up the actions inspector, and let you add arbitrary 
actions. Then, connect the menu item to the first responder the usual 
way.

At runtime, the app will do a 

[NSApp sendAction: @selector(mymenuCommand:) to: nil sender: 
<the--menu-item>];

which will walk the responder chain looking for the first object that 
can handle that selector.

People usually keep their entire menu bar in their main nib, separate 
from their document's nib, and just let the fact that the current 
document is in the responder chain handle it.

-- 
David Phillip Oster
0
David
7/8/2005 4:19:25 PM
David Phillip Oster wrote:
> Yes. Select the First Responder "numeral one" instance. Then switch the 
> current pane of that window to "Classes". The class "First Responder" 
> should be selected. If it isn't, select it. Then, use the Contextual 
> menu by <Control>Clicking on "First Responder". Choose "Add Action". 
> That will bring up the actions inspector, and let you add arbitrary 
> actions. Then, connect the menu item to the first responder the usual 
> way.

Thanks, that worked.  I didn't know FirstResponder had its own 
class entry, funny that.

-- 
By claiming a patent [...], I'm saying that you are not permitted 
to use your own knowledge to further your ends. By what right?
	Roderick T. Long
0
Ulrich
7/8/2005 4:43:23 PM
Reply: