Re: Need Better Understanding of Modal Delegates
Re: Need Better Understanding of Modal Delegates
- Subject: Re: Need Better Understanding of Modal Delegates
- From: Brian Ganninger <email@hidden>
- Date: Sat, 17 Feb 2007 18:20:50 -0600
You are running the dialog in different modes, and that's what needs
to be understood. (1) The runModalForDirectory call is behaving as an
application-modal dialog on which you are blocking for the returned
value whereas the beginSheet: call is window-modal and allows the
application to continue on in execution. You should specify a
callback method as defined in the documentation. (2) This will be
called when the user eventually interacts with the sheet and you can
check the return code in the parameters.
Sheets basically behave asynchronously while application-modal
dialogs are synchronous in behavior.
(1) Sheet programming guide - application modal dialogs - http://
developer.apple.com/documentation/Cocoa/Conceptual/Sheets/Tasks/
UsingAppModalDialogs.html
(2) NSApplication documentation
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//
apple_ref/occ/instm/NSApplication/
beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
On Feb 17, 2007, at 5:14 PM, Jerry Krinock wrote:
Several times I've run into a design dead end like this with modal
delegates:
Example: (Saving a Document)
I have a "save:" method to handle saving my document. It returns an
error/result because some senders (for example, AppleScript's
handleCloseScriptCommand: with NSSaveOptionsYes) require an error/
result.
However, if the document has no path, "save:" first creates a
NSSavePanel,
and then runs it with
beginSheetForDirectory:file:modalForWindow:etc:etc.
But then "save:" continues on and returns to the sender
immediately, before
there is an error/result to return!
Now, in this particular case, I "solved" the problem by sending the
panel
the message -runModalForDirectory:file: instead of
beginSheetForDirectory:file:modalForWindow:etc:etc. Instead of
leaving a
didEndSelector to finish the job and continuing on its merry way,
runModalForDirectory:file: blocks until the user dismisses the
dialog, so
I've got the error/result.
But instead of giving me a nice sheet, runModalForDirectory:file:
gives me a
dialog box instead. The sheet made more sense, cosmetically.
Obviously, I don't understand the theory on which this stuff is
built. Why
does the simple cosmetic change from a dialog box to a sheet
require such a
fundamentally different method? And how can I design a "save:"
method to
run an NSSavePanel sheet and return an error/result?
Thanks,
Jerry Krinock
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40mac.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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