• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Gilles Celli <email@hidden>
  • Date: Fri, 10 Feb 2012 16:28:44 +0100

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@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


  • Follow-Ups:
    • Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
      • From: Mike Abdullah <email@hidden>
References: 
 >How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Kyle Sluder <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: Animated NSSplitView headache
  • Next by Date: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Previous by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Next by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Index(es):
    • Date
    • Thread