Re: NSDocument's Open File Panel unresponsive when opening large file from disc
Re: NSDocument's Open File Panel unresponsive when opening large file from disc
- Subject: Re: NSDocument's Open File Panel unresponsive when opening large file from disc
- From: Gilles Celli <email@hidden>
- Date: Wed, 30 Jan 2013 22:29:23 +0100
Well I think I found it: now the Open Panel disappears when opening large files in my document-based app.
Now the process of the data file is done in the subclassed NSWindowController windowDidLoad method.
I've found something here on the Cocoa mailing list from 2002!:
http://www.cocoabuilder.com/archive/cocoa/53353-grief-with-nsdocument-windowcontrollerdidloadnib.html
and this sentence was the most important:
"If you do subclass NSWindowController you should instead override NSWindowController's windowWillLoad and windowDidLoad methods."
Also here:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html
The fix to close the Open Panel immediately when the user clicked "Open" to open small and large files:
1. Read the content of the data file into NSString with NSDocument readFromURL:ofType:error
2. NSDocument's makeWindowControllers creates a new windowController object and I'm passing the data file
3. In the subclassed NSWindowController windowDidLoad / windowWillLoad method the data file is processed before displayed as a graph.
This works now as expected, no more Open Panel staying open.
Maybe I should even move the data processing to windowWillLoad, (tested it and this works too).
My mistake was that I processed the data file inside readFromURL:ofType:error and then makeWindowControllers passed the processed data file
to the subclassed NSWindowController and everything was setup via awakeFromNib.
I didn't use NSWindowController's windowDidLoad or windowWillLoad method.
Hope this helps someone somewhere in the future ;-)
Anyway thanks again to everybody helping out with this.
Gilles
On 30 janv. 2013, at 12:41, Mike Abdullah <email@hidden> wrote:
>
> On 29 Jan 2013, at 16:18, Gilles Celli <email@hidden> wrote:
>
>> I looked a little bit today here with my application, and the term unresponsive for the Open Panel is not appropriate:
>> it should be "stays open" when reading /processing the big data file and then the panel closes.
>>
>> The main processing time is when converting date/time to NSTimeIntervalSince1970, and extracting data values..so a big ASCII data file can have > 500000 lines
>>
>> Simply put, the Open Panel should be closed, but it stays open until the data file has been processed and the data displayed as a graph.
>>
>> There should be a way to close NSDocument openPanel but didn't find anything about it…
>>
>> Any help is as always greatly appreciated :-)
>
> So I ran a quick little test here. Our app already uses asynchronous document opening. I simply whacked in a sleep(5) call to make sure that opening documents takes a long time. With that in place:
>
> 1. Bring up the Open Panel (File > Open, no custom code here)
> 2. Select a document
> 3. Click Open
> 4. The panel disappears shortly after
> 5. After a delay, the document appears
>
> Thus I conclude that if you are seeing the open panel hang around, you're likely doing something wrong to block the main thread.
>
_______________________________________________
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