Take the 2-minute tour ×

How can I cancel the automatic display of the Save Panel when closing windows in a doc based Cocoa app?



share|improve this question
You'll have to tell us why you would want to do this: the save panel is shown if the document is "dirty" (i.e. has unsaved changes). Why, in God's name, would you want to close a document that the user has changed without showing them a save dialog? If your document initialization causes apparent changes and you want to make the new document appear clean instead of "dirty" to the NSDocument system, that's a different question. You'll have to give us a little more info to work with. –  Barry Wark Feb 13 '10 at 7:25
Using WebKit to build a custom browser module. I thought by using a doc based app it would be easier to support opening multiple pages at once. In this case there is no reason for a save option. –  paul Feb 13 '10 at 13:51

2 Answers 2

For control on a per-window basis, override -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:

There's also similar methods on NSDocumentController for when there's more then one document with unsaved changes.

Agreed with Barry though, this is generally a bad idea.

share|improve this answer

Try overriding -isDocumentEdited. This works for all open docs and is much simpler and safer than overriding canCloseDocumentWithDelegate or canCloseAllDocumentsWithDelegate.

- (BOOL) isDocumentEdited 
    return NO;
share|improve this answer

Your Answer


