diff options
Diffstat (limited to 'js/io/document/document-controller.js')
-rwxr-xr-x[-rw-r--r--] | js/io/document/document-controller.js | 321 |
1 files changed, 202 insertions, 119 deletions
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 99177de0..e36181bf 100644..100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -12,37 +12,31 @@ 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 | ||
35 | _codeEditor: { | 36 | tmpSourceForTesting: { |
36 | value: { | 37 | value: "function CodeMirror(place, givenOptions) {" + |
37 | "editor": { | 38 | "// Determine effective options based on given values and defaults." + |
38 | value: null, | 39 | "var options = {}, defaults = CodeMirror.defaults; }" |
39 | enumerable: false | ||
40 | }, | ||
41 | "hline": { | ||
42 | value: null, | ||
43 | enumerable: false | ||
44 | } | ||
45 | } | ||
46 | }, | 40 | }, |
47 | 41 | ||
48 | activeDocument: { | 42 | activeDocument: { |
@@ -50,33 +44,28 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
50 | return this._activeDocument; | 44 | return this._activeDocument; |
51 | }, | 45 | }, |
52 | set: function(doc) { | 46 | set: function(doc) { |
53 | if(this._activeDocument) { | 47 | 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 | 48 | ||
62 | if(this._documents.indexOf(doc) === -1) { | 49 | 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 | 50 | ||
67 | this._activeDocument = doc; | 51 | this._activeDocument = doc; |
68 | this._activeDocument.isActive = true; | 52 | this._activeDocument.isActive = true; |
69 | 53 | ||
70 | if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { | 54 | if(!!this._activeDocument.editor){ |
71 | // TODO selection should use the document own selectionModel | 55 | this._activeDocument.editor.focus(); |
72 | //selectionManagerModule.selectionManager._selectedItems = this._activeDocument.selectionModel; | ||
73 | } | 56 | } |
57 | |||
74 | } | 58 | } |
75 | }, | 59 | }, |
76 | 60 | ||
77 | deserializedFromTemplate: { | 61 | deserializedFromTemplate: { |
78 | value: function() { | 62 | value: function() { |
79 | this.eventManager.addEventListener("appLoaded", this, false); | 63 | this.eventManager.addEventListener("appLoaded", this, false); |
64 | this.eventManager.addEventListener("executeFileOpen", this, false); | ||
65 | this.eventManager.addEventListener("executeNewFile", this, false); | ||
66 | this.eventManager.addEventListener("executeSave", this, false); | ||
67 | |||
68 | this.eventManager.addEventListener("recordStyleChanged", this, false); | ||
80 | } | 69 | } |
81 | }, | 70 | }, |
82 | 71 | ||
@@ -86,84 +75,184 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
86 | } | 75 | } |
87 | }, | 76 | }, |
88 | 77 | ||
78 | handleExecuteFileOpen: { | ||
79 | value: function(event) { | ||
80 | var pickerSettings = event._event.settings || {}; | ||
81 | pickerSettings.callback = this.openFileWithURI; | ||
82 | pickerSettings.callbackScope = this; | ||
83 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
84 | } | ||
85 | }, | ||
86 | |||
87 | handleExecuteNewFile: { | ||
88 | value: function(event) { | ||
89 | var newFileSettings = event._event.settings || {}; | ||
90 | newFileSettings.callback = this.createNewFile; | ||
91 | newFileSettings.callbackScope = this; | ||
92 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
93 | } | ||
94 | }, | ||
95 | |||
96 | handleExecuteSave: { | ||
97 | value: function(event) { | ||
98 | this.activeDocument.save(); | ||
99 | } | ||
100 | }, | ||
101 | |||
102 | createNewFile:{ | ||
103 | value:function(newFileObj){ | ||
104 | //console.log(newFileObj);//contains the template uri and the new file uri | ||
105 | if(!newFileObj) return; | ||
106 | this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this)); | ||
107 | |||
108 | if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view | ||
109 | |||
110 | }else{ | ||
111 | //open design view | ||
112 | } | ||
113 | } | ||
114 | }, | ||
115 | |||
116 | /** | ||
117 | * Public method | ||
118 | * doc contains: | ||
119 | * type : file type, like js, css, etc | ||
120 | * name : file name | ||
121 | * source : file content | ||
122 | * uri : file uri | ||
123 | */ | ||
124 | openNewFileCallback:{ | ||
125 | value:function(doc){ | ||
126 | var response = doc || {"uri":"/Users/xhdq84/Documents/test.js", "success":true};//default just for testing | ||
127 | if(!!response && response.success && !!response.uri){ | ||
128 | this.application.ninja.ioMediator.fileOpen({"uri":response.uri}, this.openFileCallback.bind(this)); | ||
129 | } | ||
130 | } | ||
131 | }, | ||
132 | |||
133 | openFileWithURI: { | ||
134 | value: function(uriArrayObj) { | ||
135 | var uri = "", fileContent = "", response=null, filename="", fileType="js"; | ||
136 | if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ | ||
137 | uri = uriArrayObj.uri[0]; | ||
138 | } | ||
139 | //console.log("URI is: ", uri); | ||
140 | |||
141 | this.application.ninja.ioMediator.fileOpen({"uri":uri}, this.openFileCallback.bind(this)); | ||
142 | } | ||
143 | }, | ||
144 | |||
145 | /** | ||
146 | * Public method | ||
147 | * doc contains: | ||
148 | * type : file type, like js, css, etc | ||
149 | * name : file name | ||
150 | * source : file content | ||
151 | * uri : file uri | ||
152 | */ | ||
153 | openFileCallback:{ | ||
154 | value:function(doc){ | ||
155 | this.openDocument(doc); | ||
156 | } | ||
157 | }, | ||
158 | |||
159 | |||
160 | openProjectWithURI: { | ||
161 | value: function(uri) { | ||
162 | console.log("URI is: ", uri); | ||
163 | |||
164 | } | ||
165 | }, | ||
166 | |||
89 | /** Open a Document **/ | 167 | /** Open a Document **/ |
90 | openDocument: { | 168 | openDocument: { |
91 | value: function(doc) { | 169 | value: function(doc) { |
92 | var d; | 170 | var newDoc; |
93 | 171 | ||
94 | if(!doc) return false; | 172 | if(!doc) return false; |
95 | 173 | ||
96 | try { | 174 | // try { |
97 | if (doc.type === 'html' || doc.type === 'htm') { | 175 | if (doc.type === 'html' || doc.type === 'htm') { |
98 | d = Montage.create(HTMLDocument); | 176 | newDoc = Montage.create(HTMLDocument); |
99 | d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); | 177 | newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); |
100 | } else { | 178 | } else { |
101 | d = Montage.create(TextDocument); | 179 | newDoc = Montage.create(TextDocument, { |
102 | d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); | 180 | "source": { value: doc.source } |
181 | }); | ||
182 | var docUuid = Uuid.generate(); | ||
183 | var textArea = this.application.ninja.stage.stageView.createTextAreaElement(docUuid); | ||
184 | newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); | ||
< |