diff options
Diffstat (limited to 'js/mediators/keyboard-mediator.js')
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 220 |
1 files changed, 122 insertions, 98 deletions
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index a1fdead3..0282060f 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js | |||
@@ -85,22 +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") { | ||
89 | // Don't do anything if an input or other control is focused | ||
90 | return; | ||
91 | } | ||
92 | 88 | ||
93 | // Disable defaults for the Arrow Keys | 89 | //keyboard controls for html design view |
94 | 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")){ |
95 | evt.preventDefault(); | 91 | |
96 | } | 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); | ||
97 | 196 | ||
98 | // Check DELETE OR BACKSPACE | ||
99 | if((evt.keyCode == Keyboard.BACKSPACE) || (evt.keyCode == Keyboard.DELETE)) { | ||
100 | evt.stopImmediatePropagation(); | ||
101 | evt.preventDefault(); | ||
102 | NJevent("deleting"); | ||
103 | return; | ||
104 | } | 197 | } |
105 | 198 | ||
106 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) | 199 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) |
@@ -110,6 +203,13 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
110 | return; | 203 | return; |
111 | } | 204 | } |
112 | 205 | ||
206 | // Check if cmd+s/ctrl+s for Save (Windows/Mac) | ||
207 | if ((evt.keyCode == Keyboard.S) && (evt.ctrlKey || evt.metaKey) && !evt.shiftKey) { | ||
208 | NJevent("executeSave"); | ||
209 | evt.preventDefault(); | ||
210 | return; | ||
211 | } | ||
212 | |||
113 | // Check if cmd+shift+z for Redo (Mac) | 213 | // Check if cmd+shift+z for Redo (Mac) |
114 | if ((evt.keyCode == Keyboard.Z) && evt.metaKey && evt.shiftKey) { | 214 | if ((evt.keyCode == Keyboard.Z) && evt.metaKey && evt.shiftKey) { |
115 | NJevent("executeRedo"); | 215 | NJevent("executeRedo"); |
@@ -124,97 +224,21 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
124 | return; | 224 | return; |
125 | } | 225 | } |
126 | 226 | ||
127 | // Shortcut for Selection Tool is V | ||
128 | if(evt.keyCode === Keyboard.V) { | ||
129 | evt.preventDefault(); | ||
130 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | // Shortcut for Tag Tool is D | ||
135 | if(evt.keyCode === Keyboard.D){ | ||
136 | evt.preventDefault(); | ||
137 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | // Shortcut for Rotate Tool is W | ||
142 | if(evt.keyCode === Keyboard.W){ | ||
143 | evt.preventDefault(); | ||
144 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); | ||
145 | return; | ||
146 | } | ||
147 | |||
148 | // Shortcut for Translate Tool is G | ||
149 | if(evt.keyCode === Keyboard.G){ | ||
150 | evt.preventDefault(); | ||
151 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[3]}); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | // Shortcut for Rectangle Tool is R | ||
156 | // unless the user is pressing the command key. | ||
157 | // If the user is pressing the command key, they want to refresh the browser. | ||
158 | if((evt.keyCode === Keyboard.R) && !evt.metaKey) { | ||
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[1]}); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | // Shortcut for Oval Tool is O | ||
166 | if(evt.keyCode === Keyboard.O) { | ||
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[0]}); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | // Shortcut for Line Tool is L | ||
174 | if(evt.keyCode === Keyboard.L ) { | ||
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[2]}); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | if(evt.keyCode === Keyboard.H ) { | ||
182 | evt.preventDefault(); | ||
183 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); | ||
184 | return; | ||
185 | } | ||
186 | |||
187 | if(evt.keyCode === Keyboard.Z ) { | ||
188 | evt.preventDefault(); | ||
189 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[16]}); | ||
190 | return; | ||
191 | } | ||
192 | |||
193 | // Check if cmd+a/ctrl+a for Select All | ||
194 | if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { | ||
195 | NJevent("selectAll"); | ||
196 | return; | ||
197 | } | ||
198 |