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 From f51718fc39f1311a13cc6c998eb63160dc25218d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 31 May 2012 00:31:22 -0700 Subject: cleanup items Signed-off-by: Valerio Virgillito --- js/controllers/code-editor-controller.js | 1 + 1 file changed, 1 insertion(+) (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 d0b1f179..d292f838 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -32,6 +32,7 @@ exports.CodeEditorController = Montage.create(Component, { if(!value) { } else if(this._currentDocument.currentView === "code") { + this._currentDocument.model.views.code.editor.focus(); this.applySettings(); } } -- cgit v1.2.3 From 3a3a2351ea2d816bf953cbf76622772f7d64aa8b Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 1 Jun 2012 00:16:31 -0700 Subject: fixing the code editor, closing documents and cleanup of the stage Signed-off-by: Valerio Virgillito --- js/controllers/code-editor-controller.js | 83 ++++++++++++-------------------- 1 file changed, 31 insertions(+), 52 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 d292f838..f3c19b92 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -32,6 +32,7 @@ exports.CodeEditorController = Montage.create(Component, { if(!value) { } else if(this._currentDocument.currentView === "code") { + this.autocomplete = !this.codeCompletionSupport[this._currentDocument.model.file.extension]; this._currentDocument.model.views.code.editor.focus(); this.applySettings(); } @@ -51,13 +52,23 @@ exports.CodeEditorController = Montage.create(Component, { value: {"js": true} }, + autocomplete: { + value: false + }, + _automaticCodeComplete: { value:false }, automaticCodeComplete:{ - get: function(){return this._automaticCodeComplete;}, - set: function(value){this._automaticCodeComplete = value;} + get: function(){ + return this._automaticCodeComplete; + }, + set: function(value) { + if(this._automaticCodeComplete !== value) { + this._automaticCodeComplete = value; + } + } }, _editorTheme: { @@ -65,17 +76,23 @@ exports.CodeEditorController = Montage.create(Component, { }, editorTheme:{ - get: function(){return this._editorTheme;}, - set: function(value){this._editorTheme = value;} + get: function(){ + return this._editorTheme; + }, + set: function(value){ + this._editorTheme = value; + } }, - _zoomFactor:{ + _zoomFactor: { value:100 }, zoomFactor:{ - get: function(){return this._zoomFactor;}, - set: function(value){ + get: function() { + return this._zoomFactor; + }, + set: function(value) { this.handleZoom(value); } }, @@ -115,13 +132,15 @@ exports.CodeEditorController = Montage.create(Component, { }; //configure auto code completion if it is supported for that document type - if(this.codeCompletionSupport[documentType] === true){ - editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)}; - } + if(this.autocomplete) { - var editor = self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); + editorOptions.onKeyEvent = function(cm, keyEvent){ + self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType) + }; - return editor; + } + + return self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); } }, @@ -198,50 +217,12 @@ exports.CodeEditorController = Montage.create(Component, { } }, - handleCodeCompletionSupport:{ - value:function(fileType){ - var autoCodeCompleteElem = document.getElementsByClassName("autoCodeComplete")[0], elems=null, i=0; - if(autoCodeCompleteElem){ - elems = autoCodeCompleteElem.getElementsByTagName("*"); - } - - if(elems && (this.codeCompletionSupport[fileType] === true)){ - //enable elements - for(i=0;i