Re: Displaying multiple errors in NSOpenPanel beginSheetModalForWindow:completionHandler:
Re: Displaying multiple errors in NSOpenPanel beginSheetModalForWindow:completionHandler:
- Subject: Re: Displaying multiple errors in NSOpenPanel beginSheetModalForWindow:completionHandler:
- From: Ken Thomases <email@hidden>
- Date: Tue, 24 Feb 2015 06:25:17 -0600
On Feb 24, 2015, at 3:09 AM, Steve Mills <email@hidden> wrote:
> I've been trying tons of different things, but can't make this work. I'm running an NSOpenPanel with beginSheetModalForWindow:completionHandler: to choose a destination folder. In the completionHandler I'm processing 1 or more files by copying them to the chosen folder. When an error appears for a file copy, I want to put up an NSAlert to warn the user with beginSheetModalForWindow:completionHandler:, and use showsSuppressionButton to allow them to skip subsequent errors, and I need the loop to wait until the user has dismissed the alert.
>
> Just doing it that way puts up lots of overlapping alert sheets without waiting for the user to respond. While that certainly would keep the user on their toes, it's not at all right. I've tried using a semaphore to wait for the alert (couldn't process user input), running the alert in a dispatch_sync block (that just blocked), and a bunch of other stuff.
Sheets are an inherently asynchronous mechanism. You put one up and then you have to let execution return to the event loop. Part of the point is that while they can block interaction with the window to which they are attached, the user should be able to use the rest of the app. So, you can't have your code stuck in some internal code path.
The right approach is to stash the list of the files you need to copy in some variable, along with the state necessary to know where you were. Then, when the user dismisses the sheet, do the next one. That will either be successful, in which case you can do another, or it will fail, in which case you note where you were and put up another sheet. Of course, if you exhaust your list, you stop.
Given that file copying can be slow, you should probably be using an asynchronous mechanism for that, anyway. So, you'd fire off the copy on a background thread and have it dispatch a completion handler back to the main thread with a result when done. That completion handler would check for success, in which case it would start another copy in the same fashion, or failure, in which case it would put up the sheet. The completion handler for the sheet would potentially start the next copy or, if the user canceled, do nothing (in which case things naturally stop).
Regards,
Ken
_______________________________________________
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