diff options
Diffstat (limited to 'js/io/document/document-controller.js')
-rwxr-xr-x[-rw-r--r--] | js/io/document/document-controller.js | 310 |
1 files changed, 219 insertions, 91 deletions
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 99177de0..1a5d6058 100644..100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -12,26 +12,33 @@ 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, |
20 | 18 | HTMLDocument = require("js/io/document/html-document").HTMLDocument, | |
21 | var HTMLDocument = require("js/io/document/html-document").HTMLDocument; | 19 | TextDocument = require("js/io/document/text-document").TextDocument; |
22 | var TextDocument = require("js/io/document/text-document").TextDocument; | ||
23 | 20 | ||
24 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 21 | var DocumentController = exports.DocumentController = Montage.create(Component, { |
25 | hasTemplate: { value: false }, | 22 | hasTemplate: { |
23 | value: false | ||
24 | }, | ||
25 | |||
26 | _documents: { | ||
27 | value: [] | ||
28 | }, | ||
26 | 29 | ||
27 | _documents: { value: [] }, | ||
28 | _documentsHash: { value: {} }, | ||
29 | _activeDocument: { value: null }, | 30 | _activeDocument: { value: null }, |
30 | _iframeCounter: { value: 1, enumerable: false }, | 31 | _iframeCounter: { value: 1, enumerable: false }, |
31 | _iframeHolder: { value: null, enumerable: false }, | 32 | _iframeHolder: { value: null, enumerable: false }, |
32 | _textHolder: { value: null, enumerable: false }, | 33 | _textHolder: { value: null, enumerable: false }, |
33 | _codeMirrorCounter: {value: 1, enumerable: false}, | 34 | _codeMirrorCounter: {value: 1, enumerable: false}, |
34 | 35 | ||
36 | tmpSourceForTesting: { | ||
37 | value: "function CodeMirror(place, givenOptions) {" + | ||
38 | "// Determine effective options based on given values and defaults." + | ||
39 | "var options = {}, defaults = CodeMirror.defaults; }" | ||
40 | }, | ||
41 | |||
35 | _codeEditor: { | 42 | _codeEditor: { |
36 | value: { | 43 | value: { |
37 | "editor": { | 44 | "editor": { |
@@ -50,33 +57,22 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
50 | return this._activeDocument; | 57 | return this._activeDocument; |
51 | }, | 58 | }, |
52 | set: function(doc) { | 59 | set: function(doc) { |
53 | if(this._activeDocument) { | 60 | 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 | 61 | ||
62 | if(this._documents.indexOf(doc) === -1) { | 62 | 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 | 63 | ||
67 | this._activeDocument = doc; | 64 | this._activeDocument = doc; |
68 | this._activeDocument.isActive = true; | 65 | this._activeDocument.isActive = true; |
69 | 66 | ||
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 | } | 67 | } |
75 | }, | 68 | }, |
76 | 69 | ||
77 | deserializedFromTemplate: { | 70 | deserializedFromTemplate: { |
78 | value: function() { | 71 | value: function() { |
79 | this.eventManager.addEventListener("appLoaded", this, false); | 72 | this.eventManager.addEventListener("appLoaded", this, false); |
73 | this.eventManager.addEventListener("executeFileOpen", this, false); | ||
74 | this.eventManager.addEventListener("executeNewFile", this, false); | ||
75 | this.eventManager.addEventListener("executeSave", this, false); | ||
80 | } | 76 | } |
81 | }, | 77 | }, |
82 | 78 | ||
@@ -86,59 +82,196 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
86 | } | 82 | } |
87 | }, | 83 | }, |
88 | 84 | ||
85 | handleExecuteFileOpen: { | ||
86 | value: function(event) { | ||
87 | var pickerSettings = event._event.settings || {}; | ||
88 | pickerSettings.callback = this.openFileWithURI; | ||
89 | pickerSettings.callbackScope = this; | ||
90 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
91 | } | ||
92 | }, | ||
93 | |||
94 | handleExecuteNewFile: { | ||
95 | value: function(event) { | ||
96 | var newFileSettings = event._event.settings || {}; | ||
97 | newFileSettings.callback = this.createNewFile; | ||
98 | newFileSettings.callbackScope = this; | ||
99 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
100 | } | ||
101 | }, | ||
102 | |||
103 | handleExecuteSave: { | ||
104 | value: function(event) { | ||
105 | this.activeDocument.save(); | ||
106 | } | ||
107 | }, | ||
108 | |||
109 | createNewFile:{ | ||
110 | value:function(newFileObj){ | ||
111 | //console.log(newFileObj);//contains the template uri and the new file uri | ||
112 | if(!newFileObj) return; | ||
113 | this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this}); | ||
114 | |||
115 | if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view | ||
116 | |||
117 | }else{ | ||
118 | //open design view | ||
119 | } | ||
120 | } | ||
121 | }, | ||
122 | |||
123 | /** | ||
124 | * Public method | ||
125 | * doc contains: | ||
126 | * type : file type, like js, css, etc | ||
127 | * name : file name | ||
128 | * source : file content | ||
129 | * uri : file uri | ||
130 | */ | ||
131 | openNewFileCallback:{ | ||
132 | value:function(doc){ | ||
133 | if(!doc){ | ||
134 | doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; | ||
135 | } | ||
136 | this.openDocument(doc); | ||
137 | } | ||
138 | }, | ||
139 | |||
140 | openFileWithURI: { | ||
141 | value: function(uriArrayObj) { | ||
142 | var uri = "", fileContent = "", response=null, filename="", fileType="js"; | ||
143 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ | ||
144 | uri = uriArrayObj.uri[0]; | ||
145 | } | ||
146 | //console.log("URI is: ", uri); | ||
147 | |||
148 | this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this}); | ||
149 | } | ||
150 | }, | ||
151 | |||
152 | /** | ||
153 | * Public method | ||
154 | * doc contains: | ||
155 | * type : file type, like js, css, etc | ||
156 | * name : file name | ||
157 | * source : file content | ||
158 | * uri : file uri | ||
159 | */ | ||
160 | openFileCallback:{ | ||
161 | value:function(doc){ | ||
162 | this.openDocument(doc); | ||
163 | } | ||
164 | }, | ||
165 | |||
166 | |||
167 | openProjectWithURI: { | ||
168 | value: function(uri) { | ||
169 | console.log("URI is: ", uri); | ||
170 | |||
171 | } | ||
172 | }, | ||
173 | |||
89 | /** Open a Document **/ | 174 | /** Open a Document **/ |
90 | openDocument: { | 175 | openDocument: { |
91 | value: function(doc) { | 176 | value: function(doc) { |
92 | var d; | 177 | var newDoc; |
93 | 178 | ||
94 | if(!doc) return false; | 179 | if(!doc) return false; |
95 | 180 | ||
96 | try { | 181 | // try { |
97 | if (doc.type === 'html' || doc.type === 'htm') { | 182 | if (doc.type === 'html' || doc.type === 'htm') { |
98 | d = Montage.create(HTMLDocument); | 183 | newDoc = Montage.create(HTMLDocument); |
99 | d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); | 184 | newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); |
100 | } else { | 185 | } else { |
101 | d = Montage.create(TextDocument); | 186 | newDoc = Montage.create(TextDocument, { |
102 | d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); | 187 | "source": { value: doc.source } |
188 | }); | ||
189 | var docUuid = Uuid.generate(); | ||
190 | var textArea = this.application.ninja.stage.stageView.createTextAreaElement(docUuid); | ||
191 | newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); | ||
192 | |||
193 | // Tmp this will be filled with the real content | ||
194 | newDoc.textArea.value = doc.source; //this.tmpSourceForTesting; | ||
195 | |||
196 | this.textDocumentOpened(newDoc); | ||
197 | |||
103 | } | 198 | } |
104 | 199 | ||
105 | } catch (err) { | 200 | // } catch (err) { |
106 | console.log("Could not open Document ", err); | 201 | // console.log("Could not open Document ", err); |
107 | } |