diff options
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/code-editor-controller.js | 83 |
1 files changed, 31 insertions, 52 deletions
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, { | |||
32 | if(!value) { | 32 | if(!value) { |
33 | 33 | ||
34 | } else if(this._currentDocument.currentView === "code") { | 34 | } else if(this._currentDocument.currentView === "code") { |
35 | this.autocomplete = !this.codeCompletionSupport[this._currentDocument.model.file.extension]; | ||
35 | this._currentDocument.model.views.code.editor.focus(); | 36 | this._currentDocument.model.views.code.editor.focus(); |
36 | this.applySettings(); | 37 | this.applySettings(); |
37 | } | 38 | } |
@@ -51,13 +52,23 @@ exports.CodeEditorController = Montage.create(Component, { | |||
51 | value: {"js": true} | 52 | value: {"js": true} |
52 | }, | 53 | }, |
53 | 54 | ||
55 | autocomplete: { | ||
56 | value: false | ||
57 | }, | ||
58 | |||
54 | _automaticCodeComplete: { | 59 | _automaticCodeComplete: { |
55 | value:false | 60 | value:false |
56 | }, | 61 | }, |
57 | 62 | ||
58 | automaticCodeComplete:{ | 63 | automaticCodeComplete:{ |
59 | get: function(){return this._automaticCodeComplete;}, | 64 | get: function(){ |
60 | set: function(value){this._automaticCodeComplete = value;} | 65 | return this._automaticCodeComplete; |
66 | }, | ||
67 | set: function(value) { | ||
68 | if(this._automaticCodeComplete !== value) { | ||
69 | this._automaticCodeComplete = value; | ||
70 | } | ||
71 | } | ||
61 | }, | 72 | }, |
62 | 73 | ||
63 | _editorTheme: { | 74 | _editorTheme: { |
@@ -65,17 +76,23 @@ exports.CodeEditorController = Montage.create(Component, { | |||
65 | }, | 76 | }, |
66 | 77 | ||
67 | editorTheme:{ | 78 | editorTheme:{ |
68 | get: function(){return this._editorTheme;}, | 79 | get: function(){ |
69 | set: function(value){this._editorTheme = value;} | 80 | return this._editorTheme; |
81 | }, | ||
82 | set: function(value){ | ||
83 | this._editorTheme = value; | ||
84 | } | ||
70 | }, | 85 | }, |
71 | 86 | ||
72 | _zoomFactor:{ | 87 | _zoomFactor: { |
73 | value:100 | 88 | value:100 |
74 | }, | 89 | }, |
75 | 90 | ||
76 | zoomFactor:{ | 91 | zoomFactor:{ |
77 | get: function(){return this._zoomFactor;}, | 92 | get: function() { |
78 | set: function(value){ | 93 | return this._zoomFactor; |
94 | }, | ||
95 | set: function(value) { | ||
79 | this.handleZoom(value); | 96 | this.handleZoom(value); |
80 | } | 97 | } |
81 | }, | 98 | }, |
@@ -115,13 +132,15 @@ exports.CodeEditorController = Montage.create(Component, { | |||
115 | }; | 132 | }; |
116 | 133 | ||
117 | //configure auto code completion if it is supported for that document type | 134 | //configure auto code completion if it is supported for that document type |
118 | if(this.codeCompletionSupport[documentType] === true){ | 135 | if(this.autocomplete) { |
119 | editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)}; | ||
120 | } | ||
121 | 136 | ||
122 | var editor = self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); | 137 | editorOptions.onKeyEvent = function(cm, keyEvent){ |
138 | self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType) | ||
139 | }; | ||
123 | 140 | ||
124 | return editor; | 141 | } |
142 | |||
143 | return self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); | ||
125 | } | 144 | } |
126 | }, | 145 | }, |
127 | 146 | ||
@@ -198,50 +217,12 @@ exports.CodeEditorController = Montage.create(Component, { | |||
198 | } | 217 | } |
199 | }, | 218 | }, |
200 | 219 | ||
201 | handleCodeCompletionSupport:{ | ||
202 | value:function(fileType){ | ||
203 | var autoCodeCompleteElem = document.getElementsByClassName("autoCodeComplete")[0], elems=null, i=0; | ||
204 | if(autoCodeCompleteElem){ | ||
205 | elems = autoCodeCompleteElem.getElementsByTagName("*"); | ||
206 | } | ||
207 | |||
208 | if(elems && (this.codeCompletionSupport[fileType] === true)){ | ||
209 | //enable elements | ||
210 | for(i=0;i<elems.length;i++){ | ||
211 | if(elems[i].hasAttribute("disabled")){ | ||
212 | elems[i].removeAttribute("disabled"); | ||
213 | } | ||
214 | if(elems[i].classList.contains("disabled")){ | ||
215 | elems[i].classList.remove("disabled"); | ||
216 | } | ||
217 | } | ||
218 | }else if(elems && !this.codeCompletionSupport[fileType]){ | ||
219 | //disable elements | ||
220 | for(i=0;i<elems.length;i++){ | ||
221 | if(!elems[i].hasAttribute("disabled")){ | ||
222 | elems[i].setAttribute("disabled", "disabled"); | ||
223 | } | ||
224 | if(!elems[i].classList.contains("disabled")){ | ||
225 | elems[i].classList.add("disabled"); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | }, | ||
231 | |||
232 | getSelectedRange:{ | 220 | getSelectedRange:{ |
233 | value:function(editor){ | 221 | value:function(editor){ |
234 | return { from: editor.getCursor(true), to: editor.getCursor(false) }; | 222 | return { from: editor.getCursor(true), to: editor.getCursor(false) }; |
235 | } | 223 | } |
236 | }, | 224 | }, |
237 | 225 | ||
238 | autoFormatSelection:{ | ||
239 | value: function(){ | ||
240 | var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); | ||
241 | this.currentDocument.model.views.code.editor.autoFormatRange(range.from, range.to); | ||
242 | } | ||
243 | }, | ||
244 | |||
245 | commentSelection:{ | 226 | commentSelection:{ |
246 | value: function(isComment){ | 227 | value: function(isComment){ |
247 | var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); | 228 | var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); |
@@ -271,8 +252,6 @@ exports.CodeEditorController = Montage.create(Component, { | |||
271 | value:function(){ | 252 | value:function(){ |
272 | //set theme | 253 | //set theme |
273 | this.handleThemeSelection(); | 254 | this.handleThemeSelection(); |
274 | //check autocomplete support | ||
275 | this.handleCodeCompletionSupport(this.currentDocument.model.file.extension); | ||
276 | //set zoom | 255 | //set zoom |
277 | this.handleZoom(this._zoomFactor); | 256 | this.handleZoom(this._zoomFactor); |
278 | } | 257 | } |