Re: Dismissing Open dlog before doc actually opens
Re: Dismissing Open dlog before doc actually opens
- Subject: Re: Dismissing Open dlog before doc actually opens
- From: Bryan Vines <email@hidden>
- Date: Mon, 12 Aug 2013 21:22:07 -0500
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" <email@hidden> 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 (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