aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rw-r--r--js/controllers/code-editor-controller.js48
-rwxr-xr-xjs/controllers/document-controller.js327
-rwxr-xr-xjs/controllers/elements/element-controller.js23
-rwxr-xr-xjs/controllers/elements/shapes-controller.js4
-rwxr-xr-xjs/controllers/selection-controller.js96
-rwxr-xr-xjs/controllers/styles-controller.js98
-rwxr-xr-xjs/controllers/undo-controller.js8
7 files changed, 237 insertions, 367 deletions
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js
index e7163bd8..d292f838 100644
--- a/js/controllers/code-editor-controller.js
+++ b/js/controllers/code-editor-controller.js
@@ -9,11 +9,35 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component; 10 Component = require("montage/ui/component").Component;
11 11
12var CodeEditorController = exports.CodeEditorController = Montage.create(Component, { 12exports.CodeEditorController = Montage.create(Component, {
13 hasTemplate: { 13 hasTemplate: {
14 value: false 14 value: false
15 }, 15 },
16 16
17 _currentDocument: {
18 value : null
19 },
20
21 currentDocument : {
22 get : function() {
23 return this._currentDocument;
24 },
25 set : function(value) {
26 if (value === this._currentDocument) {
27 return;
28 }
29
30 this._currentDocument = value;
31
32 if(!value) {
33
34 } else if(this._currentDocument.currentView === "code") {
35 this._currentDocument.model.views.code.editor.focus();
36 this.applySettings();
37 }
38 }
39 },
40
17 _codeEditor : { 41 _codeEditor : {
18 value:null 42 value:null
19 }, 43 },
@@ -213,22 +237,22 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
213 237
214 autoFormatSelection:{ 238 autoFormatSelection:{
215 value: function(){ 239 value: function(){
216 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); 240 var range = this.getSelectedRange(this.currentDocument.model.views.code.editor);
217 this.application.ninja.documentController.activeDocument.model.views.code.editor.autoFormatRange(range.from, range.to); 241 this.currentDocument.model.views.code.editor.autoFormatRange(range.from, range.to);
218 } 242 }
219 }, 243 },
220 244
221 commentSelection:{ 245 commentSelection:{
222 value: function(isComment){ 246 value: function(isComment){
223 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); 247 var range = this.getSelectedRange(this.currentDocument.model.views.code.editor);
224 this.application.ninja.documentController.activeDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); 248 this.currentDocument.model.views.code.editor.commentRange(isComment, range.from, range.to);
225 } 249 }
226 }, 250 },
227 251
228 handleThemeSelection:{ 252 handleThemeSelection:{
229 value: function(){ 253 value: function(){
230 this.application.ninja.documentController.activeDocument.model.views.code.editor.setOption("theme", this.editorTheme); 254 this.currentDocument.model.views.code.editor.setOption("theme", this.editorTheme);
231 this.application.ninja.documentController.activeDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); 255 this.currentDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme);
232 } 256 }
233 }, 257 },
234 258
@@ -236,10 +260,10 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
236 value:function(value){ 260 value:function(value){
237 var originalFont=13,originalLineHeight=16; 261 var originalFont=13,originalLineHeight=16;
238 this._zoomFactor = value; 262 this._zoomFactor = value;
239 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; 263 this.currentDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px";
240 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.cursor = "text"; 264 this.currentDocument.model.views.code.textViewContainer.style.cursor = "text";
241 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; 265 this.currentDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px";
242 this.application.ninja.documentController.activeDocument.model.views.code.editor.refresh();//refresh editor display for xoom 266 this.currentDocument.model.views.code.editor.refresh();//refresh editor display for xoom
243 } 267 }
244 }, 268 },
245 269
@@ -248,7 +272,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
248 //set theme 272 //set theme
249 this.handleThemeSelection(); 273 this.handleThemeSelection();
250 //check autocomplete support 274 //check autocomplete support
251 this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.model.file.extension); 275 this.handleCodeCompletionSupport(this.currentDocument.model.file.extension);
252 //set zoom 276 //set zoom
253 this.handleZoom(this._zoomFactor); 277 this.handleZoom(this._zoomFactor);
254 } 278 }
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 2c34eedf..f85e2f97 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -8,37 +8,58 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 Uuid = require("montage/core/uuid").Uuid,
12 HTMLDocument = require("js/document/document-html").HtmlDocument, 11 HTMLDocument = require("js/document/document-html").HtmlDocument,
13 TextDocument = require("js/document/document-text").TextDocument; 12 TextDocument = require("js/document/document-text").TextDocument;
14//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
15// 14//
16exports.DocumentController = Montage.create(Component, { 15exports.DocumentController = Montage.create(Component, {
17 // 16 //
18 hasTemplate: {value: false}, 17 hasTemplate: {
19 _documents: {value: []}, 18 value: false
20 //TODO: what is this?!?! 19 },
21 _hackInitialStyles: {value: true}, 20
22 _activeDocument: { value: null }, 21 iframeContainer: {
23 //TODO: Are any of these needed? 22 value: null
24 _iframeCounter: { value: 1, enumerable: false }, 23 },
25 _iframeHolder: { value: null, enumerable: false }, 24
26 _textHolder: { value: null, enumerable: false }, 25 codeContainer: {
27 _codeMirrorCounter: {value: 1, enumerable: false}, 26 value: null
28 27 },
29 activeDocument: { 28
30 get: function() { 29 documents: {
31 return this._activeDocument; 30 value: []
31 },
32
33 _currentDocument: {
34 value : null
35 },
36
37 currentDocument : {
38 get : function() {
39 return this._currentDocument;
32 }, 40 },
33 set: function(doc) { 41 set : function(value) {
34 //if(!!this._activeDocument){ this._activeDocument.isActive = false;} 42 if (value === this._currentDocument) {
43 return;
44 }
35 45
36 this._activeDocument = doc; 46 if(this._currentDocument) {
47 this._currentDocument.model.currentView.hide();
48 }
49
50 this._currentDocument = value;
37 51
38 if(!!this._activeDocument){ 52 if(!value) {
39 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 53 document.getElementById("iframeContainer").style.display = "block";
40 this._activeDocument.isActive = true; 54 document.getElementById("codeViewContainer").style.display = "block";
55 } else if(this._currentDocument.currentView === "design") {
56 this._currentDocument.model.currentView.show();
57 this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*');
58 } else {
59 document.getElementById("iframeContainer").style.display = "none";
60 this._currentDocument.model.currentView.show();
41 } 61 }
62
42 } 63 }
43 }, 64 },
44 65
@@ -52,11 +73,15 @@ exports.DocumentController = Montage.create(Component, {
52 this.eventManager.addEventListener("executeSaveAll", this, false); 73 this.eventManager.addEventListener("executeSaveAll", this, false);
53 this.eventManager.addEventListener("executeFileClose", this, false); 74 this.eventManager.addEventListener("executeFileClose", this, false);
54 this.eventManager.addEventListener("executeFileCloseAll", this, false); 75 this.eventManager.addEventListener("executeFileCloseAll", this, false);
76 }
77 },
55 78
56 this.eventManager.addEventListener("styleSheetDirty", this, false); 79 didCreate: {
80 value: function() {
81 this.iframeContainer = document.getElementById("iframeContainer");
82 this.codeContainer = document.getElementById("codeViewContainer");
57 } 83 }
58 }, 84 },
59
60 85
61 //TODO: Ensure these APIs are not needed 86 //TODO: Ensure these APIs are not needed
62 redirectRequests: { 87 redirectRequests: {
@@ -70,11 +95,11 @@ exports.DocumentController = Montage.create(Component, {
70 if (this.redirectRequests && request.parentFrameId !== -1) { 95 if (this.redirectRequests && request.parentFrameId !== -1) {
71 //Checking for proper URL redirect (from different directories) 96 //Checking for proper URL redirect (from different directories)
72 if (request.url.indexOf('js/document/templates/banner') !== -1) { 97 if (request.url.indexOf('js/document/templates/banner') !== -1) {
73<