On 14/08/13 16:00 , cocoa-dev-requ...@lists.apple.com wrote:
Date: Wed, 14 Aug 2013 14:58:42 -0400
Message-ID: <20130814185842.823741...@mail.rogue-research.com>
On Wed, 14 Aug 2013 09:03:59 -0500, Steve Mills said:

There most certainly is not a deeper issue with my code. Run this and
you'll see for yourself:

-(IBAction) openDocument:(id)sender
{
        NSOpenPanel*                    p = [NSOpenPanel openPanel];
        
        if([p runModal] == NSFileHandlingPanelOKButton) {
                [p orderOut:self];
                // Simulate code that takes 5 seconds to open a document:
                sleep(5);
        }
}

Apologies for being late to the thread.

I have a similar situation: the NSOpenPanel references a potentially large document which may take nearly a minute to fully open. (I don't use NSDocument, however.)

My solution was to pre-create an empty document window and attach the NSOpenPanel to it as a modal sheet with a completion handler like this:

NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel beginSheetModalForWindow:theWindow completionHandler:^(NSInteger result) {
        if (result==NSFileHandlingPanelOKButton) {
[self performSelectorOnMainThread:@selector(openTheseURLS:) withObject:[panel URLs] waitUntilDone:NO];
        }
}

I don't need to call orderOut: at all. The main runloop will close the sheet and then process the selected URLs, updating the window as it does so.

Not sure how this would play out with NSDocument though... :-/

HTH,
--
Rainer Brockerhoff  <rai...@brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/
_______________________________________________

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