diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 5c316f8017..4ebd2e5db2 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -261,6 +261,7 @@ var CPDocumentUntitledCount = 0; - (void)makeViewAndWindowControllers { var viewCibName = [self viewCibName], + windowCibName = [self windowCibName], viewController = nil, windowController = nil; @@ -268,31 +269,21 @@ var CPDocumentUntitledCount = 0; if ([viewCibName length]) viewController = [[CPViewController alloc] initWithCibName:viewCibName bundle:nil owner:self]; - // If we have a view controller, check if we have a free window for it. - if (viewController) - windowController = [self firstEligibleExistingWindowController]; + // From a cib if we have one. + if ([windowCibName length]) + windowController = [[CPWindowController alloc] initWithWindowCibName:windowCibName owner:self]; - // If not, create one. - if (!windowController) + // If not you get a standard window capable of displaying multiple documents and view + else if (viewController) { - var windowCibName = [self windowCibName]; - - // From a cib if we have one. - if ([windowCibName length]) - windowController = [[CPWindowController alloc] initWithWindowCibName:windowCibName owner:self]; + var view = [viewController view], + viewFrame = [view frame]; - // If not you get a standard window capable of displaying multiple documents and view - else if (viewController) - { - var view = [viewController view], - viewFrame = [view frame]; + viewFrame.origin = CGPointMake(50, 50); - viewFrame.origin = CGPointMake(50, 50); + var theWindow = [[CPWindow alloc] initWithContentRect:viewFrame styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask]; - var theWindow = [[CPWindow alloc] initWithContentRect:viewFrame styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask]; - - windowController = [[CPWindowController alloc] initWithWindow:theWindow]; - } + windowController = [[CPWindowController alloc] initWithWindow:theWindow]; } if (windowController && viewController) diff --git a/AppKit/CPDocumentController.j b/AppKit/CPDocumentController.j index a36e96e4cb..35a42559da 100644 --- a/AppKit/CPDocumentController.j +++ b/AppKit/CPDocumentController.j @@ -253,6 +253,14 @@ var CPSharedDocumentController = nil; return _documents; } +/*! + Returns the CPDocument object associated with the main window. +*/ +- (CPDocument)currentDocument +{ + return [[[CPApp mainWindow] windowController] document]; +} + /*! Adds \c aDocument under the control of the receiver. @param aDocument the document to add @@ -271,6 +279,33 @@ var CPSharedDocumentController = nil; [_documents removeObjectIdenticalTo:aDocument]; } +/*! + Returns the document object whose window controller + owns a specified window. +*/ +- (CPDocument)documentForWindow:(CPWindow)aWindow +{ + return [[aWindow windowController] document]; +} + +/*! + Returns a Boolean value that indicates whether the receiver + has any documents with unsaved changes. +*/ +- (BOOL)hasEditedDocuments +{ + var iter = [_documents objectEnumerator], + obj; + + while ((obj = [iter nextObject]) !== nil) + { + if ([obj isDocumentEdited]) + return YES; + } + + return NO; +} + - (CPString)defaultType { return [_documentTypes[0] objectForKey:@"CPBundleTypeName"];