On Oct 9, 2014, at 12:33 , Matthew LeRoy <mle...@minitab.com> wrote:

> I agree this sounds like a better idea. There’s no good reason I can’t prompt 
> for and validate the password prior to actually opening and reading the 
> document contents, provided I have access to the document’s URL. However, I’m 
> not entirely sure how to go about it…

It depends on which API you’re using. It isn’t clear from your original post 
whether you’re using different API for different deployment targets.

In an open panel completion handler, ‘openPanel.URLs’ is the array of URLs that 
the user chose.

In the -[NSDocumentController beginOpenPanelWithCompletionHandler:] completion 
handler, the array of URLs is passed as a parameter.

If you’re using older API, then -[NSDocumentController 
URLsFromRunningOpenPanel] might be the way to get the array of URLs.

> The documentation for [NSDocumentController 
> beginOpenPanelWithCompletionHandler:] states in the Discussion section that 
> the default completion handler “determines which button the user pressed … 
> and orders out the open panel”. Presumably I would want to wait until after 
> the default completion handler runs and orders out the open panel before I do 
> my password checking to avoid the open panel being in the way… but the 
> default completion handler is what creates/opens the documents, so if I wait 
> until after the completion handler runs then my readFromURL: will have 
> already been called and the document will have been opened — too late to do 
> password checking. Also, it appears that on Mountain Lion the documents are 
> opened first and then the open panel is ordered out, while on Mavericks 
> (where I do not have this problem) the open panel is ordered out prior to the 
> documents being opened.

It’s easier than that. In your completion handler, use 'dispatch_async 
(dispatch_get_main_queue (), ^{…})’ to wrap the password and document code in 
another block that’s queued on the main queue, and them simply return.

That unblocks the open panel (which has invoked your completion handler 
synchronously), and allows it to dismiss the window. Your code will run 
independently of that.




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to