Adds support for warning before closing documents that have unsaved changes.

Includes changes to the multiple documents per window controller stuff.
This commit is contained in:
Ross Boucher committed 2009-10-27 17:36:46 -07:00
1 parent 06eac3e79b
commit b2d994bd66
4 files changed
+88 -27

No files matched your search

+3 -3
View File
@@ -302,11 +302,11 @@ var CPAlertWarningImage,
/* @ignore */
- (void)_notifyDelegate:(id)button
{
if (_delegate && [_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
[_delegate alertDidEnd:self returnCode:[button tag]];
[CPApp abortModal];
[_alertPanel close];
if (_delegate && [_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
[_delegate alertDidEnd:self returnCode:[button tag]];
}
@end
+5 -3
View File
@@ -282,12 +282,13 @@ var CPDocumentUntitledCount = 0;
var view = [viewController view],
theWindow = [[CPWindow alloc] initWithContentRect:[view frame] styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask];
[theWindow setSupportsMultipleDocuments:YES];
windowController = [[CPWindowController alloc] initWithWindow:theWindow];
}
}
if (windowController && viewController)
[windowController setSupportsMultipleDocuments:YES];
if (windowController)
[self addWindowController:windowController];
@@ -838,7 +839,7 @@ var CPDocumentUntitledCount = 0;
- (void)close
{
[_windowControllers makeObjectsPerformSelector:@selector(close)];
[_windowControllers makeObjectsPerformSelector:@selector(removeDocumentAndCloseIfNecessary:) withObject:self];
[[CPDocumentController sharedDocumentController] removeDocument:self];
}
@@ -846,6 +847,7 @@ var CPDocumentUntitledCount = 0;
{
if ([controller shouldCloseDocument] || ([_windowControllers count] < 2 && [_windowControllers indexOfObject:controller] !== CPNotFound))
[self canCloseDocumentWithDelegate:delegate shouldCloseSelector:selector contextInfo:info];
else if ([delegate respondsToSelector:selector])
objj_msgSend(delegate, selector, self, YES, info);
}
+29 -21
View File
@@ -258,7 +258,6 @@ var CPWindowSaveImage = nil,
BOOL _isMovableByWindowBackground;
unsigned _shadowStyle;
BOOL _supportsMultipleDocuments;
BOOL _isDocumentEdited;
BOOL _isDocumentSaving;
@@ -460,19 +459,6 @@ CPTexturedBackgroundWindowMask
return _CPBorderlessBridgeWindowView;
}
- (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
{
shouldSupportMultipleDocuments = !!shouldSupportMultipleDocuments;
// FIXME: throw exception if window controller already has multiple documents and shouldSupportMultipleDocuments === NO
_supportsMultipleDocuments = shouldSupportMultipleDocuments;
}
- (BOOL)supportsMultipleDocuments
{
return _supportsMultipleDocuments;
}
- (void)awakeFromCib
{
if (_initialFirstResponder)
@@ -1650,13 +1636,15 @@ CPTexturedBackgroundWindowMask
else if ([self respondsToSelector:@selector(windowShouldClose:)] && ![self windowShouldClose:self])
return;
var document = [_windowController document];
if (document)
var documents = [_windowController documents];
if ([documents count])
{
[document shouldCloseWindowController:_windowController
delegate:self
shouldCloseSelector:@selector(_document:shouldClose:contextInfo:)
contextInfo:nil];
var index = [documents indexOfObject:[_windowController document]];
[documents[index] shouldCloseWindowController:_windowController
delegate:self
shouldCloseSelector:@selector(_document:shouldClose:contextInfo:)
contextInfo:index];
}
else
[self close];
@@ -1665,7 +1653,27 @@ CPTexturedBackgroundWindowMask
- (void)_document:(CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context
{
if (shouldClose)
[self close];
{
var windowController = [self windowController],
documents = [windowController documents];
[documents[context] close];
var count = [documents count];
if (count)
{
var index = context % count;
[windowController setDocument:documents[index]];
[documents[index] shouldCloseWindowController:_windowController
delegate:self
shouldCloseSelector:@selector(_document:shouldClose:contextInfo:)
contextInfo:index];
}
else
[self close];
}
}
/*!
+51
View File
@@ -43,8 +43,10 @@
{
CPWindow _window;
CPArray _documents;
CPDocument _document;
BOOL _shouldCloseDocument;
BOOL _supportsMultipleDocuments;
id _cibOwner;
CPString _windowCibName;
@@ -74,6 +76,8 @@
[self setShouldCloseDocument:NO];
[self setNextResponder:CPApp];
_documents = [];
}
return self;
@@ -220,6 +224,9 @@
if (_document)
{
if (![self supportsMultipleDocuments])
[self removeDocument:_document];
[defaultCenter removeObserver:self
name:CPDocumentWillSaveNotification
object:_document];
@@ -237,6 +244,8 @@
if (_document)
{
[self addDocument:_document];
[defaultCenter addObserver:self
selector:@selector(_documentWillSave:)
name:CPDocumentWillSaveNotification
@@ -263,6 +272,48 @@
[self synchronizeWindowTitleWithDocumentName];
}
- (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
{
_supportsMultipleDocuments = shouldSupportMultipleDocuments;
}
- (BOOL)supportsMultipleDocuments
{
return _supportsMultipleDocuments;
}
- (void)addDocument:(CPDocument)aDocument
{
if (aDocument && ![_documents containsObject:aDocument])
[_documents addObject:aDocument];
}
- (void)removeDocument:(CPDocument)aDocument
{
var index = [_documents indexOfObjectIdenticalTo:aDocument];
if (index === CPNotFound)
return;
[_documents removeObjectAtIndex:index];
if (_document === aDocument && [_documents count])
[self setDocument:[_documents objectAtIndex:MIN(index, [_documents count] - 1)]];
}
- (void)removeDocumentAndCloseIfNecessary:(CPDocument)aDocument
{
[self removeDocument:aDocument];
if (![_documents count])
[self close];
}
- (CPArray)documents
{
return _documents;
}
- (void)setViewController:(CPViewController)aViewController
{
var containerView = [self viewControllerContainerView] || [[self window] contentView],