Re: notification for first responder status
Re: notification for first responder status
- Subject: Re: notification for first responder status
- From: Erik Buck <email@hidden>
- Date: Wed, 7 Dec 2005 08:57:20 -0800 (PST)
As a simplistic option, consider
[[NSapp keyWindow] firstResponder];
If you need a trigger to call [[NSapp keyWindow] firstResponder];, consider
overriding -update for the window that shows the state that needs to be updated when the first responder changes. You don't have to override -update in every window. You might want to use the NSApplicationWillUpdateNotification instead...
------------------------------------------------------
For a more complete solution, do what automatic menu validation does:
Use - (id)targetForAction:(SEL)anAction to:(id)aTarget from:(id)sender to find an appropriate responder if any whenever you need to know.
Again, use -update or NSApplicationWillUpdateNotification or the fact that you are about to update a user interface element for some other reason to trigger a call to -targetForAction:to:from:.
------------------------------------------------------
You can also use this method to find the first responder unconditionally:
1) Use a category on NSResponder to add a -(IBAction)myIdentifySelfToSender:(id)sender method.
2) Implement -myIdentifySelfToSender: to call [sender setCurrentResponder:self]
3) Use -myIdentifySelfToSender: by calling [NSApp targetForAction:@selector(myIdentifySelfToSender:) to:nil from:someObject]
4) Make sure someObject responds to -setCurrentResponder:
This tiny amount of code encapsulated within a category on NSResponder gives you the ability to always find the first responder no matter what window it is in or even if Apple changes the target for action search order...
------------------------------------------------------
See
http://www.cocoabuilder.com/archive/message/cocoa/2005/7/11/141462 for a previous discussion of dynamic updating based on the current first responder.
------------------------------------------------------
Philosophically:
There are lots of cases where the state of a user interface depends on the current first responder. The built-in menu validation depends on this. Toolbar validation may depend on this. Which inspector modes are available may depend on this.
In general, if there seems to be a common need for a capability, there is probably a simple (low or no-code) solution as there is with menu validation :)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden