Skip to content

Commit

Permalink
Merge pull request cappuccino#1870 from BlairDuncan/documentControlle…
Browse files Browse the repository at this point in the history
…rCurrentDocument

Fixed CPDocumentController missing method currentDocument
  • Loading branch information
aljungberg committed Jun 12, 2013
2 parents 566521f + 5868a4c commit 6ab6503
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
31 changes: 11 additions & 20 deletions AppKit/CPDocument.j
Original file line number Diff line number Diff line change
Expand Up @@ -261,38 +261,29 @@ var CPDocumentUntitledCount = 0;
- (void)makeViewAndWindowControllers
{
var viewCibName = [self viewCibName],
windowCibName = [self windowCibName],
viewController = nil,
windowController = nil;

// Create our view controller if we have a cib for it.
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)
Expand Down
35 changes: 35 additions & 0 deletions AppKit/CPDocumentController.j
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"];
Expand Down

0 comments on commit 6ab6503

Please sign in to comment.