diff options
Diffstat (limited to 'js/io/document')
-rwxr-xr-x[-rw-r--r--] | js/io/document/base-document.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/document/document-controller.js | 166 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/document/html-document.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/document/text-document.js | 15 |
4 files changed, 137 insertions, 44 deletions
diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index 44f54f78..44f54f78 100644..100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js | |||
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 99177de0..6f363bc7 100644..100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -12,26 +12,35 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
12 | @requires js/document/text-document | 12 | @requires js/document/text-document |
13 | */ | 13 | */ |
14 | 14 | ||
15 | // TODO : Fix deps from Montage V4 Archi | ||
16 | |||
17 | var Montage = require("montage/core/core").Montage, | 15 | var Montage = require("montage/core/core").Montage, |
18 | Component = require("montage/ui/component").Component, | 16 | Component = require("montage/ui/component").Component, |
19 | Uuid = require("montage/core/uuid").Uuid; | 17 | Uuid = require("montage/core/uuid").Uuid, |
18 | fileSystem = require("js/io/system/filesystem").FileSystem; | ||
20 | 19 | ||
21 | var HTMLDocument = require("js/io/document/html-document").HTMLDocument; | 20 | var HTMLDocument = require("js/io/document/html-document").HTMLDocument; |
22 | var TextDocument = require("js/io/document/text-document").TextDocument; | 21 | var TextDocument = require("js/io/document/text-document").TextDocument; |
23 | 22 | ||
24 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 23 | var DocumentController = exports.DocumentController = Montage.create(Component, { |
25 | hasTemplate: { value: false }, | 24 | hasTemplate: { |
25 | value: false | ||
26 | }, | ||
27 | |||
28 | _documents: { | ||
29 | value: [] | ||
30 | }, | ||
26 | 31 | ||
27 | _documents: { value: [] }, | ||
28 | _documentsHash: { value: {} }, | ||
29 | _activeDocument: { value: null }, | 32 | _activeDocument: { value: null }, |
30 | _iframeCounter: { value: 1, enumerable: false }, | 33 | _iframeCounter: { value: 1, enumerable: false }, |
31 | _iframeHolder: { value: null, enumerable: false }, | 34 | _iframeHolder: { value: null, enumerable: false }, |
32 | _textHolder: { value: null, enumerable: false }, | 35 | _textHolder: { value: null, enumerable: false }, |
33 | _codeMirrorCounter: {value: 1, enumerable: false}, | 36 | _codeMirrorCounter: {value: 1, enumerable: false}, |
34 | 37 | ||
38 | tmpSourceForTesting: { | ||
39 | value: "function CodeMirror(place, givenOptions) {" + | ||
40 | "// Determine effective options based on given values and defaults." + | ||
41 | "var options = {}, defaults = CodeMirror.defaults; }" | ||
42 | }, | ||
43 | |||
35 | _codeEditor: { | 44 | _codeEditor: { |
36 | value: { | 45 | value: { |
37 | "editor": { | 46 | "editor": { |
@@ -50,33 +59,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
50 | return this._activeDocument; | 59 | return this._activeDocument; |
51 | }, | 60 | }, |
52 | set: function(doc) { | 61 | set: function(doc) { |
53 | if(this._activeDocument) { | 62 | if(this._activeDocument) this._activeDocument.isActive = false; |
54 | if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { | ||
55 | // TODO selection should use the document own selectionModel | ||
56 | //this._activeDocument.selectionModel = selectionManagerModule.selectionManager._selectedItems; | ||
57 | } | ||
58 | |||
59 | this._activeDocument.isActive = false; | ||
60 | } | ||
61 | 63 | ||
62 | if(this._documents.indexOf(doc) === -1) { | 64 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); |
63 | //this._documentsHash[doc.uuid] = this._documents.push(doc) - 1; | ||
64 | this._documents.push(doc); | ||
65 | } | ||
66 | 65 | ||
67 | this._activeDocument = doc; | 66 | this._activeDocument = doc; |
68 | this._activeDocument.isActive = true; | 67 | this._activeDocument.isActive = true; |
69 | 68 | ||
70 | if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { | ||
71 | // TODO selection should use the document own selectionModel | ||
72 | //selectionManagerModule.selectionManager._selectedItems = this._activeDocument.selectionModel; | ||
73 | } | ||
74 | } | 69 | } |
75 | }, | 70 | }, |
76 | 71 | ||
77 | deserializedFromTemplate: { | 72 | deserializedFromTemplate: { |
78 | value: function() { | 73 | value: function() { |
79 | this.eventManager.addEventListener("appLoaded", this, false); | 74 | this.eventManager.addEventListener("appLoaded", this, false); |
75 | |||
76 | this.eventManager.addEventListener("executeFileOpen", this, false); | ||
80 | } | 77 | } |
81 | }, | 78 | }, |
82 | 79 | ||
@@ -86,28 +83,126 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
86 | } | 83 | } |
87 | }, | 84 | }, |
88 | 85 | ||
86 | handleExecuteFileOpen: { | ||
87 | value: function(event) { | ||
88 | var pickerSettings = event._event.settings || {}; | ||
89 | pickerSettings.callback = this.openFileWithURI; | ||
90 | pickerSettings.callbackScope = this; | ||
91 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
92 | |||
93 | //this.openDocument({"type": "js", "source": this.tmpSourceForTesting}); | ||
94 | } | ||
95 | }, | ||
96 | |||
97 | openFileWithURI: { | ||
98 | value: function(uriArrayObj) { | ||
99 | var uri = "", fileContent = "", response=null; | ||
100 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ | ||
101 | uri = uriArrayObj.uri[0]; | ||
102 | } | ||
103 | console.log("URI is: ", uri); | ||
104 | |||
105 | // Get file from Jose Code with a callback to here | ||
106 | if(!!uri){ | ||
107 | response = fileSystem.shellApiHandler.openFile({"uri":uri}); | ||
108 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ | ||
109 | fileContent = response.content; | ||
110 | } | ||
111 | |||
112 | console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); | ||
113 | this.openDocument({"type": "js", "name": "tmp.js", "source": fileContent}); | ||
114 | } | ||
115 | |||
116 | } | ||
117 | }, | ||
118 | |||
119 | openProjectWithURI: { | ||
120 | value: function(uri) { | ||
121 | console.log("URI is: ", uri); | ||
122 | |||
123 | // Get project from Jose Code with a callback to here | ||
124 | } | ||
125 | }, | ||
126 | |||
89 | /** Open a Document **/ | 127 | /** Open a Document **/ |
90 | openDocument: { | 128 | openDocument: { |
91 | value: function(doc) { | 129 | value: function(doc) { |
92 | var d; | 130 | var newDoc; |
93 | 131 | ||
94 | if(!doc) return false; | 132 | if(!doc) return false; |
95 | 133 | ||
96 | try { | 134 | // try { |
97 | if (doc.type === 'html' || doc.type === 'htm') { | 135 | if (doc.type === 'html' || doc.type === 'htm') { |
98 | d = Montage.create(HTMLDocument); | 136 | newDoc = Montage.create(HTMLDocument); |
99 | d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); | 137 | newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); |
100 | } else { | 138 | } else { |
101 | d = Montage.create(TextDocument); | 139 | newDoc = Montage.create(TextDocument, { |
102 | d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); | 140 | "source": { value: doc.source } |
141 | }); | ||
142 | newDoc.initialize(doc, Uuid.generate(), this._createTextAreaElement()); | ||
143 | |||
144 | // Tmp this will be filled with the real content | ||
145 | newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; | ||
146 | |||
147 | this.textDocumentOpened(newDoc); | ||
148 | |||
103 | } | 149 | } |
104 | 150 | ||
105 | } catch (err) { | 151 | // } catch (err) { |
106 | console.log("Could not open Document ", err); | 152 | // console.log("Could not open Document ", err); |
107 | } | 153 | // } |
108 | } | 154 | } |
109 | }, | 155 | }, |
110 | 156 | ||
157 | // Document has been loaded into the Iframe. Dispatch the event. | ||
158 | // Event Detail: Contains the current ActiveDocument | ||
159 | _onOpenDocument: { | ||
160 | value: function(doc){ | ||
161 | |||
162 | DocumentController.activeDocument = doc; | ||
163 | |||
164 | NJevent("onOpenDocument", doc); | ||
165 | |||
166 | } | ||
167 | }, | ||
168 | |||
169 | textDocumentOpened: { | ||
170 | value: function(doc) { | ||
171 | |||
172 | this.activeDocument = doc; | ||
173 | |||
174 | this.application.ninja.stage.stageView.createTextView(doc); | ||
175 | |||
176 | /* | ||
177 | DocumentManager._hideCurrentDocument(); | ||
178 | stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | ||
179 | DocumentManager.activeDocument = doc; | ||
180 | |||
181 | var type; | ||
182 | |||
183 | switch(doc.documentType) { | ||
184 | case "css" : | ||
185 | type = "css"; | ||
186 | break; | ||
187 | case "js" : | ||
188 | type = "javascript"; | ||
189 | break; | ||
190 | } | ||
191 | |||
192 | DocumentManager._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { | ||
193 |