Question

I have a document-based Cocoa app that uses a secondary NSWindow for a preview mode (with shouldCloseDocument set to NO).

If the document is dirty (edited without saving) and I close the secondary NSWindow, a "Do you want to save the changes made to the document" prompt appears.

How can I avoid this prompt on the secondary NSWindow?

Was it helpful?

Solution

I couldn't find a way to do this. I expected to find a NSWindowDelegate or NSWindow method called before the save prompt but none of the obvious candidates (windowWillClose, close, performClose, windowShouldClose) are.

As a workaround, instead of setting NSWindowController.document I'm using a custom property to pass the document. With document set to NIL, the save prompt is not shown anymore.

OTHER TIPS

specifically you can do this inside your viewController subclass: make sure delegate is set from the window to the owner class:

//-------------------------------------------------------
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
NSLog (@"windowControllerDidLoadNib");
    aController.document = nil;
    [super windowControllerDidLoadNib:aController];

............. etc.......
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top