Thank you Quincey for your very good explanation and to Mike taking the time to making some tests ! I really appreciate it!
I tried a few things and it seems that when preparing the graphs with a lot of data the Open Panel stays open….but disappears immediately when only reading and extracting a big data. So I don't think that using NSDocumentController will change anything, it's only a matter on how to prepare data and the graphs…although… I will try using a combination of serial dispatch queues and as you suggested Quincey with your 3rd approach to defer the conversion at a later time… I'll let you know ASAP when I'm done…hopefully not in several days or month(s) ;-) On 29 Jan 2013, at 22:03, Quincey Morris wrote: > On Jan 29, 2013, at 12:00 , Gilles Celli <gilles.ce...@ecgs.lu> wrote: > >> Ok, sounds good...but what bothers me is that I'm using an NSDocument based >> app: >> so can I use without problems NSOpenPanel's >> beginSheetModalForWindow:completionHandler: method instead of using >> NSDocument's readFomURL:ofType:error ? > > If *your* code is displaying the open panel, then ordering-out the open panel > before you start your processing should be no problem. That's what I thought > you were doing, but apparently not. > > If you are relying on NSDocumentController to display the open panel, invoke > its default methods, down to 'readFromURL', and that's the first time your > code gets control, then it's a bit harder. > > There are several possible approaches: > > 1. In 'readFromURL:', dispatch your conversion as a separate asynchronous > operation (either using GCD or NSOperationQueue). In that case, your document > will go ahead and open normally, but that could happen before your conversion > is complete, so your window controller/document initialization code would > have to take that into account. > > 2. Provide your own 'openDocument:' method. Read the comments in > NSDocumentController.h to find out the standard behavior, and tweak the > behavior to make sure the open doesn't happen before open panel is dismissed. > That likely means invoking > 'openDocumentWithContentsOfURL:display:completionHandler:' from a separate > asynchronous operation, rather than directly from the > 'beginOpenPanelWithCompletionHandler:' completion handler. > > 3. As you suggested earlier, defer the conversion to a later time. You can't > really do it synchronously while window controllers are being created, since > that would block the main thread, so in practice, you have to wait till the > window controller's 'windowDidLoad' (or the document's > windowControllerDidLoadNib:') to start the conversion. This approach also > means that your window will be open possibly before the conversion is > complete. > > 4. You can use a hybrid approach, overriding 'openDocument:' so that you can > invoke 'openDocumentWithContentsOfURL:display: NO completionHandler:' to skip > the creation of windows, then dispatch your conversion asynchronously, then > create your window controllers (on the main thread) after the conversion is > done. > > I don't know of any easier ways of doing this. It's something of a deficiency > in the NSDocument architecture, which wasn't originally designed to do > anything asynchronously. Of course, I may be missing something obvious. > _______________________________________________ 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