Steve,

Could you use a boolean property such as fileIsBeingRead? Set that to YES when 
you start the file read on the background thread, then set it back to NO when 
the file read has completed.

I used this technique in a proof-of-concept app. The app has a status label in 
its window; the label's value and "hidden" properties are bound to an NSString 
property and a BOOL property in the app delegate.

When the user clicks File > Open, I run the open panel modally [myOpenPanel 
runModal]. When the user selects a file and clicks the panel's Open button, I 
set the NSString property something like @"Reading Fileā€¦" and set the 
fileIsBeingRead property to YES. Then I call a method to open the file on a 
background thread.

When the "open a file" method finishes reading the file, it resets the NSString 
and fileIsBeingRead properties, then shows an alert to let the user know the 
file has been read.

You are welcome to the Xcode project for the app I referenced. It's 36K, zipped.

TL;DR: You can set a property to indicate the file is being read, and by 
observing that property, you'll know when the read has finished.

Hope that helps.
--
Bryan Vines


On Aug 13, 2013, at 1:02 PM, Steve Mills <smi...@makemusic.com> wrote:

> On Aug 12, 2013, at 21:22:07, Bryan Vines <bkvi...@me.com> wrote:
> 
>> 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?
> 
> Well, this won't work. The current code runs the dlog with runModal instead 
> of beginWithCompletionHandler. If I change it to beginWithCompletionHandler, 
> it returns right away and falls out of our semi-portable code for opening 
> files before the dlog is even presented. We expect the Open dlog to be modal, 
> not modeless. Any other ideas? I also tried calling orderOut after runModal 
> returned, but it didn't make it go away.
> 
> --
> Steve Mills
> office: 952-818-3871
> home: 952-401-6255
> cell: 612-803-6157

_______________________________________________

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