diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/components/layout/document-bar.reel/document-bar.js | 2 | ||||
-rw-r--r-- | js/controllers/code-editor-controller.js | 79 | ||||
-rwxr-xr-x | js/ninja.reel/ninja.html | 6 | ||||
-rwxr-xr-x | js/stage/stage-view.reel/stage-view.css | 24 | ||||
-rwxr-xr-x | js/stage/stage-view.reel/stage-view.js | 156 |
5 files changed, 122 insertions, 145 deletions
diff --git a/js/components/layout/document-bar.reel/document-bar.js b/js/components/layout/document-bar.reel/document-bar.js index 4dc39fd6..27402dff 100755 --- a/js/components/layout/document-bar.reel/document-bar.js +++ b/js/components/layout/document-bar.reel/document-bar.js | |||
@@ -100,7 +100,7 @@ exports.DocumentBar = Montage.create(Component, { | |||
100 | if(event._event.target.id === this.currentView) return; | 100 | if(event._event.target.id === this.currentView) return; |
101 | 101 | ||
102 | this.currentView = event._event.target.id; | 102 | this.currentView = event._event.target.id; |
103 | this.application.ninja.documentController.stage.stageView.switchViews(event._event.target.id);//switch between design view | 103 | this.application.ninja.documentController.stage.stageView.switchDesignDocViews(event._event.target.id);//switch between design view |
104 | } | 104 | } |
105 | }, | 105 | }, |
106 | 106 | ||
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 | ||
diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html index ead7f576..5862cf61 100755 --- a/js/ninja.reel/ninja.html +++ b/js/ninja.reel/ninja.html | |||
@@ -348,6 +348,11 @@ | |||
348 | } | 348 | } |
349 | }, | 349 | }, |
350 | 350 | ||
351 | "codeEditorController": { | ||
352 | "module": "js/controllers/code-editor-controller", | ||
353 | "name": "CodeEditorController" | ||
354 | }, | ||
355 | |||
351 | "owner": { | 356 | "owner": { |
352 | "module": "js/ninja.reel", | 357 | "module": "js/ninja.reel", |
353 | "name": "Ninja", | 358 | "name": "Ninja", |
@@ -377,6 +382,7 @@ | |||
377 | "ioMediator": {"@": "ioMediator"}, | 382 | "ioMediator": {"@": "ioMediator"}, |
378 | "timeline": {"@": "timeline"}, | 383 | "timeline": {"@": "timeline"}, |
379 | "mainMenuController": {"@": "mainMenuController"}, | 384 | "mainMenuController": {"@": "mainMenuController"}, |
385 | "codeEditorController": {"@": "codeEditorController"}, | ||
380 | "rightPanelContainer": {"#": "rightPanelContainer" }, | 386 | "rightPanelContainer": {"#": "rightPanelContainer" }, |
381 | "panelSplitter": {"@": "splitter3"}, | 387 | "panelSplitter": {"@": "splitter3"}, |
382 | "timelineSplitter": {"@": "splitter4"} | 388 | "timelineSplitter": {"@": "splitter4"} |
diff --git a/js/stage/stage-view.reel/stage-view.css b/js/stage/stage-view.reel/stage-view.css index ce7072c7..372af144 100755 --- a/js/stage/stage-view.reel/stage-view.css +++ b/js/stage/stage-view.reel/stage-view.css | |||
@@ -23,15 +23,17 @@ | |||
23 | } | 23 | } |
24 | */ | 24 | */ |
25 | 25 | ||
26 | .CodeMirror { | 26 | /*.CodeMirror {*/ |
27 | width: 100%; | 27 | /*width: 100%;*/ |
28 | height: 100%; | 28 | /*height: 100%;*/ |
29 | background: white; | 29 | /*background: white;*/ |
30 | } | 30 | /*}*/ |
31 | |||
32 | /*.CodeMirror .CodeMirror-scroll {*/ | ||
33 | /*height: 100%;*/ | ||
34 | /*overflow: scroll;*/ | ||
35 | /*overflow-x: auto;*/ | ||
36 | /*overflow-y: auto;*/ | ||
37 | /*}*/ | ||
38 | |||
31 | 39 | ||
32 | .CodeMirror .CodeMirror-scroll { | ||
33 | height: 100%; | ||
34 | overflow: scroll; | ||
35 | overflow-x: auto; | ||
36 | overflow-y: auto; | ||
37 | } | ||
diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index 917cbeb5..bfbee2b6 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js | |||
@@ -52,12 +52,11 @@ exports.StageView = Montage.create(Component, { | |||
52 | }, | 52 | }, |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Creates a text area which will contain the content of the opened text document. | 55 | * Public method |
56 | * Creates a textarea element which will contain the content of the opened text document. | ||
56 | */ | 57 | */ |
57 | createTextAreaElement: { | 58 | createTextAreaElement: { |
58 | value: function(uuid) { | 59 | value: function(uuid) { |
59 | |||
60 | |||
61 | var codeMirrorDiv = document.createElement("div"); | 60 | var codeMirrorDiv = document.createElement("div"); |
62 | codeMirrorDiv.id = "codeMirror_" + uuid; | 61 | codeMirrorDiv.id = "codeMirror_" + uuid; |
63 | codeMirrorDiv.style.display = "block"; | 62 | codeMirrorDiv.style.display = "block"; |
@@ -66,19 +65,22 @@ exports.StageView = Montage.create(Component, { | |||
66 | var textArea = document.createElement("textarea"); | 65 | var textArea = document.createElement("textarea"); |
67 | textArea.id = "code"; | 66 | textArea.id = "code"; |
68 | textArea.name = "code"; | 67 | textArea.name = "code"; |
69 | |||
70 | codeMirrorDiv.appendChild(textArea); | 68 | codeMirrorDiv.appendChild(textArea); |
71 | 69 | ||
72 | return textArea; | 70 | return textArea; |
73 | } | 71 | } |
74 | }, | 72 | }, |
75 | 73 | ||
76 | // Temporary function to create a Codemirror text view | 74 | /** |
75 | * Public method | ||
76 | * Creates a new instance of a code editor | ||
77 | */ | ||
77 | createTextView: { | 78 | createTextView: { |
78 | value: function(doc) { | 79 | value: function(doc) { |
80 | var type; | ||
79 | this.application.ninja.documentController._hideCurrentDocument(); | 81 | this.application.ninja.documentController._hideCurrentDocument(); |
80 | this.hideOtherDocuments(doc.uuid); | 82 | this.hideOtherDocuments(doc.uuid); |
81 | var type; | 83 | |
82 | switch(doc.documentType) { | 84 | switch(doc.documentType) { |
83 | case "css" : | 85 | case "css" : |
84 | type = "css"; | 86 | type = "css"; |
@@ -87,66 +89,25 @@ exports.StageView = Montage.create(Component, { | |||
87 | type = "javascript"; | 89 | type = "javascript"; |
88 | break; | 90 | break; |
89 | } | 91 | } |
90 | |||
91 | //fix hack | ||
92 | document.getElementById("codeMirror_"+doc.uuid).style.display="block"; | 92 | document.getElementById("codeMirror_"+doc.uuid).style.display="block"; |
93 | 93 | ||
94 | var documentController = this.application.ninja.documentController; | 94 | doc.editor = this.application.ninja.codeEditorController.createEditor(doc, type); |
95 | doc.editor = CodeMirror.fromTextArea(doc.textArea, { | ||
96 | lineNumbers: true, | ||
97 | lineWrapping: true, | ||
98 | matchBrackets:true, | ||
99 | mode: type, | ||
100 | onChange: function(){ | ||