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

> My document-based application can potentially display an app-modal dialog via 
> [NSApp runModalForWindow:] from within my override of [NSDocument 
> readFromURL:ofType:error:]

I dunno, but this seems like a really, really bad idea. Although ‘readFromURL’ 
looks like a fairly top-level method in your source-code, when it’s called you 
are (call-wise) deep in the bowels of NSDocument. Stalling the whole process 
while you ask the user a question may not be the best thing to do.

Without knowing the details of your use-case, I’d suggest that it’s preferable 
to ask for and validate the password before opening the document. You would 
trigger this from the NSOpenPanel completion handler, but if you use any 
blocking methods, don’t try to do it *in* the completion handler, otherwise the 
open panel may still be in your way.

If there’s a good reason you can’t do it that early, I’d defer asking for the 
password until much later — in fact, make it a responsibility of the document’s 
window controller. Then, you can actually use a sheet of the (empty) document 
window, instead of a app-model panel, which I think is a better user experience 
anyway. Note you don’t have to try to read anything from the document until 
after you have the password — there’s nothing that requires ‘readFromURL’ to 
actually *do* anything. Document data may be loaded lazily, and waiting till 
after the password check is similar to laziness.

I don’t recommend trying to intervene somewhere else in the middle of the 
document opening process (for example, putting up a modal dialog instead of 
creating the document window controller). I tried that sort of thing once and 
it just never worked right in all the paths through the document-opening 
mechanism.

A couple of other issues about checking passwords in ‘readFromURL’ that you may 
or may not have yet considered:

— If your app is starting up and being given an autosaved untitled document to 
open, it’s not clear what password behavior you want, or what behavior you’re 
going to get, if you have the password check in ‘readFromURL’.

— If the user reverts the document, I think in the default case you’ll end up 
back at ‘readFromURL’, which presumably means you’ll ask for the password 
again. Again, it’s not clear if that’s what you really want.



_______________________________________________

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