Steve,

Can you run an NSOpenPanel with a completion handler block, and in that block, 
call a method on a background thread to actually perform the file read 
operation?

As a test, I put this together. I called the selectAFile method and chose a 4GB 
text file. The open panel was dismissed after about a second, the file read 
completed after four seconds:

-(void)selectAFile
{
    // Get and configure an open panel.
    NSOpenPanel * myOpenPanel = [NSOpenPanel openPanel];
    [myOpenPanel setCanChooseDirectories:NO];
    [myOpenPanel setAllowedFileTypes:[NSArray arrayWithObject:@"txt"]];
    
    // Run the panel.
    [myOpenPanel  beginWithCompletionHandler:^(NSInteger result)
     {
         if (result==NSFileHandlingPanelOKButton)
         {
             // User clicked OK, do the actual file read in a background thread.
             [self performSelectorInBackground:@selector(openAFileURL:) 
withObject:myOpenPanel.URL];
         }
     }];
}

-(void)openAFileURL:(NSURL *)aFileURL
{
    // Read the contents of the file at aFileURL into a string.
    NSString * fileString = [NSString stringWithContentsOfURL:aFileURL 
encoding:NSUTF8StringEncoding error:nil];
    
    // Log the result.
    if (fileString) {
        NSLog(@"Successfully read file: %@", [aFileURL lastPathComponent]);
    } else {
        NSLog(@"Could not load file: %@", [aFileURL lastPathComponent]);
    }
}

--
Bryan Vines

On Aug 12, 2013, at 6:27 PM, "Mills, Steve" <smi...@makemusic.com> wrote:

> I haven't been able to find any info about this, but I might be searching for 
> the wrong thing. How can we get rid of the Open dlog so it doesn't hang 
> around while the document is being read? It's an incredibly annoying design.
> 
> Steve via iPad
_______________________________________________

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