diff options
Diffstat (limited to 'js/io/document/document-controller.js')
-rwxr-xr-x | js/io/document/document-controller.js | 91 |
1 files changed, 40 insertions, 51 deletions
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index bba7e0e7..8ce43dcc 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -99,9 +99,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
99 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ | 99 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ |
100 | uri = uriArrayObj.uri[0]; | 100 | uri = uriArrayObj.uri[0]; |
101 | } | 101 | } |
102 | console.log("URI is: ", uri); | 102 | //console.log("URI is: ", uri); |
103 | 103 | ||
104 | // Get file from Jose Code with a callback to here | ||
105 | if(!!uri){ | 104 | if(!!uri){ |
106 | response = this.application.ninja.coreIoApi.openFile({"uri":uri}); | 105 | response = this.application.ninja.coreIoApi.openFile({"uri":uri}); |
107 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ | 106 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ |
@@ -113,7 +112,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
113 | if(uri.indexOf('.') != -1){ | 112 | if(uri.indexOf('.') != -1){ |
114 | fileType = uri.substr(uri.lastIndexOf('.') + 1); | 113 | fileType = uri.substr(uri.lastIndexOf('.') + 1); |
115 | } | 114 | } |
116 | this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent}); | 115 | this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri}); |
117 | } | 116 | } |
118 | 117 | ||
119 | } | 118 | } |
@@ -124,7 +123,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
124 | value: function(uri) { | 123 | value: function(uri) { |
125 | console.log("URI is: ", uri); | 124 | console.log("URI is: ", uri); |
126 | 125 | ||
127 | // Get project from Jose Code with a callback to here | ||
128 | } | 126 | } |
129 | }, | 127 | }, |
130 | 128 | ||
@@ -143,7 +141,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
143 | newDoc = Montage.create(TextDocument, { | 141 | newDoc = Montage.create(TextDocument, { |
144 | "source": { value: doc.source } | 142 | "source": { value: doc.source } |
145 | }); | 143 | }); |
146 | newDoc.initialize(doc, Uuid.generate(), this._createTextAreaElement()); | 144 | var docUuid = Uuid.generate(); |
145 | var textArea = this.application.ninja.stage.stageView.createTextAreaElement(docUuid); | ||
146 | newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); | ||
147 | 147 | ||
148 | // Tmp this will be filled with the real content | 148 | // Tmp this will be filled with the real content |
149 | newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; | 149 | newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; |
@@ -158,18 +158,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
158 | } | 158 | } |
159 | }, | 159 | }, |
160 | 160 | ||
161 | // Document has been loaded into the Iframe. Dispatch the event. | ||
162 | // Event Detail: Contains the current ActiveDocument | ||
163 | _onOpenDocument: { | ||
164 | value: function(doc){ | ||
165 | |||
166 | DocumentController.activeDocument = doc; | ||
167 | |||
168 | NJevent("onOpenDocument", doc); | ||
169 | |||
170 | } | ||
171 | }, | ||
172 | |||
173 | textDocumentOpened: { | 161 | textDocumentOpened: { |
174 | value: function(doc) { | 162 | value: function(doc) { |
175 | 163 | ||
@@ -209,13 +197,31 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
209 | 197 | ||
210 | closeDocument: { | 198 | closeDocument: { |
211 | value: function(id) { | 199 | value: function(id) { |
200 | |||
201 | //if file dirty then save | ||
202 | |||
212 | var doc = this._findDocumentByUUID(id); | 203 | var doc = this._findDocumentByUUID(id); |
213 | this._removeDocumentView(doc.container); | 204 | this._removeDocumentView(doc.container); |
214 | 205 | ||
215 | this._documents.splice(this._findIndexByUUID(id), 1); | 206 | this._documents.splice(this._findIndexByUUID(id), 1); |
216 | 207 | ||
217 | if(this.activeDocument.uuid === id && this._documents.length > 0) { | 208 | if(this.activeDocument.uuid === id && this._documents.length > 0) { |
209 | |||
210 | var closeDocumentIndex = this._findIndexByUUID(id); | ||
211 | var nextDocumentIndex = -1 ; | ||
212 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ | ||
213 | nextDocumentIndex = 1; | ||
214 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ | ||
215 | nextDocumentIndex = closeDocumentIndex - 1; | ||
216 | } | ||
217 | |||
218 | //remove the codemirror div if this is for a code view | ||
219 | /////test | ||
220 | |||
221 | ////end- test | ||
222 | |||
218 | this.switchDocument(this._documents[0].uuid); | 223 | this.switchDocument(this._documents[0].uuid); |
224 | |||
219 | } | 225 | } |
220 | } | 226 | } |
221 | }, | 227 | }, |
@@ -238,6 +244,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
238 | 244 | ||
239 | switchViews: { | 245 | switchViews: { |
240 | value: function() { | 246 | value: function() { |
247 | |||
248 | //save file if dirty | ||
249 | |||
241 | this.application.ninja.stage.saveScroll(); | 250 | this.application.ninja.stage.saveScroll(); |
242 | this._hideCurrentDocument(); | 251 | this._hideCurrentDocument(); |
243 | 252 | ||
@@ -250,19 +259,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
250 | 259 | ||
251 | } else { | 260 | } else { |
252 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | 261 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe |
253 | var codeview = this._createTextAreaElement(); | 262 | |
254 | this._textHolder.style.display = "block"; | 263 | var codeview = this.activeDocument.container; |
255 | codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; | 264 | //this._textHolder.style.display = "block"; |
256 | 265 | //codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; | |
257 | this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { | 266 | |
258 | lineNumbers: true, | 267 | // this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { |
259 | mode: "htmlmixed", | 268 | // lineNumbers: true, |
260 | onCursorActivity: function() { | 269 | // mode: "htmlmixed", |
261 | DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); | 270 | // onCursorActivity: function() { |
262 | DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); | 271 | // DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); |
263 | } | 272 | // DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); |
264 | }); | 273 | // } |
265 | this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); | 274 | // }); |
275 | // this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); | ||
266 | } | 276 | } |
267 | } | 277 | } |
268 | }, | 278 | }, |
@@ -405,26 +415,5 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
405 | value: function() { | 415 | value: function() { |
406 | return "userDocument_" + (this._iframeCounter++); | 416 | return "userDocument_" + (this._iframeCounter++); |
407 | } | 417 | } |
408 | }, | ||
409 | |||
410 | /** | ||
411 | * Creates a text area which will contain the content of the opened text document. | ||
412 | */ | ||
413 | _createTextAreaElement: { | ||
414 | value: function() { | ||
415 | var codeMirrorDiv = document.createElement("div"); | ||
416 | codeMirrorDiv.id = "codeMirror_" + (this._codeMirrorCounter++); | ||
417 | |||
418 | var textArea = document.createElement("textarea"); | ||
419 | textArea.id = "code"; | ||
420 | textArea.name = "code"; | ||
421 | |||
422 | //codeMirrorDiv.appendChild(textArea); | ||
423 | |||
424 | // if(!this._textHolder) this._textHolder = document.getElementById("codeViewContainer"); | ||
425 | // this._textHolder.appendChild(codeMirrorDiv); | ||
426 | |||
427 | return textArea; | ||
428 | } | ||
429 | } | 418 | } |
430 | }); \ No newline at end of file | 419 | }); \ No newline at end of file |