Re: NSDocument: Connecting the menubar to objects?
Re: NSDocument: Connecting the menubar to objects?
- Subject: Re: NSDocument: Connecting the menubar to objects?
- From: Gorazd Krosl <email@hidden>
- Date: Tue, 14 Jun 2005 10:31:25 -0400 (EDT)
On 14 Jun 2005, at 04:07, Fritz Anderson wrote:
> On 13 Jun 2005, at 5:09 PM, Theodore H. Smith wrote:
>
>
>> I'm wondering how do I connect the menubar to
objects, in an
>> NSDocument based project.
>>
>> Heres what I have: One nib with a file's owner of
NSApplication,
>> and all the menu targets connected up to the app.
>>
>> Another nib with a file's owner of MyDocument
(NSDocument subclass).
>>
>> I want the menu to call action targets in the the
document.
>>
>> How do I do this? Must I subclass NSApplication to
redirect the
>> stuff across to MyDocument? But that wouldn't work,
would it,
>> because the NSApplication is already instantiated
for me.
>>
>> So how do I do this? I can't figure it out.
>>
>
> The front NSDocument is automatically in the
responder chain. Link
> the menu items to the First Responder, and the
action method will
> get shopped up the chain until it hits your document
subclass.
> Review the NSResponder/responder chain
documentation.
>Hi Fritz,
>My NSDocument subclass needs to get the message
>"moveFileUp", which
>will move the selected file in my UI, upwards.
>
>There is no "moveFileUp" message listed in the first
responder in
>InterfaceBuilder. I also can't change the custom
class >of the first
>responder.
>
>So how do I link any object to the menu, when the
>object is defined
>in another nib? Can I add messages to the first
>responder in IB? But
>I can't see anyway to add messages in IB.
Hi Theodore,
Double click icon for FirstResponder in IB and then
you can add your action method (i.e. moveFileUp) to in
in inspector panel. Note that there will be ":"
automatically added to the action name (When you
implement in in your Document class it has to be named
"-(IBAction)moveFileUp:(id)sender"). Then you
control-drag from you menu item to the FirstResponder
and select your action method from the list. Remember
well the name of your action, since the FirstResponder
contains a lot of actions already build in.
To answer your menu validation question, you should
implement <MenuValidationProtocol> (I hope it is the
right name, I am not at my home computer right now). I
think the method is called
-(BOOL)validateMenuItem:(id<NSMenuItem>)item. This
method is called for the menu items that are connected
to the targets where the method is implemented. That
means the following: if your Document subclass
implements "-(IBAction)moveFileUp:(id)sender" and
"-(BOOL)validateMenuItem:(id<NSMenuItem>)item" then
menu validation method will be called for the menu
item connected to -moveFileUp: method. If your
document instance responds to more than one menu item,
you can distingush between them by obtaining selector
as NSString (using NSStringFromSelector and -action
message sent to menu item passed to your validation
method) and performing proper action according to the
menu item passed in.
HTH
Gorazd
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.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