Re: Making custom key-commands
Re: Making custom key-commands
- Subject: Re: Making custom key-commands
- From: William Turner <email@hidden>
- Date: Tue, 18 Dec 2007 12:59:53 -0800
Glad that helped. In general (but not always) menu actions will go
through the first responder. The document is _in_ the responder chain,
but so are views, windows, window controllers, the app, the app
delegate, etc. - the responder chain section of the document I refer
to below is going to explain it better than I can :)
In your case, it's possible that you could handle the action in your
controller - if it is part of the chain, such as being the
NSWindowController managing your document window.
-wil
On Dec 18, 2007, at 12:33 PM, James Maxwell wrote:
Thanks William.
I was trying to implement the method in my controller class, not the
document class - that did the trick!
thanks _sooooo_ much for the tip!
(ps - I'm guessing this is necessary because it's the document
that's first responder, yes?)
J.
On 18-Dec-07, at 12:11 PM, William Turner wrote:
Not aware of a sample showing this, but I'll try to explain what's
needed - assuming your using IB3/Leopard.
1) Add the menu item in your MainMenu nib. The title can be
whatever, the key should be the key you want to capture.
2) Select the First Responder in that nib. Open the "Identity"
inspector. Add an action in the "Class Actions" section at the top.
The name of the action doesn't matter, but it has to end with a ":".
3) Connect your menu item to the First Responder, to the new action
you added.
4) In your document class, implement the action.
When your document window is active, your document will be in the
responder chain and receive events. If it has implemented the
actions associated with the events, its implementation will be
called unless another object in the chain handles them first.
Rather than say more, the best thing is to look at http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_6.html
for a more in depth explanation of how this works :)
-wil
On Dec 18, 2007, at 10:41 AM, James Maxwell wrote:
Okay, I've been trying to get this working, but I'm not getting
anywhere. I think this is because I'm creating a document-based
application, and I can't figure out how to get the main menu to
talk to my document's view.
Does anyone know of a piece of sample code for getting key
commands and their associated menu items working in a document-
based app?
This is a bit of a nightmare, right now, but I'm hoping it will
become clearer soon...
thanks,
J.
On 17-Dec-07, at 2:10 PM, Nick Zitzmann wrote:
On Dec 17, 2007, at 3:08 PM, email@hidden wrote:
The only thing that bothers me a bit about this is that some of
the commands I have in mind change depending on the selected
object. Would that just be a matter of having different classes
handle the menu commands differently?
You can deal with that by using the NSMenu delegate methods,
added to Panther & later.
BTW, Are the menu key-commands set-up in IB, or are they coded?
You can do it either way.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden