• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDocument -close called multiple times?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument -close called multiple times?


  • Subject: Re: NSDocument -close called multiple times?
  • From: Kevin Perry <email@hidden>
  • Date: Fri, 21 Sep 2012 10:25:52 -0700

No. -[NSDocument close] is non-cancellable and non-reversible.

On Sep 21, 2012, at 9:55 AM, Markus Spoettl <email@hidden> wrote:

> OK, so one further question: Is there any chance that if -close is called the document won't actually be closed and stays open?
>
> Regards
> Markus
>
> On 9/21/12 6:49 PM, Kevin Perry wrote:
>> Oh dear. Forget you heard me mention anything about unpublished API. The lack of an "_" threw me off...
>>
>> Yes, you'll probably want to keep your own flag.
>>
>> -KP
>>
>> On Sep 20, 2012, at 11:41 PM, Markus Spoettl <email@hidden> wrote:
>>
>>> Just to clarify: -isClosed is not something that is available on NSDocument or NSWindowController, did you mean to say that I'll have to keep a flag myself?
>>>
>>> Regards
>>> Markus
>>>
>>> On 9/20/12 6:53 PM, Kevin Perry wrote:
>>>> This is an known and unfortunate result of the current architecture of NSWindow, NSWindowController, and NSDocument.
>>>>
>>>> There isn't any documentation I'm aware of that explicitly states that -close can be invoked re-entrantly, but it can be deduced from the existing documentation:
>>>>
>>>> On -[NSDocument close]:
>>>>
>>>> 	"The default implementation of this method  … sends each of the document's window controllers a -close message"
>>>>
>>>> On -[NSWindowController close]:
>>>>
>>>> 	"If the controller belongs to a document and it is either the last controller for the document or -shouldCloseDocument is YES, then this will also -close the document."
>>>>
>>>>
>>>> The best way around this at the moment is to first verify [self isClosed] == NO before calling super and doing your own work.
>>>>
>>>>
>>>> [kevin perry];
>>>>
>>>> On Sep 19, 2012, at 1:06 PM, Markus Spoettl <email@hidden> wrote:
>>>>
>>>>> Why does AppKit call into NSDocument's -close multiple times by indirect recursion? Can this be on purpose?
>>>>>
>>>>> It happens when I have this:
>>>>>
>>>>> 1) A document with unsaved with changes
>>>>> 2) Terminate the app via CMD-Q
>>>>> 3) Answer "Don't Save" in the save-changes-sheet
>>>>>
>>>>> This doesn't smell right. I override -close and call super right away, doing some cleanup work afterwards. Under some bizarre situations which I have not been able to recreate it gets called up to 4 times.
>>>>>
>>>>> I'm pasting the call stack (line 366 is the call to super, line 375 is my breakpoint).
>>>>>
>>>>> Regards
>>>>> Markus
>>>>>
>>>>> #0	0x00000001000034d8 in -[MyDocument close] at /Users/markus/Projects/MyApp/src/MyDocument.m:375
>>>>> #1	0x00007fff8bed7d25 in -[NSWindowController _windowDidClose] ()
>>>>> #2	0x00007fff8a30ddf0 in -[QLSeamlessDocumentCloser closeWindow:contentFrame:withBlock:] ()
>>>>> #3	0x00007fff8baa8602 in -[NSWindow _close] ()
>>>>> #4	0x00007fff8bbe1c74 in -[NSDocument close] ()
>>>>> #5	0x00000001000033c9 in -[MyDocument close] at /Users/markus/Projects/MyApp/src/MyDocument.m:366
>>>>> #6	0x00007fff8bbf342e in __-[NSDocumentController closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo:]_block_invoke_3 ()
>>>>> #7	0x00007fff8bbf54c5 in -[NSDocumentController _something:didSomething:soContinue:] ()
>>>>> #8	0x00007fff8bbd62a8 in __-[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:]_block_invoke_2 ()
>>>>> #9	0x00007fff8bbd5ec1 in __-[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:]_block_invoke_11 ()
>>>>> #10	0x00007fff8bbe8e08 in -[NSDocument _something:wasPresentedWithResult:soContinue:] ()
>>>>> #11	0x00007fff8bad8a4d in -[NSAlert didEndAlert:returnCode:contextInfo:] ()
>>>>> #12	0x00007fff8bae53df in -[NSApplication endSheet:returnCode:] ()
>>>>> #13	0x00007fff8bad8913 in -[NSAlert buttonPressed:] ()
>>>>> #14	0x00007fff8053770d in -[NSObject performSelector:withObject:] ()
>>>>> #15	0x00007fff8b934f7e in -[NSApplication sendAction:to:from:] ()
>>>>> #16	0x00007fff8b934eb2 in -[NSControl sendAction:to:] ()
>>>>> #17	0x00007fff8b934ddd in -[NSCell _sendActionFrom:] ()
>>>>> #18	0x00007fff8b9342a0 in -[NSCell trackMouse:inRect:ofView:untilMouseUp:] ()
>>>>> #19	0x00007fff8b9b3fc4 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] ()
>>>>> #20	0x00007fff8b932eaa in -[NSControl mouseDown:] ()
>>>>> #21	0x00007fff8b8fe348 in -[NSWindow sendEvent:] ()
>>>>> #22	0x00007fff8b897a55 in -[NSApplication sendEvent:] ()
>>>>> #23	0x00007fff8bae427e in -[NSApplication _shouldTerminate] ()
>>>>> #24	0x00007fff8b838115 in -[NSApplication terminate:] ()
>>>>> #25	0x000000010001a4a3 in -[AppDelegate terminate:] at /Users/markus/Projects/rubiTrack/src/AppDelegate.m:219
>>>>> #26	0x00007fff8053770d in -[NSObject performSelector:withObject:] ()
>>>>> #27	0x00007fff8b934f7e in -[NSApplication sendAction:to:from:] ()
>>>>> #28	0x00007fff8ba21bfb in -[NSMenuItem _corePerformAction] ()
>>>>> #29	0x00007fff8ba21932 in -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] ()
>>>>> #30	0x00007fff8b99f524 in -[NSMenu performKeyEquivalent:] ()
>>>>> #31	0x00007fff8b99e175 in -[NSApplication _handleKeyEquivalent:] ()
>>>>> #32	0x00007fff8b897536 in -[NSApplication sendEvent:] ()
>>>>> #33	0x00007fff8b82e0c6 in -[NSApplication run] ()
>>>>> #34	0x00007fff8baaa244 in NSApplicationMain ()
>>>>> #35	0x000000010000b552 in main at /Users/markus/Projects/MyApp/src/main.m:22
>>>>> #36	0x00000001000021c4 in start ()
>>>>>
>>>>> --
>>>>> __________________________________________
>>>>> Markus Spoettl
>>>>> _______________________________________________
>>>>>
>>>>> Cocoa-dev mailing list (email@hidden)
>>>>>
>>>>> Please do not post admin requests or moderator comments to the list.
>>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>>
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>
>>>>> This email sent to email@hidden
>>>>
>>>>
>>>
>>>
>>> --
>>> __________________________________________
>>> Markus Spoettl
>>
>>
>
>
> --
> __________________________________________
> Markus Spoettl


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >NSDocument -close called multiple times? (From: Markus Spoettl <email@hidden>)
 >Re: NSDocument -close called multiple times? (From: Kevin Perry <email@hidden>)
 >Re: NSDocument -close called multiple times? (From: Markus Spoettl <email@hidden>)
 >Re: NSDocument -close called multiple times? (From: Kevin Perry <email@hidden>)
 >Re: NSDocument -close called multiple times? (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Re: NSDocument -close called multiple times?
  • Next by Date: iOS:targeting iOS3 through iOS6
  • Previous by thread: Re: NSDocument -close called multiple times?
  • Next by thread: Best practice to handle remoteControlEvent
  • Index(es):
    • Date
    • Thread