When the user makes changes in my document, I call document.updateChangeCount(.changeDone)
which seems to successfully mark the document as changed - the close button has a dot, the proxy icon is disabled, and when closing/quitting I get the save prompt.
The problem is that the File > Save command is never enabled, so saving/quitting is the only way I can get it to save.
I'm not overriding any menu validation methods in my NSDocument subclass. I do have a validateMenuItem()
in my main view controller, but it's only for a popup menu, and setting a breakpoint there confirms that it only gets called for the popup.
What else could be preventing Save from getting enabled?
Edit:
I tried overriding validateUserInterfaceItem()
to return true when appropriate, which works, although the Save command then appears as "Save..." so apparently I'm also responsible for updating the title. In any case this seems like it shouldn't be necessary.
I wonder if it's because I implement saving in save(to:ofType:for:completionHandler:)
rather than one of the other possibilities. I was going to try wirte(to:ofType)
instead but that is surprisingly nonisolated
, so I'm not sure how I'm expected to safely access my data model from there. I can't do data(ofType:)
because saving may involve writing to multiple files.