Add support for reviewing unsaved documents before application termination.

This commit is contained in:
Ross Boucher
2009-10-27 18:44:09 -07:00
parent 039de1b6e8
commit a0a81be042
2 changed files with 64 additions and 1 deletions
+35
View File
@@ -323,3 +323,38 @@ var CPSharedDocumentController = nil;
}
@end
@implementation CPDocumentController (Closing)
- (void)closeAllDocumentsWithDelegate:(id)aDelegate didCloseAllSelector:(SEL)didCloseSelector contextInfo:(Object)info
{
var context = {
delegate: aDelegate,
selector: didCloseSelector,
context: info
};
[self _closeDocumentsStartingWith:nil shouldClose:YES context:context];
}
// Recursive callback method. Start it by passing in a document of nil.
- (void)_closeDocumentsStartingWith:(CPDocument)aDocument shouldClose:(BOOL)shouldClose context:(Object)context
{
if (shouldClose)
{
[aDocument close];
if ([[self documents] count] > 0)
{
[[[self documents] lastObject] canCloseDocumentWithDelegate:self
shouldCloseSelector:@selector(_closeDocumentsStartingWith:shouldClose:context:)
contextInfo:context];
return;
}
}
if ([context.delegate respondsToSelector:context.selector])
objj_msgSend(context.delegate, context.selector, self, [[self documents] count] === 0, context.context);
}
@end