Re: Arg! Document window restoration. Again.

Steve Mills

On Aug 1, 2019, at 09:30:12, Quincey Morris <> wrote:

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.
I got it to work by calling the window's restoreStateWithCoder: instead of the document's.

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.
In my tests, it takes care of this and repositions the window so it's on the currently available screen[s] if the previous screen is not available.

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).
Not a problem. If the doc file's locked, I ain't changin' nothing'!

Steve Mills
Drummer, Mac geek

Join to automatically receive all group messages.