We have CPWindows displaying CRUD forms for selected data.
The detail views are currently non-modal.
On close of window, would like to:
- Display CPAlert with three possible return states
- Close window and save changes to representedObject
- Close window and discard changes to representedObject
- Leave window open and continue editing
- If changes to representedObject are to be saved, confirm that they have indeed been safely persisted (locally or remotely, depending on data) before closing window
The asynchronous behaviour of CPAlert doesn't seem to allow an obvious or clean to accomplish this - the windowShouldClose delegate method has finished executing before a return result is available from the alert.
It seems to require a combination of observers and a loop, or a chained sequence of CPOperations, using dependencies and passing state internally - but a clean approach isn't obvious to me yet.
We could make the detail window modal, requiring the user to switch from 'Show' to 'Edit' modes and vice-versa, and only allowing the window to be closed in a clean 'Show' state. This introduces extra keystrokes and mouse movement which I would like to avoid if possible.
Does anyone have suggestions on an architecture to support this?