On 10/9/14, 4:06 PM, "Quincey Morris" 
<quinceymor...@rivergatesoftware.com<mailto:quinceymor...@rivergatesoftware.com>>
 wrote:

On Oct 9, 2014, at 12:33 , Matthew LeRoy 
<mle...@minitab.com<mailto: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.

Ah yes, I should’ve specified that. We target 10.8 and newer and use the 10.8 
SDK, so -[NSDocumentController beginOpenPanelWithCompletionHandler:] is what I 
would be using.

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.

Hmm, OK. So where do I provide the custom completion handler? By overriding 
openDocument: and calling beginOpenPanelWithCompletionHandler:, passing my 
custom completion handler? Or do I override 
beginOpenPanelWithCompletionHandler: and just call super, passing my own 
completion handler which itself calls the default completion handler? In either 
case it sounds like I’m going to have to re-implement in my completion handler 
(or in the block that I queue on the main thread) some logic that I’m currently 
getting for free, including looping through the URLs and opening each one, 
presenting errors returned while opening any of the documents, etc.

This feels pretty early to be hooking into the whole process just to do 
password checking for one document type. Could I override 
openDocumentWithContentsOfURL:display:completionHandler: instead, do the 
password checking first (if the document is the right type) and then just call 
super?

Or, do I need to hook in earlier because the default implementation (at least 
on Mountain Lion) doesn’t appear to close the open panel until after it has 
opened all of the documents?
_______________________________________________

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