On 11 במאי 2012, at 03:11, koko wrote:
> I have a menu item connected to an action in First Responder;
> The action exists in an NSView subclass.
> The subclass implements acceptsFirstResonder and return YES.
> The subclass implements validateMenuItem and return YES;
> When the menu displays the menu item is disabled (set to enabled in IB).
> Is this not the proper implementation?

Hello.

Your implementation is complete and you understood it right. But I'm afraid you 
missed the architectural level...

An NSResponder (such as your view) is given a chance to respond only when it is 
in the responder chain, and no one down the responder chain responds earlier.

Practically - just click on your view to select it/focus on it/make it the 
first-responder  then try again your menu item. You'll have a nice surprise.

The whole responder-chain thing is about context and focus. Many objects can 
implement the same action, and depending on user focus, they will become the 
first to get a chance to handle the action.

If you want the action to be handled even when the view is out-of-focus (not in 
focus, and not containing the currently focused element, not in the current 
responder chain) than you must move the action implementation (and 
menu-validation) to some other view or controller up the chain, that is always 
"there" - in the responder chain - when the user wishes to perform the action.

For example you'd always want the "Save..." to be available, regardless of the 
current user focus on this view or another within the window. But you still 
want to have different "Save..." handlers act, for different windows. right? 

So you'll put your -(IBAction)save:(id)sender; implementation in your 
WindowController. It is high enough in the view hierarchy, and in the responder 
chain to be always available (when some window is active), but when user 
switched between windows --- he'll have different responder-chains that lead 
(up the chain) to different window controllers!

I hope this explanation helps.

Motti Shneor, Mac OS X Software Architect & Team Leader
Spectrum Reflections Ltd.




_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to