Re: Open document panel always on top - Mountain Lion
Re: Open document panel always on top - Mountain Lion
- Subject: Re: Open document panel always on top - Mountain Lion
- From: Quincey Morris <email@hidden>
- Date: Thu, 09 Oct 2014 21:39:14 +0000
On Oct 9, 2014, at 13:44 , Matthew LeRoy <email@hidden> wrote:
> so -[NSDocumentController beginOpenPanelWithCompletionHandler:] is what I would be using.
> Hmm, OK. So where do I provide the custom completion handler?
Ah, I see, I thought you were already *providing* a completion handler somewhere, but I guess you’re not. In that case, I think you would override -[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:], like this:
- (void)openDocumentWithContentsOfURL:(NSURL *)url display:(BOOL)displayDocument completionHandler:(void (^)(NSDocument*document, BOOL documentWasAlreadyOpen, NSError *error))completionHandler {
if ([self typeForContentsOfURL: url …] != myOldType
[super openDocumentWithContentsOfURL: url display: displayDocument completionHandler: completionHandler];
else
dispatch_async (dispatch_get_main_queue (), ^{
[SomeClass verifyPasswordForURL: url completionHandler: ^(NSError* error) {
if (error == nil)
[super openDocumentWithContentsOfURL: url display: displayDocument completionHandler: completionHandler];
else if (completionHandler != nil)
completionHandler (nil, NO, error);
}];
});
}
Just make sure that the password verification (which is invoked on the main thread) doesn’t eventually invoke its completion handler on a background thread — or if it must, then wrap the innermost if/else in another dispatch_async (dispatch_get_main_queue (), …) block.
With this code (warning: written in Mail) you’re getting all the normal document behavior, and reporting a password verification failure through the normal document mechanism.
_______________________________________________
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