/Frameworks/Debug/AppKit/browser.platform/CPDocumentController.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 161 lines · 160 code · 1 blank · 0 comment · 0 complexity · 7c3b6598b174da9d6b406f2080f67e89 MD5 · raw file

  1. I;21;Foundation/CPObject.jI;21;Foundation/CPBundle.ji;12;CPDocument.jc;8091;
  2. var CPSharedDocumentController = nil;
  3. {var the_class = objj_allocateClassPair(CPObject, "CPDocumentController"),
  4. meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_documents"), new objj_ivar("_documentTypes")]);
  5. objj_registerClassPair(the_class);
  6. objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  7. class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $CPDocumentController__init(self, _cmd)
  8. { with(self)
  9. {
  10. self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
  11. if (self)
  12. {
  13. _documents = objj_msgSend(objj_msgSend(CPArray, "alloc"), "init");
  14. if (!CPSharedDocumentController)
  15. CPSharedDocumentController = self;
  16. _documentTypes = objj_msgSend(objj_msgSend(objj_msgSend(CPBundle, "mainBundle"), "infoDictionary"), "objectForKey:", "CPBundleDocumentTypes");
  17. }
  18. return self;
  19. }
  20. }), new objj_method(sel_getUid("documentForURL:"), function $CPDocumentController__documentForURL_(self, _cmd, aURL)
  21. { with(self)
  22. {
  23. var index = 0,
  24. count = objj_msgSend(_documents, "count");
  25. for (; index < count; ++index)
  26. {
  27. var theDocument = _documents[index];
  28. if (objj_msgSend(objj_msgSend(theDocument, "fileURL"), "isEqual:", aURL))
  29. return theDocument;
  30. }
  31. return nil;
  32. }
  33. }), new objj_method(sel_getUid("openUntitledDocumentOfType:display:"), function $CPDocumentController__openUntitledDocumentOfType_display_(self, _cmd, aType, shouldDisplay)
  34. { with(self)
  35. {
  36. var theDocument = objj_msgSend(self, "makeUntitledDocumentOfType:error:", aType, nil);
  37. if (theDocument)
  38. objj_msgSend(self, "addDocument:", theDocument);
  39. if (shouldDisplay)
  40. {
  41. objj_msgSend(theDocument, "makeWindowControllers");
  42. objj_msgSend(theDocument, "showWindows");
  43. }
  44. return theDocument;
  45. }
  46. }), new objj_method(sel_getUid("makeUntitledDocumentOfType:error:"), function $CPDocumentController__makeUntitledDocumentOfType_error_(self, _cmd, aType, anError)
  47. { with(self)
  48. {
  49. return objj_msgSend(objj_msgSend(objj_msgSend(self, "documentClassForType:", aType), "alloc"), "initWithType:error:", aType, anError);
  50. }
  51. }), new objj_method(sel_getUid("openDocumentWithContentsOfURL:display:error:"), function $CPDocumentController__openDocumentWithContentsOfURL_display_error_(self, _cmd, anAbsoluteURL, shouldDisplay, anError)
  52. { with(self)
  53. {
  54. var result = objj_msgSend(self, "documentForURL:", anAbsoluteURL);
  55. if (!result)
  56. {
  57. var type = objj_msgSend(self, "typeForContentsOfURL:error:", anAbsoluteURL, anError);
  58. result = objj_msgSend(self, "makeDocumentWithContentsOfURL:ofType:delegate:didReadSelector:contextInfo:", anAbsoluteURL, type, self, sel_getUid("document:didRead:contextInfo:"), objj_msgSend(CPDictionary, "dictionaryWithObject:forKey:", shouldDisplay, "shouldDisplay"));
  59. }
  60. else if (shouldDisplay)
  61. objj_msgSend(result, "showWindows");
  62. return result;
  63. }
  64. }), new objj_method(sel_getUid("reopenDocumentForURL:withContentsOfURL:error:"), function $CPDocumentController__reopenDocumentForURL_withContentsOfURL_error_(self, _cmd, anAbsoluteURL, absoluteContentsURL, anError)
  65. { with(self)
  66. {
  67. return objj_msgSend(self, "makeDocumentForURL:withContentsOfURL:ofType:delegate:didReadSelector:contextInfo:", anAbsoluteURL, absoluteContentsURL, objj_msgSend(objj_msgSend(_documentTypes, "objectAtIndex:", 0), "objectForKey:", "CPBundleTypeName"), self, sel_getUid("document:didRead:contextInfo:"), nil);
  68. }
  69. }), new objj_method(sel_getUid("makeDocumentWithContentsOfURL:ofType:delegate:didReadSelector:contextInfo:"), function $CPDocumentController__makeDocumentWithContentsOfURL_ofType_delegate_didReadSelector_contextInfo_(self, _cmd, anAbsoluteURL, aType, aDelegate, aSelector, aContextInfo)
  70. { with(self)
  71. {
  72. return objj_msgSend(objj_msgSend(objj_msgSend(self, "documentClassForType:", aType), "alloc"), "initWithContentsOfURL:ofType:delegate:didReadSelector:contextInfo:", anAbsoluteURL, aType, aDelegate, aSelector, aContextInfo);
  73. }
  74. }), new objj_method(sel_getUid("makeDocumentForURL:withContentsOfURL:ofType:delegate:didReadSelector:contextInfo:"), function $CPDocumentController__makeDocumentForURL_withContentsOfURL_ofType_delegate_didReadSelector_contextInfo_(self, _cmd, anAbsoluteURL, absoluteContentsURL, aType, aDelegate, aSelector, aContextInfo)
  75. { with(self)
  76. {
  77. return objj_msgSend(objj_msgSend(objj_msgSend(self, "documentClassForType:", aType), "alloc"), "initForURL:withContentsOfURL:ofType:delegate:didReadSelector:contextInfo:", anAbsoluteURL, absoluteContentsURL, aType, aDelegate, aSelector, aContextInfo);
  78. }
  79. }), new objj_method(sel_getUid("document:didRead:contextInfo:"), function $CPDocumentController__document_didRead_contextInfo_(self, _cmd, aDocument, didRead, aContextInfo)
  80. { with(self)
  81. {
  82. if (!didRead)
  83. return;
  84. objj_msgSend(self, "addDocument:", aDocument);
  85. objj_msgSend(aDocument, "makeWindowControllers");
  86. if (objj_msgSend(aContextInfo, "objectForKey:", "shouldDisplay"))
  87. objj_msgSend(aDocument, "showWindows");
  88. }
  89. }), new objj_method(sel_getUid("newDocument:"), function $CPDocumentController__newDocument_(self, _cmd, aSender)
  90. { with(self)
  91. {
  92. objj_msgSend(self, "openUntitledDocumentOfType:display:", objj_msgSend(objj_msgSend(_documentTypes, "objectAtIndex:", 0), "objectForKey:", "CPBundleTypeName"), YES);
  93. }
  94. }), new objj_method(sel_getUid("documents"), function $CPDocumentController__documents(self, _cmd)
  95. { with(self)
  96. {
  97. return _documents;
  98. }
  99. }), new objj_method(sel_getUid("addDocument:"), function $CPDocumentController__addDocument_(self, _cmd, aDocument)
  100. { with(self)
  101. {
  102. objj_msgSend(_documents, "addObject:", aDocument);
  103. }
  104. }), new objj_method(sel_getUid("removeDocument:"), function $CPDocumentController__removeDocument_(self, _cmd, aDocument)
  105. { with(self)
  106. {
  107. objj_msgSend(_documents, "removeObjectIdenticalTo:", aDocument);
  108. }
  109. }), new objj_method(sel_getUid("defaultType"), function $CPDocumentController__defaultType(self, _cmd)
  110. { with(self)
  111. {
  112. return objj_msgSend(_documentTypes[0], "objectForKey:", "CPBundleTypeName");
  113. }
  114. }), new objj_method(sel_getUid("typeForContentsOfURL:error:"), function $CPDocumentController__typeForContentsOfURL_error_(self, _cmd, anAbsoluteURL, outError)
  115. { with(self)
  116. {
  117. var index = 0,
  118. count = _documentTypes.length,
  119. extension = objj_msgSend(objj_msgSend(anAbsoluteURL, "pathExtension"), "lowercaseString");
  120. for (; index < count; ++index)
  121. {
  122. var documentType = _documentTypes[index],
  123. extensions = objj_msgSend(documentType, "objectForKey:", "CFBundleTypeExtensions"),
  124. extensionIndex = 0,
  125. extensionCount = extensions.length;
  126. for (; extensionIndex < extensionCount; ++extensionIndex)
  127. if (objj_msgSend(extensions[extensionIndex], "lowercaseString") == extension)
  128. return objj_msgSend(documentType, "objectForKey:", "CPBundleTypeName");
  129. }
  130. return objj_msgSend(self, "defaultType");
  131. }
  132. }), new objj_method(sel_getUid("_infoForType:"), function $CPDocumentController___infoForType_(self, _cmd, aType)
  133. { with(self)
  134. {
  135. var i = 0,
  136. count = objj_msgSend(_documentTypes, "count");
  137. for (;i < count; ++i)
  138. {
  139. var documentType = _documentTypes[i];
  140. if (objj_msgSend(documentType, "objectForKey:", "CPBundleTypeName") == aType)
  141. return documentType;
  142. }
  143. return nil;
  144. }
  145. }), new objj_method(sel_getUid("documentClassForType:"), function $CPDocumentController__documentClassForType_(self, _cmd, aType)
  146. { with(self)
  147. {
  148. var className = objj_msgSend(objj_msgSend(self, "_infoForType:", aType), "objectForKey:", "CPDocumentClass");
  149. return className ? CPClassFromString(className) : nil;
  150. }
  151. })]);
  152. class_addMethods(meta_class, [new objj_method(sel_getUid("sharedDocumentController"), function $CPDocumentController__sharedDocumentController(self, _cmd)
  153. { with(self)
  154. {
  155. if (!CPSharedDocumentController)
  156. objj_msgSend(objj_msgSend(self, "alloc"), "init");
  157. return CPSharedDocumentController;
  158. }
  159. })]);
  160. }