Re: saveDocument:
Re: saveDocument:
- Subject: Re: saveDocument:
- From: Fritz Anderson <email@hidden>
- Date: Tue, 08 May 2012 11:33:21 -0500
On 8 May 2012, at 11:11 AM, ecir hana wrote:
> please, could you clarify one thing for me? In document-based apps, if I
> were to implement my own document controller, how would I trigger the
> saving of a file? In other words, in menu there is an item which fires
> "saveDocument:" and in document there is a method "saveDocument:" - how
> does the action travels through document controller? In yet another words:
>
> (Menu) saveDocument: -> (Document controller) ? -> (Document) saveDocument:
>
> Do I have the picture right? Is it ok to write something like (in the
> controller):
>
> - (void)saveDocument:(id)sender {
> [[self currentDocument] saveDocument:sender];
> }
>
> I think I just need to pass "saveDocument:" from the menu to the document,
> am I right?
I'll get this wrong if I answer in the amount of time I have. Look up "responder chain" in the Mac OS X documentation.
To oversimplify:
Menu commands typically go to the "first responder" — whatever has the UI focus. If the focused object doesn't implement the menu item's method, the event system shops the event up a logical hierarchy called the "responder chain" (e.g. text field -> window -> document -> application) until it finds an object that does implement the command. The first object that implements the command executes it.
File > Save Document sends saveDocument: to the first responder. Because the chain goes from bottom up, the saveDocument: message arrives at the document object directly, without mediation from the application's document controller.
— F
_______________________________________________
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