Prevent saving prompts when closing NSWindow

I have a Cocoa application based on a document that uses a secondary NSWindowfor preview mode (with shouldCloseDocumentset to NO).

If the document is dirty (edited without saving), and I close the secondary one NSWindow, the prompt “You want to save the changes made to the document” appears.

How to avoid this invitation on the secondary NSWindow?

+5
source share
2 answers

I could not find a way to do this. I expected to find a method NSWindowDelegateor NSWindowwhich is called before the invitation to save, but none of the obvious candidates ( windowWillClose, close, performClose, windowShouldClose) is not.

As a workaround, instead of setting, NSWindowController.documentI use a custom property to transfer the document. If documentset to NIL, the save request is no longer displayed.

0
source

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

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

............. etc.......
0
source

All Articles