diff options
author | Ananya Sen | 2012-04-09 13:11:40 -0700 |
---|---|---|
committer | Ananya Sen | 2012-04-09 13:11:40 -0700 |
commit | dece82791f43b5e8d278aba89cf8d6119af1478f (patch) | |
tree | bc15d90a380527071d77a2c8a5598a2e245b486c /js/controllers | |
parent | 22ade57a30b45774882028eef4ab5a5bffe1a624 (diff) | |
download | ninja-dece82791f43b5e8d278aba89cf8d6119af1478f.tar.gz |
- Decouple code editor from stage document switching logic
- cleaning up
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/code-editor-controller.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js new file mode 100644 index 00000000..23bd9279 --- /dev/null +++ b/js/controllers/code-editor-controller.js | |||
@@ -0,0 +1,79 @@ | |||
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 | var CodeEditorController = exports.CodeEditorController = Montage.create(Component, { | ||
13 | hasTemplate: { | ||
14 | value: false | ||
15 | }, | ||
16 | |||
17 | _codeEditor : { | ||
18 | value:null | ||
19 | }, | ||
20 | |||
21 | codeEditor:{ | ||
22 | get: function(){return this._codeEditor;}, | ||
23 | set: function(value){this._codeEditor = value;} | ||
24 | }, | ||
25 | |||
26 | deserializedFromTemplate: { | ||
27 | value: function() { | ||
28 | //TODO:add logic to check some configuration file to load the right code editor | ||
29 | this.codeEditor = CodeMirror; | ||
30 | } | ||
31 | }, | ||
32 | |||
33 | createEditor : { | ||
34 | value:function(doc, type){ | ||
35 | var self = this; | ||
36 | var editor = self.codeEditor.fromTextArea(doc.textArea, { | ||
37 | lineNumbers: true, | ||
38 | matchBrackets:true, | ||
39 | mode: type, | ||
40 | onChange: function(){ | ||
41 | var historySize = doc.editor.historySize(); | ||
42 | if(historySize.undo>0){ | ||
43 | doc.needsSave = true; | ||
44 | }else if(historySize.undo===0 && historySize.redo>0){ | ||
45 | doc.needsSave = false; | ||
46 | } | ||
47 | }, | ||
48 | onCursorActivity: function() { | ||
49 | doc.editor.matchHighlight("CodeMirror-matchhighlight"); | ||
50 | doc.editor.setLineClass(doc.editor.hline, null, null); | ||
51 | doc.editor.hline = doc.editor.setLineClass(doc.editor.getCursor().line, null, "activeline"); | ||
52 | }, | ||
53 | //extraKeys: {"Ctrl-Space": function(cm) {CodeMirror.simpleHint(cm, CodeMirror.javascriptHint);}} | ||
54 | onKeyEvent: function(cm, keyEvent) { | ||
55 | if((keyEvent.type === "keyup")//need seperate keycode set per mode | ||
56 | && ((keyEvent.keyCode > 47 && keyEvent.keyCode < 57)//numbers | ||
57 | || (keyEvent.keyCode > 64 && keyEvent.keyCode <91)//letters | ||
58 | || (keyEvent.keyCode === 190)//period | ||
59 | || (keyEvent.keyCode === 189)//underscore, dash | ||
60 | ) | ||
61 | && !( (keyEvent.keyCode === 219)//open bracket [ | ||
62 | || (keyEvent.keyCode === 221)//close bracket ] | ||
63 | || (keyEvent.shiftKey && keyEvent.keyCode === 219)//open bracket { | ||
64 | || (keyEvent.shiftKey && keyEvent.keyCode === 221)//close bracket } | ||
65 | || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket ( | ||
66 | || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket ) | ||
67 | ) | ||
68 | ){ | ||
69 | |||
70 | self.codeEditor.simpleHint(cm, self.codeEditor.javascriptHint); | ||
71 | } | ||
72 | } | ||
73 | }); | ||
74 | |||
75 | return editor; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | }); \ No newline at end of file | ||