diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index ef87fe151..22f62b0a8 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -317,6 +317,20 @@ var CPDocumentUntitledCount = 0; [aWindowController setDocument:self]; } +/*! + Remove a controller to the document's list of controllers. This should + be called after closing the controller's window. + @param aWindowController the controller to remove +*/ +- (void)removeWindowController:(CPWindowController)aWindowController +{ + if (aWindowController) + [_windowControllers removeObject:aWindowController]; + + if ([aWindowController document] === self) + [aWindowController setDocument:nil]; +} + - (CPView)view { return _view; @@ -846,12 +860,20 @@ var CPDocumentUntitledCount = 0; - (void)shouldCloseWindowController:(CPWindowController)controller delegate:(id)delegate shouldCloseSelector:(SEL)selector contextInfo:(Object)info { if ([controller shouldCloseDocument] || ([_windowControllers count] < 2 && [_windowControllers indexOfObject:controller] !== CPNotFound)) - [self canCloseDocumentWithDelegate:delegate shouldCloseSelector:selector contextInfo:info]; + [self canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(_document:shouldClose:context:) contextInfo:{delegate:delegate, selector:selector, context:info}]; else if ([delegate respondsToSelector:selector]) objj_msgSend(delegate, selector, self, YES, info); } +- (void)_document:(CPDocument)aDocument shouldClose:(BOOL)shouldClose context:(Object)context +{ + if (aDocument === self && shouldClose) + [self close]; + + objj_msgSend(context.delegate, context.selector, aDocument, shouldClose, context.context); +} + - (void)canCloseDocumentWithDelegate:(id)aDelegate shouldCloseSelector:(SEL)aSelector contextInfo:(Object)context { if (![self isDocumentEdited]) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index f82c3da50..59c0c3501 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1643,33 +1643,33 @@ CPTexturedBackgroundWindowMask [documents[index] shouldCloseWindowController:_windowController delegate:self - shouldCloseSelector:@selector(_document:shouldClose:contextInfo:) - contextInfo:index]; + shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) + contextInfo:{documents:[documents copy], visited:0, index:index}]; } else [self close]; } -- (void)_document:(CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context +- (void)_windowControllerContainingDocument:(CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context { if (shouldClose) { var windowController = [self windowController], - documents = [windowController documents]; + documents = context.documents, + count = [documents count], + visited = ++context.visited, + index = ++context.index % count; - [documents[context] close]; + [document removeWindowController:windowController]; - var count = [documents count]; - if (count) + if (visited < count) { - var index = context % count; - [windowController setDocument:documents[index]]; [documents[index] shouldCloseWindowController:_windowController delegate:self - shouldCloseSelector:@selector(_document:shouldClose:contextInfo:) - contextInfo:index]; + shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) + contextInfo:context]; } else [self close]; @@ -1682,9 +1682,9 @@ CPTexturedBackgroundWindowMask */ - (void)close { - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillCloseNotification object:self]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillCloseNotification object:self]; - [self orderOut:nil]; + [self orderOut:nil]; } // Managing Main Status diff --git a/Foundation/CPDate.j b/Foundation/CPDate.j index 436c51a0c..3d712734c 100644 --- a/Foundation/CPDate.j +++ b/Foundation/CPDate.j @@ -127,6 +127,11 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0)); return [[CPDate date] timeIntervalSinceReferenceDate]; } +- (BOOL)isEqual:(CPDate)aDate +{ + return [self isEqualToDate:aDate]; +} + - (BOOL)isEqualToDate:(CPDate)anotherDate { return !(self < anotherDate || self > anotherDate);