conmulligan
conmulligan

Reputation: 7148

How do you change the state of the window close button in Cocoa?

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.

Upvotes: 16

Views: 3573

Answers (3)

AlBlue
AlBlue

Reputation: 24060

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.

Upvotes: 9

titaniumdecoy
titaniumdecoy

Reputation: 19261

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.

Upvotes: 18

Alex
Alex

Reputation: 26859

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.

Upvotes: 14

Related Questions