trying to capture doc info at close/quit time
trying to capture doc info at close/quit time
- Subject: trying to capture doc info at close/quit time
- From: Ken Victor <email@hidden>
- Date: Wed, 17 Aug 2005 12:10:19 -0700
I'm attempting to catch the "closed" status of changed documents at
quit time in my (core data) document based cocoa app.
I have a [mydoc
canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:] method
in my document class and when I call this (passing in my own
shouldCloseSelector) when I close the document via a "close document"
menu item or when the last window closes, my shouldCloseSelector is
properly called and does what I want.
However, at quit time [mydoc canCloseDocumentWithDelegate:
shouldCloseSelector:contextInfo:] is called from the shared
NSDocumentController and it is passed a selector to a private method
(_closeDocumentsStartingWith:shouldClose:closeAllContext:) thus my
shouldCloseSelector is not called. So i modified my
canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: method
such that if it is called at quit time with a delegate that
isKindOfClass: [NSDocumentController class], I save the passed in
delegate, shouldCloseSelector, and contextInfo and replace them with
myself as delegate, my shouldCloseSelector, and an appropriate
contextInfo. Then in my shouldCloseSelector, after I've captured the
info I want, I create a NSInvocation object using the saved values
and invoke it. Note that the calls to create an NSMethodSignature and
a NSInvocation succeed and look correct. Additionally, i check that
the saved delegate responds to the saved selector. However, my
invocation fails with a:
*** -[nsdocumentcontroller methodsignatureforselector:]: null selector
When I set a breakpoint at NSLog to catch the write to the console, I
get the following stack trace:
#0 0x928897ac in -[NSObject methodSignatureForSelector:] ()
#1 0x92870ca4 in -[NSObject(NSForwardInvocation) forward::] ()
#2 0x909b20d0 in _objc_msgForward ()
#3 0x909b2214 in objc_msgSendv ()
#4 0x92878a28 in -[NSInvocation invoke] ()
#5 0x92878fd8 in -[NSInvocation invokeWithTarget:] ()
#6 0x000069a8 in -[myDoc
shouldCloseDelegate:shouldClose:contextInfo:] (self=0x348b90,
_cmd=0x17184, document=0x348b90, shouldClose=1 '\001',
contextInfo=0x348b90) at
/Volumes/Disk2/Contracts/MyApp/code/Source/MyDoc:910
#7 0x93960454 in -[NSDocument
_closeAlertSheet:wasPresentedWithResult:inContext:] ()
#8 0x9382e288 in -[NSAlert didEndSheet:returnCode:contextInfo:] ()
#9 0x938195dc in -[NSAlert buttonPressed:] ()
#10 0x936cd08c in -[NSApplication sendAction:to:from:] ()
#11 0x936ccfc0 in -[NSControl sendAction:to:] ()
#12 0x936ccea0 in -[NSCell _sendActionFrom:] ()
#13 0x936e6eb8 in -[NSCell trackMouse:inRect:ofView:untilMouseUp:] ()
#14 0x936e6aa0 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] ()
#15 0x936e64c4 in -[NSControl mouseDown:] ()
#16 0x93687d28 in -[NSWindow sendEvent:] ()
#17 0x93630f5c in -[NSApplication sendEvent:] ()
#18 0x936cf634 in -[NSApplication _shouldTerminate] ()
#19 0x936cf278 in -[NSApplication terminate:] ()
#20 0x936cd08c in -[NSApplication sendAction:to:from:] ()
#21 0x93727888 in -[NSMenu performActionForItemAtIndex:] ()
#22 0x9372760c in -[NSCarbonMenuImpl
performActionWithHighlightingForItemAtIndex:] ()
#23 0x937270b4 in -[NSMenu performKeyEquivalent:] ()
#24 0x93726d00 in -[NSApplication _handleKeyEquivalent:] ()
#25 0x93630a90 in -[NSApplication sendEvent:] ()
#26 0x936283f0 in -[NSApplication run] ()
#27 0x93718c1c in NSApplicationMain ()
#28 0x00002874 in main (argc=1, argv=0xbffffa9c) at
/Volumes/Disk2/Contracts/MyApp/code/Source/main.m:13
Also, my app's delegate method applicationWillTerminate is not
called, but the app does go on to terminate.
So, my questions are as follows:
1) is there a better way to capture the result of closing documents
at quite time? and if so, what is it?
2) if what I am doing is not an unreasonable approach, then what is
going wrong?
thanx,
ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden