Mike,

I'm not sure what you mean to set the cancel flag on the main thread.
I have done this so far, but I'm still stuck:

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];
    if (!progressLoadingWindowController)
    {
        progressLoadingWindowController = [[ProgressLoadingWindowController 
alloc] init];
        [[progressLoadingWindowController fileNameOutlet] 
setStringValue:[absoluteURL lastPathComponent]];    
        [[progressLoadingWindowController loadProgressBar] 
setUsesThreadedAnimation:YES];
        [[progressLoadingWindowController loadProgressBar] startAnimation:self];

    }
    
    // Display the progressLoading window
    [progressLoadingWindowController showWindow:self];

    if ( [progressLoadingWindowController cancelLoadingFlag] )
    {
        NSLog(@"User cancelled opening...");
        
        *outError = [NSError errorWithDomain:NSCocoaErrorDomain
                                        code:NSUserCancelledError userInfo:nil];
    }
   
    myDocWindowController = [[TsoftViewerWindowController alloc] 
initWithTsfFileString:asciiFileContents];
        
        [self addWindowController:myDocWindowController];
        
        [asciiFileContents release];
   

    return YES;
        
}

I'm sure I'm doing something wrong here :-(

Any clues ?

Gilles


On Feb 9, 2012, at 11:53 PM, Mike Abdullah wrote:

> 
> On 9 Feb 2012, at 20:23, Gilles Celli wrote:
> 
>> Mike, Kyle,
>> 
>> Thanks for the quick answers!
>> 
>> Yes I'm targeting Mac OS X 10.6 and later so 
>> canConcurrentlyReadDocumentsOfType: is a welcome addition, I completely 
>> forgot that.
>> 
>> Strangely if I put the method canConcurrentlyReadDocumentsOfType: inside my 
>> NSDocument I get a warning when trying to open a document (It seems to be a 
>> QuickLook error ?) on Mac OS X 10.7.3:
>> 
>> [QL] QLError(): +[QLSeamlessDocumentOpener seamlessDocumentOpenerForURL:] 
>> should only be called in the main thread
> 
> Maybe try setting a breakpoint on QLError to see when it gets called?
>> 
>> Now for the cancel question: If I take the more traditional approach to 
>> cancel the operation inside readFromURL, should I fire up a new thread to 
>> check the flag's status ? 
> 
> What would this gain you? You set the cancel flag on the main thread. And you 
> have a worker thread for reading the document supplied by the system, so why 
> add another thread to the mix?
> 


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to