Objective-c – How to change the state of the window close button in Cocoa

cocoaobjective c

In Cocoa Applications, you often see a little red dot in the window's close button when you have unsaved data; TextEdit is a good example of this. I've pored through the Cocoa documentation but I can't find a way to programmatically set this state. I'm sure there's some really easy way to do it, but obviously I'm missing something.

Best Answer

To set it programmatically, you can use the -setDocumentEdited: method of NSWindow. If you are writing a Document-based app, NSDocumentManager should automatically detect when there are unsaved changes to the NSUndoManager associated with the current NSDocument.