0

Currently, the default behavior of a Cocoa NSDocument based app is for it to open the last document that was opened automatically. How can I prevent this from happening so I can provide my own behavior?

ericg
  • 8,413
  • 9
  • 43
  • 77

1 Answers1

0

I did this by adding this method to my NSDocument subclass:

- (void)addWindowController:(NSWindowController *)aController {

    //
    // Overwritten to reset all window restoration, we do our own.
    // 
    NSWindow    *window=[aController window];

    if(
        [window respondsToSelector:@selector(setRestorationClass:)]
        && [window respondsToSelector:@selector(setRestorable:)]
        && [window respondsToSelector:@selector(invalidateRestorableState)]
    )
    {
        [window setRestorationClass:Nil];
        [window setRestorable:NO];
        [window invalidateRestorableState];
    }

    [super addWindowController:aController];
}

IIRC that was all.

Gerd K
  • 2,933
  • 1
  • 20
  • 23