Re: Blocking while a save panel sheet is showing
Re: Blocking while a save panel sheet is showing
- Subject: Re: Blocking while a save panel sheet is showing
- From: Graham Cox <email@hidden>
- Date: Mon, 14 Feb 2011 23:12:27 +1100
On 14/02/2011, at 11:01 PM, Kenneth Baxter wrote:
> Hi everyone, I am using a framework where I register as a delegate and when my delegate method is called, I should be able to save my data, and then the framework does different things based on whether the data has been saved or not.
>
> I need to ask the user for the file name to save as, and then save the file. I have tried both the beginSheetModalForWindow:completionHandler: method and the old 10.5 beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: method, but both of them return immediately, and the framework thinks I haven't saved the file.
These methods do return immediately - that's what they do. They present the sheet then return to the event loop.
> Is there some way that I can display the save panel in such a way that it actually blocks until the user has chosen the save or cancel button on the save panel, like what NSRunAlertPanel does? That way, I would be able to get the file name and save the file before the method returned to the framework.
You need to factor your code so that you don't require the sheets to "block". That isn't how they work. Instead, while the sheet is displayed, the event loop is run normally and will run the sheet modally while running everything else (like other documents) as normal. The user can switch away from the document displaying the sheet and come back to it later if they want.
The point is that when the sheet ends (the user clicks OK or Cancel) the completion method (or block) is run, and it is this code that does the actual file saving. The purpose of the sheet is not only to choose the file name and location but to trigger the save itself. Rearranging your code so that the file save is triggered in this way should be straightforward - just call the save method from the sheet's completion method.
--Graham
_______________________________________________
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