I have an NSDocument-based app where a window for the document may have child windows that need to be queried for changes before the document can close. So I tried to intercept the closing of the document window to do this, but I can't find a reliable way.
I tried to use -[Document canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:] for this, but apparenty this is only called when the document has changes (signalled by -updateChangeCount). If there are no changes, this never gets called.
My other attempt to use the view controller's viewWillDisappear to update the document failed too, as this is too late to register any changes with the document, so they do not get saved (canCloseDocumentWithDelegate:... has already been called at this point.)
What would be the best way to solve this?