NSDocument last document loading

  • I have a document-based application, and when it starts it tries to automatically load previously opened documents (running on Lion). Is there a way to disable this behavior in the program?

    My problem is that the document loads/analyzes data sets, and some of the very large ones can take up to 10 minutes to analyze. Sitting around waiting 10 minutes for the app to finish starting is a pain, especially when the user just wants to quickly view a new, small data set.

    Thanks,

    Todd
  • Subclass [NSWindow restorationClass] and return nil should work.

    ----- Original Message -----
    From: "Todd Heberlein" <todd_heberlein...>
    To: <Cocoa-dev...>
    Sent: Monday, July 2, 2012 10:20:05 AM
    Subject: NSDocument last document loading

    I have a document-based application, and when it starts it tries to automatically load previously opened documents (running on Lion). Is there a way to disable this behavior in the program?

    My problem is that the document loads/analyzes data sets, and some of the very large ones can take up to 10 minutes to analyze. Sitting around waiting 10 minutes for the app to finish starting is a pain, especially when the user just wants to quickly view a new, small data set.

    Thanks,

    Todd
  • Did you check the docs in Xcode for "Restoring Your Windows and Custom Objects at Launch TIme" or "User Interface Preservation" ?

    By any chance, do you have a restoreWindowWithIdentifier method in your window classes or is there a YES for isRestorable on the window that holds the view that would be loading the data?

    (I'm assuming that a window opens up that loads the large data set).

    Maybe this will help…

    The actual process of writing out your application state to disk and restoring it later is handled by Cocoa, but you must tell Cocoa what to save. Your app’s windows are the starting point for all save operations. Cocoa iterates over all of your app’s windows and saves data for the ones whose isRestorable method returns YES. Most windows are preserved by default, but you can change the preservation state of a window using the setRestorable: method.

    On Jul 2, 2012, at 1:20 PM, Todd Heberlein <todd_heberlein...> wrote:

    > I have a document-based application, and when it starts it tries to automatically load previously opened documents (running on Lion). Is there a way to disable this behavior in the program?
    >
    >
    > My problem is that the document loads/analyzes data sets, and some of the very large ones can take up to 10 minutes to analyze. Sitting around waiting 10 minutes for the app to finish starting is a pain, especially when the user just wants to quickly view a new, small data set.
    >
    > Thanks,
    >
    > Todd
  • On Jul 2, 2012, at 10:20 AM, Todd Heberlein wrote:

    > My problem is that the document loads/analyzes data sets, and some of the very large ones can take up to 10 minutes to analyze. Sitting around waiting 10 minutes for the app to finish starting is a pain, especially when the user just wants to quickly view a new, small data set.

    Load them asynchronously? Having the app lock up for a long time is always a poor UI.

    —Jens
  • On Jul 2, 2012, at 12:52 PM, Lee Ann Rucker wrote:

    > Subclass [NSWindow restorationClass] and return nil should work.

    Rather than subclassing every NSWindow in your app, you could instead add an override of +restoreWindowWithIdentifier:state:completionHandler: to the subclass of NSDocumentController you likely already have. Or you could just call -setRestorationClass: in your document's window controller's -windowDidLoad (or your document's -windowControllerDidLoadNib method if your app is so simple that you don't even have one of those).

    --Kyle Sluder
  • On Jul 2, 2012, at 2:11 PM, Kyle Sluder wrote:

    > On Jul 2, 2012, at 12:52 PM, Lee Ann Rucker wrote:
    >
    >> Subclass [NSWindow restorationClass] and return nil should work.
    >
    > Rather than subclassing every NSWindow in your app, you could instead add an override of +restoreWindowWithIdentifier:state:completionHandler: to the subclass of NSDocumentController you likely already have. Or you could just call -setRestorationClass: in your document's window controller's -windowDidLoad (or your document's -windowControllerDidLoadNib method if your app is so simple that you don't even have one of those).

    Oops, I should've said "call -setRestorable:", not -setRestorationClass:. Going with -setRestorable: is the most direct way to define your explicit intent.

    But the real answer to Todd's question is itself a question: if it takes 10 minutes to load a document, can you implement +canConcurrentlyReadDocumentsOfType: so the loading happens on a background thread?

    --Kyle Sluder
  • Also, avoid doing any lengthy operation on the main thread/queue.

    Even if a user opens a file with the intent to analyze, getting stuck for ten minutes is a suboptimal experience.

    (Sent from my iPhone.)

    --
    Conrad Shultz

    On Jul 2, 2012, at 12:52, Lee Ann Rucker <lrucker...> wrote:

    > Subclass [NSWindow restorationClass] and return nil should work.
    >
    > ----- Original Message -----
    > From: "Todd Heberlein" <todd_heberlein...>
    > To: <Cocoa-dev...>
    > Sent: Monday, July 2, 2012 10:20:05 AM
    > Subject: NSDocument last document loading
    >
    > I have a document-based application, and when it starts it tries to automatically load previously opened documents (running on Lion). Is there a way to disable this behavior in the program?
    >
    >
    > My problem is that the document loads/analyzes data sets, and some of the very large ones can take up to 10 minutes to analyze. Sitting around waiting 10 minutes for the app to finish starting is a pain, especially when the user just wants to quickly view a new, small data set.
    >
    > Thanks,
    >
    > Todd

  • > Oops, I should've said "call -setRestorable:", not -setRestorationClass:. Going with -setRestorable: is the most direct way to define your explicit intent.

    That explains why I didn't find it; I looked for "restoration".

    Is there a single document that explains how all this fits together, or should I file a bug? Someday I'm going to have to implement this for our own decidedly non-standard window handling.
  • On Jul 2, 2012, at 2:13 PM, Kyle Sluder wrote:

    > Oops, I should've said "call -setRestorable:", not -setRestorationClass:. Going with -setRestorable: is the most direct way to define your explicit intent.

    Below is what I added to my Document class (which works with some interesting caveats below);

    - (void)windowControllerDidLoadNib:(NSWindowController *)aController
    {
        [super windowControllerDidLoadNib:aController];
        [[aController window] setRestorable:NO];
    }

    Interestingly, it has two different behaviors depending on whether I launch the application via Xcode or double clicking it in the Finder. Double clicking it in the finder does what I expect -- it launches a single empty document window. But when I run it from Xcode, no document window appears *until* I click on the icon in the dock. The application is the front running application (at least its menus are displayed).

    Since I was initially only running it from Xcode (and no initial document window was showing up), I tried working around this by creating an application delegate and adding this method:

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        NSDocumentController *myDocController;
        NSError *myError;

        myDocController = [NSDocumentController sharedDocumentController];
        [myDocController openUntitledDocumentAndDisplay:YES error:&myError];
    }

    Which worked fine in Xcode (got a single initial blank document window at start), but when I launched the application from the finder, I got *two* windows.

    In the end, I got rid of the application delegate so the program behaves correctly when launching it from the Finder.

    Todd
  • On 7/2/12 7:20 PM, Todd Heberlein wrote:
    > I have a document-based application, and when it starts it tries to
    > automatically load previously opened documents (running on Lion). Is there a
    > way to disable this behavior in the program?
    >
    >
    > My problem is that the document loads/analyzes data sets, and some of the
    > very large ones can take up to 10 minutes to analyze. Sitting around waiting
    > 10 minutes for the app to finish starting is a pain, especially when the user
    > just wants to quickly view a new, small data set.

    If you analyze the data as part of document loading and you don't need support
    for previous SDKs have a look at

    + (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)typeName

    in NSDocument

    Regards
    Markus
    --
    __________________________________________
    Markus Spoettl
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today