Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
- Subject: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
- From: Mike Abdullah <email@hidden>
- Date: Fri, 10 Feb 2012 16:08:13 +0000
> I'm sure I'm doing something wrong here :-(
>
> Any clues ?
Yep, here we go:
On 10 Feb 2012, at 15:28, Gilles Celli wrote:
> In my NSDocument readFromURL:ofType:error: method it init's a progressLoading WindowController (which shows up the window with progress bar and Cancel button).
> In my progressLoadingWC I have a BOOL cancelLoadingFlag which is checked in readFromURL method…however nothing seems to happen if I call NSError…the document is still opened...
>
> Also opening the file and trying to click the button is nearly impossible since it slows down heavily. Here's an excerpt of my code
>
> -(BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
> {
> asciiFileContents = [[NSString alloc] initWithContentsOfURL:absoluteURL
> encoding:NSISOLatin1StringEncoding error:outError];
OK, good, you're grabbing file contents on the worker thread. How long does this typically take? Why not show your progress display before this?
> if (!progressLoadingWindowController)
> {
> progressLoadingWindowController = [[ProgressLoadingWindowController alloc] init];
> [[progressLoadingWindowController fileNameOutlet] setStringValue:[absoluteURL lastPathComponent]];
> [[progressLoadingWindowController loadProgressBar] setUsesThreadedAnimation:YES];
> [[progressLoadingWindowController loadProgressBar] startAnimation:self];
>
> }
Don't do this. AppKit is not thread safe. Creating a window controller on a secondary thread is not supported.
>
> // Display the progressLoading window
> [progressLoadingWindowController showWindow:self];
>
> if ( [progressLoadingWindowController cancelLoadingFlag] )
> {
> NSLog(@"User cancelled opening...");
>
> *outError = [NSError errorWithDomain:NSCocoaErrorDomain
> code:NSUserCancelledError userInfo:nil];
Never blindly assign to error pointers. Check the caller is actually interested in receiving an error first.
> }
>
> myDocWindowController = [[TsoftViewerWindowController alloc] initWithTsfFileString:asciiFileContents];
Or is it this line of code that takes a long time to run? If so, what's it doing?
>
> [self addWindowController:myDocWindowController];
Furthermore, it is not this method's job to create the UI. That should be done in -makeWindowControllers instead.
>
> [asciiFileContents release];
>
>
> return YES;
>
> }
_______________________________________________
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