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.
Depends on what kind of application you're building. If it's NSDocument
based, use NSDocument
's updateChangeCount:
method. If you've just got an NSWindowController
, use setDocumentEdited:
. NSWindow
has a setDocumentEdited:
method if all you've got is the NSWindow
.
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.
Also, in 10.6, the 'setDocumentEdited' marks the application as dirty, and so can't be fast-killed. If you don't call this, and set the flag in the Info.plist (see What's New in 10.6)
<key>NSSupportsSuddenTermination</key>
<string>YES</string>
That way, if your app is running (but isn't dirty) then Mac OS X can simply kill it, rather than invoking polite shutdown requests. If your document(s) are marked dirty (or the window is) then it'll go through the normal app shutdown process to shut it down.