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') 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