Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CPDocumentController missing method currentDocument #1870

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 11 additions & 20 deletions AppKit/CPDocument.j
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
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