I have a 'standard' OS X document based app using NSWindowController, NSDocument etc. It has an NSTextView as part of its UI.
Question I have (and it's driving me nuts) is how best to trap 'Close Document' and then tell the NSTexView to finish edit.
Finishing the edit MAY result in the model being updated (and possibly the change count of the document) so I need to do this BEFORE all the other NSDocument logic decides whether a save is necessary.
Thanks
Your textview doesn't allow undo.
You either disabled it by calling former method or unchecked it in interface builder (for the textview). Without undo support in your textview your document isn't made dirty automatically (no updateChangeCount is made so document doesn't know it was edited).
Cleaner solution (without allowing undo):
To fix this you have to register as delegate and implement textDidChange: (NSTextViewDelegate method) or register for NSTextDidChangeNotification. Within those methods you can update your model AND/OR make document dirty/edited.
Alternatively:
When there is an attempt to close window/document catch one of those event. And resign responder. NSTextView will loose focus and update it's backing value.
List of possible methods where to catch closing.
NSTextViewDelegate inherits from NSTextDelegate