diff options
author | Ananya Sen | 2012-02-20 12:04:57 -0800 |
---|---|---|
committer | Ananya Sen | 2012-02-20 12:04:57 -0800 |
commit | 50e555587d3a97dbfc75c33f3589cfccee392180 (patch) | |
tree | 5b7c9329c13e457b5aa4f10c24b105e5cb75816a /js/mediators | |
parent | 8fdce771bfcf662cf1acc16d45e4361ffd06c53e (diff) | |
download | ninja-50e555587d3a97dbfc75c33f3589cfccee392180.tar.gz |
- moved tools specific keyboard controls for desing view only
- stopped snapping when all documents are closed
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 220 |
1 files changed, 115 insertions, 105 deletions
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 40b26582..0282060f 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js | |||
@@ -85,23 +85,115 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
85 | 85 | ||
86 | handleKeydown: { | 86 | handleKeydown: { |
87 | value: function(evt) { | 87 | value: function(evt) { |
88 | if((document.activeElement.nodeName !== "BODY") && (!!this.application.ninja.documentController.activeDocument) | ||
89 | && (this.application.ninja.documentController.activeDocument.currentView === "design")) { | ||
90 | // Don't do anything if an input or other control is focused | ||
91 | return; | ||
92 | } | ||
93 | 88 | ||
94 | // Disable defaults for the Arrow Keys | 89 | //keyboard controls for html design view |
95 | if((evt.keyCode == Keyboard.LEFT) || (evt.keyCode == Keyboard.RIGHT) || (evt.keyCode == Keyboard.UP) || (evt.keyCode == Keyboard.DOWN)) { | 90 | if((!!this.application.ninja.documentController.activeDocument) && (this.application.ninja.documentController.activeDocument.currentView === "design")){ |
96 | evt.preventDefault(); | 91 | |
97 | } | 92 | // Don't do anything if an input or other control is focused |
93 | if(document.activeElement.nodeName !== "BODY") { | ||
94 | return; | ||
95 | } | ||
96 | |||
97 | // Disable defaults for the Arrow Keys | ||
98 | if((evt.keyCode == Keyboard.LEFT) || (evt.keyCode == Keyboard.RIGHT) || (evt.keyCode == Keyboard.UP) || (evt.keyCode == Keyboard.DOWN)) { | ||
99 | evt.preventDefault(); | ||
100 | } | ||
101 | |||
102 | // Check DELETE OR BACKSPACE | ||
103 | if((evt.keyCode == Keyboard.BACKSPACE) || (evt.keyCode == Keyboard.DELETE)) { | ||
104 | evt.stopImmediatePropagation(); | ||
105 | evt.preventDefault(); | ||
106 | NJevent("deleting"); | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | |||
111 | // Shortcut for Selection Tool is V | ||
112 | if(evt.keyCode === Keyboard.V) { | ||
113 | evt.preventDefault(); | ||
114 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | // Shortcut for Tag Tool is D | ||
119 | if(evt.keyCode === Keyboard.D){ | ||
120 | evt.preventDefault(); | ||
121 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | // Shortcut for Rotate Tool is W | ||
126 | if(evt.keyCode === Keyboard.W){ | ||
127 | evt.preventDefault(); | ||
128 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | // Shortcut for Translate Tool is G | ||
133 | if(evt.keyCode === Keyboard.G){ | ||
134 | evt.preventDefault(); | ||
135 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[3]}); | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | // Shortcut for Rectangle Tool is R | ||
140 | // unless the user is pressing the command key. | ||
141 | // If the user is pressing the command key, they want to refresh the browser. | ||
142 | if((evt.keyCode === Keyboard.R) && !evt.metaKey) { | ||
143 | evt.preventDefault(); | ||
144 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
145 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[1]}); | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | // Shortcut for Oval Tool is O | ||
150 | if(evt.keyCode === Keyboard.O) { | ||
151 | evt.preventDefault(); | ||
152 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
153 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[0]}); | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | // Shortcut for Line Tool is L | ||
158 | if(evt.keyCode === Keyboard.L ) { | ||
159 | evt.preventDefault(); | ||
160 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
161 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[2]}); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | if(evt.keyCode === Keyboard.H ) { | ||
166 | evt.preventDefault(); | ||
167 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | if(evt.keyCode === Keyboard.Z ) { | ||
172 | evt.preventDefault(); | ||
173 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[16]}); | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | // Check if cmd+a/ctrl+a for Select All | ||
178 | if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { | ||
179 | NJevent("selectAll"); | ||
180 | return; | ||
181 | } | ||
182 | |||
183 | if(evt.keyCode === Keyboard.ESCAPE){//ESC key | ||
184 | //console.log("ESC key pressed"); | ||
185 | if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleEscape(evt); | ||
186 | //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); | ||
187 | } | ||
188 | |||
189 | |||
190 | if((evt.keyCode == Keyboard.ENTER) && (evt.ctrlKey || evt.metaKey)) { | ||
191 | this.application.ninja.executeChromePreview(); | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyPress(evt); | ||
98 | 196 | ||
99 | // Check DELETE OR BACKSPACE | ||
100 | if((evt.keyCode == Keyboard.BACKSPACE) || (evt.keyCode == Keyboard.DELETE)) { | ||
101 | evt.stopImmediatePropagation(); | ||
102 | evt.preventDefault(); | ||
103 | NJevent("deleting"); | ||
104 | return; | ||
105 | } | 197 | } |
106 | 198 | ||
107 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) | 199 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) |
@@ -132,103 +224,21 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
132 | return; | 224 | return; |
133 | } | 225 | } |
134 | 226 | ||
135 | // Shortcut for Selection Tool is V | ||
136 | if(evt.keyCode === Keyboard.V) { | ||
137 | evt.preventDefault(); | ||
138 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); | ||
139 | return; | ||
140 | } | ||
141 | |||
142 | // Shortcut for Tag Tool is D | ||
143 | if(evt.keyCode === Keyboard.D){ | ||
144 | evt.preventDefault(); | ||
145 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | // Shortcut for Rotate Tool is W | ||
150 | if(evt.keyCode === Keyboard.W){ | ||
151 | evt.preventDefault(); | ||
152 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); | ||
153 | return; | ||
154 | } | ||
155 | |||
156 | // Shortcut for Translate Tool is G | ||
157 | if(evt.keyCode === Keyboard.G){ | ||
158 | evt.preventDefault(); | ||
159 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[3]}); | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | // Shortcut for Rectangle Tool is R | ||
164 | // unless the user is pressing the command key. | ||
165 | // If the user is pressing the command key, they want to refresh the browser. | ||
166 | if((evt.keyCode === Keyboard.R) && !evt.metaKey) { | ||
167 | evt.preventDefault(); | ||
168 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
169 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[1]}); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | // Shortcut for Oval Tool is O | ||
174 | if(evt.keyCode === Keyboard.O) { | ||
175 | evt.preventDefault(); | ||
176 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
177 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[0]}); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | // Shortcut for Line Tool is L | ||
182 | if(evt.keyCode === Keyboard.L ) { | ||
183 | evt.preventDefault(); | ||
184 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); | ||
185 | this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[2]}); | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | if(evt.keyCode === Keyboard.H ) { | ||
190 | evt.preventDefault(); | ||
191 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | if(evt.keyCode === Keyboard.Z ) { | ||
196 | evt.preventDefault(); | ||
197 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[16]}); | ||
198 | return; | ||
199 | } | ||
200 | |||
201 | // Check if cmd+a/ctrl+a for Select All | ||
202 | if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { | ||
203 | NJevent("selectAll"); | ||
204 | return; | ||
205 | } | ||
206 | |||
207 | if(evt.keyCode === Keyboard.ESCAPE){//ESC key | ||
208 | //console.log("ESC key pressed"); | ||
209 | if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleEscape(evt); | ||
210 | //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); | ||
211 | } | ||
212 | |||
213 | // Check if cmd+a/ctrl+a for Select All | ||
214 | if((evt.keyCode == Keyboard.ENTER) && (evt.ctrlKey || evt.metaKey)) { | ||