aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rw-r--r--js/controllers/code-editor-controller.js262
1 files changed, 0 insertions, 262 deletions
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js
deleted file mode 100644
index 4572d69a..00000000
--- a/js/controllers/code-editor-controller.js
+++ /dev/null
@@ -1,262 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component;
11
12exports.CodeEditorController = Montage.create(Component, {
13 hasTemplate: {
14 value: false
15 },
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.autocomplete = this.codeCompletionSupport[this._currentDocument.model.file.extension];
36 this._currentDocument.model.views.code.editor.focus();
37 this.applySettings();
38 }
39 }
40 },
41
42 _codeEditor : {
43 value:null
44 },
45
46 codeEditor:{
47 get: function(){return this._codeEditor;},
48 set: function(value){this._codeEditor = value;}
49 },
50
51 codeCompletionSupport : {
52 value: {"js": true}
53 },
54
55 autocomplete: {
56 value: false
57 },
58
59 _automaticCodeComplete: {
60 value:false
61 },
62
63 automaticCodeComplete:{
64 get: function(){
65 return this._automaticCodeComplete;
66 },
67 set: function(value) {
68 if(this._automaticCodeComplete !== value) {
69 this._automaticCodeComplete = value;
70 }
71 }
72 },
73
74 _editorTheme: {
75 value:"default"
76 },
77
78 editorTheme:{
79 get: function(){
80 return this._editorTheme;
81 },
82 set: function(value){
83 this._editorTheme = value;
84 }
85 },
86
87 _zoomFactor: {
88 value:100
89 },
90
91 zoomFactor:{
92 get: function() {
93 return this._zoomFactor;
94 },
95 set: function(value) {
96 this.handleZoom(value);
97 }
98 },
99
100 deserializedFromTemplate: {
101 value: function() {
102 //TODO:add logic to check some configuration file to load the right code editor
103 this.codeEditor = CodeMirror;
104 }
105 },
106
107 /**
108 * Public method
109 * Creates an editor instance
110 */
111 createEditor : {
112 value:function(codeDocumentView, type, documentType, textDocument){
113 var self = this, editorOptions = null;
114
115 editorOptions = {
116 lineNumbers: true,
117 matchBrackets:true,
118 mode: type,
119 onChange: function(){
120 var historySize = codeDocumentView.editor.historySize();
121 if(historySize.undo>0){
122 textDocument.model.needsSave = true;
123 }else if(historySize.undo===0 && historySize.redo>0){
124 textDocument.model.needsSave = false;
125 }
126 },
127 onCursorActivity: function() {
128 codeDocumentView.editor.matchHighlight("CodeMirror-matchhighlight");
129 codeDocumentView.editor.setLineClass(codeDocumentView.editor.hline, null, null);
130 codeDocumentView.editor.hline = codeDocumentView.editor.setLineClass(codeDocumentView.editor.getCursor().line, null, "activeline");
131 }
132 };
133
134 //configure auto code completion if it is supported for that document type
135
136 this.autocomplete = this.codeCompletionSupport[documentType];
137
138 if(this.autocomplete) {
139
140 editorOptions.onKeyEvent = function(cm, keyEvent){
141 self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)
142 };
143
144 }
145
146 return self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions);
147 }
148 },
149
150 /**
151 * Private method
152 * key event handler for showing code completion dropdown
153 */
154 _codeCompletionKeyEventHandler:{
155 enumerable:false,
156 value: function(cm, keyEvent, documentType) {
157 //comment shortkeys
158 if((keyEvent.metaKey || keyEvent.ctrlKey) && !keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+/
159 this.commentSelection(true);
160 return;
161 }
162 //uncomment shortkeys
163 if((keyEvent.metaKey || keyEvent.ctrlKey) && keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+shift+/
164 this.commentSelection(false);
165 return;
166 }
167
168 //===manually triggered code completion
169 if((this.automaticCodeComplete === false)){
170 if(keyEvent.ctrlKey && keyEvent.keyCode === 32){//Ctrl+Space
171 this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint);
172 }
173 }
174 //===automatic auto complete [performance is slower]
175 else if(this._showAutoComplete(documentType, keyEvent)){
176 this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint);
177 }
178 }
179 },
180
181 /**
182 * Private method
183 * checks for valid keyset to show code completion dropdown
184 */
185 _showAutoComplete : {
186 enumerable:false,
187 value:function(documentType, keyEvent){
188 var status=false;
189
190 if((keyEvent.metaKey || keyEvent.ctrlKey) && (keyEvent.keyCode === 83)){//ctrl+s
191 return false;
192 }
193
194 switch(documentType){
195 case "js":
196 if((keyEvent.type === "keyup")//need seperate keycode set per mode
197 && ((keyEvent.keyCode > 47 && keyEvent.keyCode < 57)//numbers
198 || (keyEvent.keyCode > 64 && keyEvent.keyCode <91)//letters
199 || (keyEvent.keyCode === 190)//period
200 || (keyEvent.keyCode === 189)//underscore, dash
201 )
202 && !(keyEvent.ctrlKey //ctrl
203 || keyEvent.metaKey//cmd
204 || (keyEvent.keyCode === 219)//open bracket [
205 || (keyEvent.keyCode === 221)//close bracket ]
206 || (keyEvent.shiftKey && keyEvent.keyCode === 219)//open bracket {
207 || (keyEvent.shiftKey && keyEvent.keyCode === 221)//close bracket }
208 || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket (
209 || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket )
210 )
211 ){
212 status = true;
213 break;
214 }
215 default :
216 status = false;
217 }
218
219 return status;
220 }
221 },
222
223 getSelectedRange:{
224 value:function(editor){
225 return { from: editor.getCursor(true), to: editor.getCursor(false) };
226 }
227 },
228
229 commentSelection:{
230 value: function(isComment){
231 var range = this.ge