Bernie
Bernie

Reputation: 23

NSDocument-based app window position

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.

Upvotes: 1

Views: 407

Answers (2)

Bernie
Bernie

Reputation: 23

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]; }

Upvotes: 0

Eugene Gordin
Eugene Gordin

Reputation: 4107

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;
}

Upvotes: 1

Related Questions