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.
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.
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With