1
votes

My Xcode NSDocument-based app contains a floating panel. On each launch of the app the default doc window and panel appear in their previous locations on the screen. However, if I save a document and quit the app then double click the saved file, the document window is positioned at the same origin as the panel.

Turning off cascading gets around the problem but of course I lose cascading.

A minimum Xcode example showing the issue can be downloaded here.

  1. Run the example project.
  2. Do a File/Save.
  3. Quit the app. << important
  4. Double click the saved file.

Any help appreciated.

2
So which behavior do you want? Do you want it to appear where it was left before app termination?Eugene Gordin

2 Answers

1
votes

If you want to store the state of your window before the app terminates try this:

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
    // If you want to save your window position
    // you can use  [window saveFrameUsingName:@"someWindowName"];
    //
    // then use [window setFrameAutosaveName:@"someWindowName"]; at the app launch.

    return NSTerminateNow;
}
0
votes

I knew it had something to do with document windows cascading from the panel. Adding this to the panel controller seems to have fixed it

- (void)windowDidLoad { [super windowDidLoad]; [self setShouldCascadeWindows:NO]; }