2

The question

What happens when one click on the red button to close the window attached to an NSDocument?

What methods are called on which object?

Can I hook up somewhere in the process?


Why I ask this question:

When I click on the red button here enter image description here of the window attached to the NSDocument, the panel

enter image description here

does not show up. I want to debug this, and that's why I need to know the process of actions raised by this click.


More info

I put a breaking point in - (void)windowWillClose:. When it stops here, the window seems to be already closed and if I ask p (bool) [self isDocumentEdited], I get true.

Community
  • 1
  • 1
Colas
  • 3,473
  • 4
  • 29
  • 68
  • How is structured your document application ? Do you have multiple `NSWindowController` attached to this document ? – Emmanuel Feb 26 '14 at 12:41
  • Yes indeed. The problem appears when I open one of these other windows (but, strangely, only for one of them). `(void)windowWillClose:(NSNotification *)notification {[self.windowControllers[0] setShouldCloseDocument:YES] ;}` or `- (void)windowWillClose:(NSNotification *)notification {[self.myWindowsManager closeAllWindows] ;}` does not help... – Colas Feb 26 '14 at 12:43
  • 2
    You need to set `-setShouldCloseDocument:` to YES for the "main" NSWindowController when you create it, or once you open other window. Changing it while `-windowWillClose:`, it's to late. – Emmanuel Feb 26 '14 at 12:50
  • Worked like a charm! I guess putting it in `windowWillClose:` was too late. Or maybe `self.windowControllers[0]` was the wrong controller. I hook on the right controller via `- (void)windowControllerDidLoadNib:(NSWindowController *)aController` where for once, I use the argument. It does not answer my question but solve my problem perfectly! – Colas Feb 26 '14 at 13:02
  • 1
    `-windowWillClose:` is send from the `-close`method. So after that all checks are done in `-performClose:` The save panel is invoke in `-performClose:` before sending [-windowShouldClose:](https://developer.apple.com/library/mac/documentation/cocoa/reference/NSWindowDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSWindowDelegate/windowShouldClose:) to the `NSWindow` delegate see `NSDocument` methods `-shouldCloseWindowController:delegate:shouldCloseSelector:contextInfo:`, and `-canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:` – Emmanuel Feb 26 '14 at 15:51

0 Answers0