44 + (id)sharedDocumentController
83 count = [_documents count];
85 for (; index < count; ++index)
87 var theDocument = _documents[index];
89 if ([[theDocument fileURL]
isEqual:aURL])
101 - (void)openUntitledDocumentOfType:(
CPString)aType display:(BOOL)shouldDisplay
110 [theDocument makeWindowControllers];
111 [theDocument showWindows];
135 - (
CPDocument)openDocumentWithContentsOfURL:(
CPURL)anAbsoluteURL display:(BOOL)shouldDisplay error:(CPError)anError
150 else if (shouldDisplay)
151 [result showWindows];
164 - (
CPDocument)reopenDocumentForURL:(
CPURL)anAbsoluteURL withContentsOfURL:(
CPURL)absoluteContentsURL error:(CPError)anError
178 - (
CPDocument)makeDocumentWithContentsOfURL:(
CPURL)anAbsoluteURL ofType:(
CPString)aType delegate:(
id)aDelegate didReadSelector:(
SEL)aSelector contextInfo:(
id)aContextInfo
180 return [[[
self documentClassForType:aType] alloc] initWithContentsOfURL:anAbsoluteURL ofType:aType delegate:aDelegate didReadSelector:aSelector contextInfo:aContextInfo];
194 - (
CPDocument)makeDocumentForURL:(
CPURL)anAbsoluteURL withContentsOfURL:(
CPURL)absoluteContentsURL ofType:(
CPString)aType delegate:(
id)aDelegate didReadSelector:(
SEL)aSelector contextInfo:(
id)aContextInfo
196 return [[[
self documentClassForType:aType] alloc] initForURL:anAbsoluteURL withContentsOfURL:absoluteContentsURL ofType:aType delegate:aDelegate didReadSelector:aSelector contextInfo:aContextInfo];
203 - (void)document:(
CPDocument)aDocument didRead:(BOOL)didRead contextInfo:(
id)aContextInfo
210 if ([aContextInfo objectForKey:
@"shouldDisplay"])
218 - (CFAction)newDocument:(
id)aSender
223 - (void)openDocument:(
id)aSender
227 [openPanel runModal];
229 var URLs = [openPanel URLs],
231 count = [URLs count];
233 for (; index < count; ++index)
234 [
self openDocumentWithContentsOfURL:[
CPURL URLWithString:URLs[index]] display:YES error:nil];
254 [_documents addObject:aDocument];
263 [_documents removeObjectIdenticalTo:aDocument];
268 return [_documentTypes[0] objectForKey:@"CPBundleTypeName"];
271 - (
CPString)typeForContentsOfURL:(
CPURL)anAbsoluteURL error:(CPError)outError
274 count = _documentTypes.length,
279 for (; index < count; ++index)
281 var documentType = _documentTypes[index],
282 extensions = [documentType objectForKey:@"CFBundleTypeExtensions"],
284 extensionCount = extensions.length;
286 for (; extensionIndex < extensionCount; ++extensionIndex)
288 var thisExtension = [extensions[extensionIndex] lowercaseString];
289 if (thisExtension === extension)
290 return [documentType objectForKey:@"CPBundleTypeName"];
292 if (thisExtension ===
"****")
293 starType = [documentType objectForKey:@"CPBundleTypeName"];
306 count = [_documentTypes count];
308 for (;i < count; ++i)
310 var documentType = _documentTypes[i];
312 if ([documentType objectForKey:
@"CPBundleTypeName"] == aType)
326 var className = [[
self _infoForType:aType] objectForKey:@"CPDocumentClass"];
335 - (void)closeAllDocumentsWithDelegate:(
id)aDelegate didCloseAllSelector:(
SEL)didCloseSelector contextInfo:(Object)info
339 selector: didCloseSelector,
343 [
self _closeDocumentsStartingWith:nil shouldClose:YES context:context];
347 - (void)_closeDocumentsStartingWith:(
CPDocument)aDocument shouldClose:(BOOL)shouldClose context:(Object)context
353 if ([[
self documents] count] > 0)
355 [[[
self documents] lastObject] canCloseDocumentWithDelegate:self
356 shouldCloseSelector:@selector(_closeDocumentsStartingWith:shouldClose:context:)
357 contextInfo:context];
362 if ([context.delegate respondsToSelector:context.selector])
363 objj_msgSend(context.delegate, context.selector,
self, [[
self documents] count] === 0, context.context);
373 if (typeof window[
"cpRecentDocumentURLs"] ===
'function')
374 return window.cpRecentDocumentURLs();
379 - (void)clearRecentDocuments:(
id)sender
381 if (typeof window[
"cpClearRecentDocuments"] ===
'function')
382 window.cpClearRecentDocuments();
384 [
self _updateRecentDocumentsMenu];
392 - (void)noteNewRecentDocumentURL:(
CPURL)aURL
395 if (typeof window[
"cpNoteNewRecentDocumentPath"] ===
'function')
396 window.cpNoteNewRecentDocumentPath(urlAsString);
398 [
self _updateRecentDocumentsMenu];
401 - (void)_removeAllRecentDocumentsFromMenu:(
CPMenu)aMenu
404 count = [items count];
408 var item = items[count];
410 if ([item action] ===
@selector(_openRecentDocument:))
415 - (void)_updateRecentDocumentsMenu
417 var
menu = [[CPApp mainMenu] _menuWithName:@"_CPRecentDocumentsMenu"],
418 recentDocuments = [
self recentDocumentURLs],
419 menuItems = [menu itemArray],
420 documentCount = [recentDocuments count],
421 menuItemCount = [menuItems count];
423 [
self _removeAllRecentDocumentsFromMenu:menu];
429 if ([menuItems[0] isSeparatorItem])
430 [menu removeItemAtIndex:0];
434 if (![menuItems[0] isSeparatorItem])
439 while (documentCount--)
441 var path = recentDocuments[documentCount],
445 [menu insertItem:item atIndex:0];
449 - (void)_openRecentDocument:(
id)sender
451 [
self openDocumentWithContentsOfURL:[sender tag] display:YES error:nil];