diff options
author | Jose Antonio Marquez | 2012-02-04 22:35:28 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-04 22:35:28 -0800 |
commit | d1fda420f898965b5dd57de0c8340886cef308a8 (patch) | |
tree | 2fad2e890c1142a7eee30c45710f1f0b78adfdde /js/io/document/document-controller.js | |
parent | cc64cfc5aaa570ed9f72545fc135200019d62311 (diff) | |
parent | 45cfffd9261ab1aa714554c584f0d0d8fe627c91 (diff) | |
download | ninja-d1fda420f898965b5dd57de0c8340886cef308a8.tar.gz |
Merge branch 'refs/heads/AnanyaFileIO' into FileIO
Diffstat (limited to 'js/io/document/document-controller.js')
-rwxr-xr-x | js/io/document/document-controller.js | 84 |
1 files changed, 65 insertions, 19 deletions
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index d7a19e35..ca6b4533 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -15,7 +15,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
15 | var Montage = require("montage/core/core").Montage, | 15 | var Montage = require("montage/core/core").Montage, |
16 | Component = require("montage/ui/component").Component, | 16 | Component = require("montage/ui/component").Component, |
17 | Uuid = require("montage/core/uuid").Uuid, | 17 | Uuid = require("montage/core/uuid").Uuid, |
18 | //nj= ("js/lib/NJUtils.js").NJUtils, | ||
19 | HTMLDocument = require("js/io/document/html-document").HTMLDocument, | 18 | HTMLDocument = require("js/io/document/html-document").HTMLDocument, |
20 | TextDocument = require("js/io/document/text-document").TextDocument; | 19 | TextDocument = require("js/io/document/text-document").TextDocument; |
21 | 20 | ||
@@ -71,8 +70,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
71 | deserializedFromTemplate: { | 70 | deserializedFromTemplate: { |
72 | value: function() { | 71 | value: function() { |
73 | this.eventManager.addEventListener("appLoaded", this, false); | 72 | this.eventManager.addEventListener("appLoaded", this, false); |
74 | |||
75 | this.eventManager.addEventListener("executeFileOpen", this, false); | 73 | this.eventManager.addEventListener("executeFileOpen", this, false); |
74 | this.eventManager.addEventListener("executeNewFile", this, false); | ||
76 | } | 75 | } |
77 | }, | 76 | }, |
78 | 77 | ||
@@ -93,6 +92,46 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
93 | } | 92 | } |
94 | }, | 93 | }, |
95 | 94 | ||
95 | handleExecuteNewFile: { | ||
96 | value: function(event) { | ||
97 | var newFileSettings = event._event.settings || {}; | ||
98 | newFileSettings.callback = this.createNewFile; | ||
99 | newFileSettings.callbackScope = this; | ||
100 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
101 | } | ||
102 | }, | ||
103 | |||
104 | createNewFile:{ | ||
105 | value:function(newFileObj){ | ||
106 | //console.log(newFileObj);//contains the template uri and the new file uri | ||
107 | if(!newFileObj) return; | ||
108 | this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this}); | ||
109 | |||
110 | if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view | ||
111 | |||
112 | }else{ | ||
113 | //open design view | ||
114 | } | ||
115 | } | ||
116 | }, | ||
117 | |||
118 | /** | ||
119 | * Public method | ||
120 | * doc contains: | ||
121 | * type : file type, like js, css, etc | ||
122 | * name : file name | ||
123 | * source : file content | ||
124 | * uri : file uri | ||
125 | */ | ||
126 | openNewFileCallback:{ | ||
127 | value:function(doc){ | ||
128 | if(!doc){ | ||
129 | doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; | ||
130 | } | ||
131 | this.openDocument(doc); | ||
132 | } | ||
133 | }, | ||
134 | |||
96 | openFileWithURI: { | 135 | openFileWithURI: { |
97 | value: function(uriArrayObj) { | 136 | value: function(uriArrayObj) { |
98 | var uri = "", fileContent = "", response=null, filename="", fileType="js"; | 137 | var uri = "", fileContent = "", response=null, filename="", fileType="js"; |
@@ -101,20 +140,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
101 | } | 140 | } |
102 | //console.log("URI is: ", uri); | 141 | //console.log("URI is: ", uri); |
103 | 142 | ||
104 | if(!!uri){ | 143 | this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this}); |
105 | response = this.application.ninja.coreIoApi.openFile({"uri":uri}); | 144 | } |
106 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ | 145 | }, |
107 | fileContent = response.content; | ||
108 | } | ||
109 | |||
110 | //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); | ||
111 | filename = nj.getFileNameFromPath(uri); | ||
112 | if(uri.indexOf('.') != -1){ | ||
113 | fileType = uri.substr(uri.lastIndexOf('.') + 1); | ||
114 | } | ||
115 | this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri}); | ||
116 | } | ||
117 | 146 | ||
147 | /** | ||
148 | * Public method | ||
149 | * doc contains: | ||
150 | * type : file type, like js, css, etc | ||
151 | * name : file name | ||
152 | * source : file content | ||
153 | * uri : file uri | ||
154 | */ | ||
155 | openFileCallback:{ | ||
156 | value:function(doc){ | ||
157 | this.openDocument(doc); | ||
118 | } | 158 | } |
119 | }, | 159 | }, |
120 | 160 | ||
@@ -146,7 +186,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
146 | newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); | 186 | newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); |
147 | 187 | ||
148 | // Tmp this will be filled with the real content | 188 | // Tmp this will be filled with the real content |
149 | newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; | 189 | newDoc.textArea.value = doc.source; //this.tmpSourceForTesting; |
150 | 190 | ||
151 | this.textDocumentOpened(newDoc); | 191 | this.textDocumentOpened(newDoc); |
152 | 192 | ||
@@ -161,7 +201,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
161 | textDocumentOpened: { | 201 | textDocumentOpened: { |
162 | value: function(doc) { | 202 | value: function(doc) { |
163 | 203 | ||
164 | this.activeDocument = doc; | 204 | |
165 | 205 | ||
166 | this.application.ninja.stage.stageView.createTextView(doc); | 206 | this.application.ninja.stage.stageView.createTextView(doc); |
167 | 207 | ||
@@ -363,7 +403,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
363 | value: function() { | 403 | value: function() { |
364 | if(this.activeDocument) { | 404 | if(this.activeDocument) { |
365 | this.activeDocument.container.style["display"] = "none"; | 405 | this.activeDocument.container.style["display"] = "none"; |
366 | //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); | 406 | if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ |
407 | this.activeDocument.container.parentNode.style["display"] = "none"; | ||
408 | this.application.ninja.stage.hideCanvas(true); | ||
409 | } | ||
367 | } | 410 | } |
368 | } | 411 | } |
369 | }, | 412 | }, |
@@ -372,7 +415,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
372 | value: function() { | 415 | value: function() { |
373 | if(this.activeDocument) { | 416 | if(this.activeDocument) { |
374 | this.activeDocument.container.style["display"] = "block"; | 417 | this.activeDocument.container.style["display"] = "block"; |
375 | //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); | 418 | if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ |
419 | this.activeDocument.container.parentNode.style["display"] = "block"; | ||
420 | this.application.ninja.stage.hideCanvas(false); | ||
421 | } | ||
376 | } | 422 | } |
377 | } | 423 | } |
378 | }, | 424 | }, |