Re: Arg! Document window restoration. Again.

Quincey Morris

On Aug 1, 2019, at 06:00 , Steve Mills via Groups.Io <sjmills@...> wrote:

From what I've experienced and read, that only helps for reopening docs on app launch, not on opening docs once launched. The OS only stores info for docs that were open when the app exits so it can restore the app to the same state (as long as you have "Close windows when quitting an app" turned off in System Prefs).

No, the window autosave name predates state restoration by a lot of years. IIRC, the behavior breaks down like this:

1. Window restoration (if enabled) overrides everything else, for windows that are being re-opened at launch.

2. Otherwise, the autosave frame is honored when a window of that type (a window having that autosave name) is opened. 

3. Depending on the rest of the window configuration, multiple windows of the same type may be cascaded when opened.

4. Document windows are generally all of the same type, so there is no standard per-document behavior. If you want documents to return to their original frame when opened, you must store the frame in the document and set the window frame manually.

#4 is a bit tricky when you’re using state restoration, because documents are opened via your regular code path before the restoration frame is applied. You have to be careful to avoid dueling frames producing strange results.

Another complication with #4 is that you’re on the hook to deal with changes in monitor configuration. If the screen sizes changes, or screens are added or removed, before the document is re-opened, you have to reposition the document sensibly. Built-in mechanisms for positioning the window do this for you in cases #1-#3.

Yet another complication is the problem of what to do about read-only documents (or editable documents that aren’t dirty). Saving the window frame means you have to change the document file, so you’ll need to save and restore the file’s modification date around the change (if you can), or discard the frame (if you can’t).

Join to automatically receive all group messages.