From 3178f0b57d51c935747753cd5d20a0da8419bbb6 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Thu, 21 Mar 2013 10:38:06 -0400 Subject: [PATCH] Fixed CPDocumentController missing method currentDocument In this commit I've added the currentDocument method to the document controller Also removed the firstEligibleExistingWindowController method from CPDocument It did nothing but add confusion as it was not used anywhere else in the frameworks. And it is not in cocoa. --- AppKit/CPDocument.j | 31 +++++++++++-------------------- AppKit/CPDocumentController.j | 8 ++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 5c316f801..4ebd2e5db 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]; + var view = [viewController view], + viewFrame = [view frame]; - // From a cib if we have one. - if ([windowCibName length]) - windowController = [[CPWindowController alloc] initWithWindowCibName:windowCibName owner:self]; + viewFrame.origin = CGPointMake(50, 50); - // If not you get a standard window capable of displaying multiple documents and view - else if (viewController) - { - var view = [viewController view], - viewFrame = [view frame]; + var theWindow = [[CPWindow alloc] initWithContentRect:viewFrame styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask]; - viewFrame.origin = CGPointMake(50, 50); - - 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 a36e96e4c..8d528a1df 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