From 0a769756547acb93346d8e1b4126931a78845255 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 30 May 2012 17:45:38 -0700 Subject: opening code view documents Signed-off-by: Valerio Virgillito --- js/controllers/code-editor-controller.js | 47 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index e7163bd8..d0b1f179 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -9,11 +9,34 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; -var CodeEditorController = exports.CodeEditorController = Montage.create(Component, { +exports.CodeEditorController = Montage.create(Component, { hasTemplate: { value: false }, + _currentDocument: { + value : null + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument) { + return; + } + + this._currentDocument = value; + + if(!value) { + + } else if(this._currentDocument.currentView === "code") { + this.applySettings(); + } + } + }, + _codeEditor : { value:null }, @@ -213,22 +236,22 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone autoFormatSelection:{ value: function(){ - var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); - this.application.ninja.documentController.activeDocument.model.views.code.editor.autoFormatRange(range.from, range.to); + var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); + this.currentDocument.model.views.code.editor.autoFormatRange(range.from, range.to); } }, commentSelection:{ value: function(isComment){ - var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); - this.application.ninja.documentController.activeDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); + var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); + this.currentDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); } }, handleThemeSelection:{ value: function(){ - this.application.ninja.documentController.activeDocument.model.views.code.editor.setOption("theme", this.editorTheme); - this.application.ninja.documentController.activeDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); + this.currentDocument.model.views.code.editor.setOption("theme", this.editorTheme); + this.currentDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); } }, @@ -236,10 +259,10 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone value:function(value){ var originalFont=13,originalLineHeight=16; this._zoomFactor = value; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.cursor = "text"; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; - this.application.ninja.documentController.activeDocument.model.views.code.editor.refresh();//refresh editor display for xoom + this.currentDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; + this.currentDocument.model.views.code.textViewContainer.style.cursor = "text"; + this.currentDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; + this.currentDocument.model.views.code.editor.refresh();//refresh editor display for xoom } }, @@ -248,7 +271,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone //set theme this.handleThemeSelection(); //check autocomplete support - this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.model.file.extension); + this.handleCodeCompletionSupport(this.currentDocument.model.file.extension); //set zoom this.handleZoom(this._zoomFactor); } -- cgit v1.2.3