Re: Handling key equivalents in a controller class?
Re: Handling key equivalents in a controller class?
- Subject: Re: Handling key equivalents in a controller class?
- From: Jeff Johnson <email@hidden>
- Date: Wed, 16 Jul 2008 13:00:09 -0500
On Jul 16, 2008, at 12:05 PM, Jens Alfke wrote:
I've run into this problem a few times now: I have an
NSWindowController subclass that manages a window. I want to handle
certain hot-keys in this window, for example Esc to exit full-
screen mode, or maybe use letter keys to switch tools as in
Photoshop. Where do I put the handler for this?
When this happened in the past I added a -performKeyEquivalent:
method to a custom view in the window. However, this only makes
sense architecturally if the action is related to that view; and if
the view is a standard class (like NSTableView) then I have to
subclass it just to add that one method. (AppKit doesn't send -
performKeyEquivalent up the responder chain to the window's
delegate, only to the views in the window.) This seems contrary to
Cocoa's usual philosophy of delegation.
Am I missing something?
—Jens_______________________________________________
Jens,
NSWindow is an NSResponder, so you could create an NSWindow subclass
and override performKeyEquivalent: or keyDown: there. Your window
subclass can then ask its controller or delegate to handle it, if you
like.
NSWindow does pass keyDown: to its NSWindowController if it doesn't
handle the key itself.
-Jeff
_______________________________________________
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