diff options
author | Jose Antonio Marquez | 2012-06-27 15:32:38 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-27 15:32:38 -0700 |
commit | 60554730ac89bb874f811ba312c491d5caacf8ce (patch) | |
tree | 3b78bab74798812a38c05bfba0f88c407f98031f /js/controllers/code-editor-controller.js | |
parent | f704705fd85c1af44ad86f8c29e8e93d330796e5 (diff) | |
parent | 07e7e2f28b863b0a4d139cc7e649a630b162e0da (diff) | |
download | ninja-60554730ac89bb874f811ba312c491d5caacf8ce.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Color
Diffstat (limited to 'js/controllers/code-editor-controller.js')
-rw-r--r-- | js/controllers/code-editor-controller.js | 259 |
1 files changed, 0 insertions, 259 deletions
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js deleted file mode 100644 index f3c19b92..00000000 --- a/js/controllers/code-editor-controller.js +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component; | ||
11 | |||
12 | exports.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 | if(this.autocomplete) { | ||
136 | |||
137 | editorOptions.onKeyEvent = function(cm, keyEvent){ | ||
138 | self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType) | ||
139 | }; | ||
140 | |||
141 | } | ||
142 | |||
143 | return self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); | ||
144 | } | ||
145 | }, | ||
146 | |||
147 | /** | ||
148 | * Private method | ||
149 | * key event handler for showing code completion dropdown | ||
150 | */ | ||
151 | _codeCompletionKeyEventHandler:{ | ||
152 | enumerable:false, | ||
153 | value: function(cm, keyEvent, documentType) { | ||
154 | //comment shortkeys | ||
155 | if((keyEvent.metaKey || keyEvent.ctrlKey) && !keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+/ | ||
156 | this.commentSelection(true); | ||
157 | return; | ||
158 | } | ||
159 | //uncomment shortkeys | ||
160 | if((keyEvent.metaKey || keyEvent.ctrlKey) && keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+shift+/ | ||
161 | this.commentSelection(false); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | //===manually triggered code completion | ||
166 | if((this.automaticCodeComplete === false)){ | ||
167 | if(keyEvent.ctrlKey && keyEvent.keyCode === 32){//Ctrl+Space | ||
168 | this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); | ||
169 | } | ||
170 | } | ||
171 | //===automatic auto complete [performance is slower] | ||
172 | else if(this._showAutoComplete(documentType, keyEvent)){ | ||
173 | this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); | ||
174 | } | ||
175 | } | ||
176 | }, | ||
177 | |||
178 | /** | ||
179 | * Private method | ||
180 | * checks for valid keyset to show code completion dropdown | ||
181 | */ | ||
182 | _showAutoComplete : { | ||
183 | enumerable:false, | ||
184 | value:function(documentType, keyEvent){ | ||
185 | var status=false; | ||
186 | |||
187 | if((keyEvent.metaKey || keyEvent.ctrlKey) && (keyEvent.keyCode === 83)){//ctrl+s | ||
188 | return false; | ||
189 | } | ||
190 | |||
191 | switch(documentType){ | ||
192 | case "js": | ||
193 | if((keyEvent.type === "keyup")//need seperate keycode set per mode | ||
194 | && ((keyEvent.keyCode > 47 && keyEvent.keyCode < 57)//numbers | ||
195 | || (keyEvent.keyCode > 64 && keyEvent.keyCode <91)//letters | ||
196 | || (keyEvent.keyCode === 190)//period | ||
197 | || (keyEvent.keyCode === 189)//underscore, dash | ||
198 | ) | ||
199 | && !(keyEvent.ctrlKey //ctrl | ||
200 | || keyEvent.metaKey//cmd | ||
201 | || (keyEvent.keyCode === 219)//open bracket [ | ||
202 | || (keyEvent.keyCode === 221)//close bracket ] | ||
203 | || (keyEvent.shiftKey && keyEvent.keyCode === 219)//open bracket { | ||
204 | || (keyEvent.shiftKey && keyEvent.keyCode === 221)//close bracket } | ||
205 | || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket ( | ||
206 | || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket ) | ||
207 | ) | ||
208 | ){ | ||
209 | status = true; | ||
210 | break; | ||
211 | } | ||
212 | default : | ||
213 | status = false; | ||
214 | } | ||
215 | |||
216 | return status; | ||
217 | } | ||
218 | }, | ||
219 | |||
220 | getSelectedRange:{ | ||
221 | value:function(editor){ | ||
222 | return { from: editor.getCursor(true), to: editor.getCursor(false) }; | ||
223 | } | ||