37 CPArray _documentTypes;
45 + (id)sharedDocumentController
62 _documents = [[CPArray alloc] init];
84 count = [_documents count];
86 for (; index < count; ++index)
88 var theDocument = _documents[index];
90 if ([[theDocument fileURL]
isEqual:aURL])
102 - (void)openUntitledDocumentOfType:(
CPString)aType display:(BOOL)shouldDisplay
111 [theDocument makeWindowControllers];
112 [theDocument showWindows];
151 else if (shouldDisplay)
152 [result showWindows];
179 - (
CPDocument)makeDocumentWithContentsOfURL:(
CPURL)anAbsoluteURL ofType:(
CPString)aType delegate:(
id)aDelegate didReadSelector:(
SEL)aSelector contextInfo:(
id)aContextInfo
181 return [[[
self documentClassForType:aType] alloc] initWithContentsOfURL:anAbsoluteURL ofType:aType delegate:aDelegate didReadSelector:aSelector contextInfo:aContextInfo];
195 - (
CPDocument)makeDocumentForURL:(
CPURL)anAbsoluteURL withContentsOfURL:(
CPURL)absoluteContentsURL ofType:(
CPString)aType delegate:(
id)aDelegate didReadSelector:(
SEL)aSelector contextInfo:(
id)aContextInfo
197 return [[[
self documentClassForType:aType] alloc] initForURL:anAbsoluteURL withContentsOfURL:absoluteContentsURL ofType:aType delegate:aDelegate didReadSelector:aSelector contextInfo:aContextInfo];
204 - (void)document:(
CPDocument)aDocument didRead:(BOOL)didRead contextInfo:(
id)aContextInfo
211 if ([aContextInfo objectForKey:
@"shouldDisplay"])
219 - (CFAction)newDocument:(
id)aSender
224 - (void)openDocument:(
id)aSender
228 [openPanel runModal];
230 var URLs = [openPanel URLs],
232 count = [URLs count];
234 for (; index < count; ++index)
235 [
self openDocumentWithContentsOfURL:[
CPURL URLWithString:URLs[index]]
display:YES error:nil];
254 return [[[CPApp mainWindow] windowController] document];
263 [_documents addObject:aDocument];
272 [_documents removeObjectIdenticalTo:aDocument];
288 - (BOOL)hasEditedDocuments
290 var iter = [_documents objectEnumerator],
293 while ((obj = [iter nextObject]) !== nil)
295 if ([obj isDocumentEdited])
304 return [_documentTypes[0] objectForKey:@"CPBundleTypeName"];
310 count = _documentTypes.length,
315 for (; index < count; ++index)
317 var documentType = _documentTypes[index],
318 extensions = [documentType objectForKey:@"CFBundleTypeExtensions"],
320 extensionCount = extensions.length;
322 for (; extensionIndex < extensionCount; ++extensionIndex)
324 var thisExtension = [extensions[extensionIndex] lowercaseString];
325 if (thisExtension === extension)
326 return [documentType objectForKey:@"CPBundleTypeName"];
328 if (thisExtension ===
"****")
329 starType = [documentType objectForKey:@"CPBundleTypeName"];
342 count = [_documentTypes count];
344 for (;i < count; ++i)
346 var documentType = _documentTypes[i];
348 if ([documentType objectForKey:
@"CPBundleTypeName"] == aType)
362 var className = [[
self _infoForType:aType] objectForKey:@"CPDocumentClass"];
371 - (void)closeAllDocumentsWithDelegate:(
id)aDelegate didCloseAllSelector:(
SEL)didCloseSelector contextInfo:(Object)info
375 selector: didCloseSelector,
379 [
self _closeDocumentsStartingWith:nil shouldClose:YES context:context];
383 - (void)_closeDocumentsStartingWith:(
CPDocument)aDocument shouldClose:(BOOL)shouldClose context:(Object)context
389 if ([[
self documents] count] > 0)
391 [[[
self documents] lastObject] canCloseDocumentWithDelegate:self
392 shouldCloseSelector:@selector(_closeDocumentsStartingWith:shouldClose:context:)
393 contextInfo:context];
398 var theDelegate = context.delegate;
400 if ([theDelegate respondsToSelector:context.selector])
401 theDelegate.isa.objj_msgSend3(theDelegate, context.selector,
self, [[
self documents] count] === 0, context.context);
408 - (CPArray)recentDocumentURLs
411 if (typeof window[
"cpRecentDocumentURLs"] ===
'function')
412 return window.cpRecentDocumentURLs();
417 - (void)clearRecentDocuments:(
id)sender
419 if (typeof window[
"cpClearRecentDocuments"] ===
'function')
420 window.cpClearRecentDocuments();
422 [
self _updateRecentDocumentsMenu];
430 - (void)noteNewRecentDocumentURL:(
CPURL)aURL
433 if (typeof window[
"cpNoteNewRecentDocumentPath"] ===
'function')
434 window.cpNoteNewRecentDocumentPath(urlAsString);
436 [
self _updateRecentDocumentsMenu];
439 - (void)_removeAllRecentDocumentsFromMenu:(
CPMenu)aMenu
442 count = [items count];
446 var item = items[count];
448 if ([item action] ===
@selector(_openRecentDocument:))
453 - (void)_updateRecentDocumentsMenu
455 var
menu = [[CPApp mainMenu] _menuWithName:@"_CPRecentDocumentsMenu"],
456 recentDocuments = [
self recentDocumentURLs],
457 menuItems = [menu itemArray],
458 documentCount = [recentDocuments count],
459 menuItemCount = [menuItems count];
461 [
self _removeAllRecentDocumentsFromMenu:menu];
467 if ([menuItems[0] isSeparatorItem])
468 [menu removeItemAtIndex:0];
472 if (![menuItems[0] isSeparatorItem])
477 while (documentCount--)
479 var path = recentDocuments[documentCount],
483 [menu insertItem:item atIndex:0];
487 - (void)_openRecentDocument:(
id)sender
489 [
self openDocumentWithContentsOfURL:[sender tag] display:YES error:nil];
CPWindowController windowController()
Class documentClassForType:(CPString aType)
void openUntitledDocumentOfType:display:(CPString aType, [display] BOOL shouldDisplay)
CPDocument makeDocumentWithContentsOfURL:ofType:delegate:didReadSelector:contextInfo:(CPURL anAbsoluteURL, [ofType] CPString aType, [delegate] id aDelegate, [didReadSelector] SEL aSelector, [contextInfo] id aContextInfo)
void makeWindowControllers()
A mutable key-value pair collection.
CPDocument makeDocumentForURL:withContentsOfURL:ofType:delegate:didReadSelector:contextInfo:(CPURL anAbsoluteURL, [withContentsOfURL] CPURL absoluteContentsURL, [ofType] CPString aType, [delegate] id aDelegate, [didReadSelector] SEL aSelector, [contextInfo] id aContextInfo)
An immutable string (collection of characters).
CPString absoluteString()
CPString lowercaseString()
id objectForKey:(id aKey)
BOOL isKindOfClass:(Class aClass)
Used for encapsulating, presenting, and recovery from errors.
void noteNewRecentDocumentURL:(CPURL aURL)
CPDocument documentForURL:(CPURL aURL)
void noteNewRecentDocument:(CPDocument aDocument)
global CPApp var CPSharedDocumentController
CPString typeForContentsOfURL:error:(CPURL anAbsoluteURL, [error] CPError outError)
CPDocument makeUntitledDocumentOfType:error:(CPString aType, [error]/*{ */CPError/*} */anError)
void addDocument:(CPDocument aDocument)
CPDictionary infoDictionary()
function CPClassFromString(aClassName)