Re: First Responder and menus
Re: First Responder and menus
- Subject: Re: First Responder and menus
- From: Matt Neuburg <email@hidden>
- Date: Wed, 05 Jul 2006 16:58:48 -0700
- Thread-topic: First Responder and menus
On or about 7/5/06 3:54 PM, thus spake "Alan Smith"
<email@hidden>:
> This is all well and good but it doesn't help. I know that the menu
> item isn't connected to the Responder Chain otherwise it would be
> enabled.
>
> So, the question is: How do I add it to the Responder Chain?
Well, I think you already know that:
(a) The menu item's target should the First Responder (which means that it
is actually nil).
(b) The menu item's action should be implemented by some class an instance
of which is in the responder chain.
The responder chain we're talking about is documented here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/BasicEventHandlin
g/Concepts/AboutRespChain.html>
An instance can be part of the responder chain "naturally" (i.e. by virtue
of its place in the architecture of things) or "artificially" (i.e. because
you yourself insert it into the responder chain exactly so that it can
function as part of the chain).
> In the TextEdit example on my hard disk I can't seem to figure out how
> the "Make Rich Text" item works. It's connected to First Responder and
> I've found that File's Owner's delegate is an instance of the
> Controller class. The only problem is that there is no implementation
> of makeRichText: in the Controller class. It's in the Document class
> and Controller just imports that.
You picked a rather convoluted example, but of course it does obey the
rules. You have already said that it obeys rule (a). Well, it also obeys
rule (b): the Document class implements makeRichText:, and sure enough, an
instance of the Document class is in the responder chain. The window in
which the user is working is part of the responder chain, ipso facto (i.e.
because the user is working in it - this makes sense, indeed, since we only
want "Make Rich Text" to be applicable when the user is working in a
document window). A Document class instance is the window's delegate, so
it's part of the responder chain too.
I am sending you (separately) a teeny-weeny project that illustrates the
same architecture in miniature. Build and run the app, and press the "Click
to show window 2" button. Now switch between the two windows, and as you do,
use the Window menu. You will see that the menu item called "Enabled when
window 2 is frontmost" is, uh, enabled when window 2 is frontmost. This is
because MyObject, which implements that menu item's action, is window 2's
delegate, so it is in the responder chain when window is frontmost. But it
is not the first window's delegate, so it is not in the responder chain when
window 1 is frontmost, and so the menu item is not enabled.
> How do I connect a menu item to a class that may not be in the
> MainMenu nib? If I make an instance of that class and put it in the
> MainMenu and connect it that way, it will get the instances mixed up.
See my first paragraph, above. m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide - Second Edition!
http://www.amazon.com/gp/product/0596102119
Take Control of Word 2004, Tiger, and more -
http://www.takecontrolbooks.com/tiger-customizing.html
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
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