aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/code-editor-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/code-editor-controller.js')
-rw-r--r--js/controllers/code-editor-controller.js48
1 files changed, 36 insertions, 12 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 }