diff options
Diffstat (limited to 'js/mediators/keyboard-mediator.js')
-rwxr-xr-x[-rw-r--r--] | js/mediators/keyboard-mediator.js | 222 |
1 files changed, 124 insertions, 98 deletions
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index a1fdead3..5b044f8a 100644..100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js | |||
@@ -85,22 +85,117 @@ 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 | // Hand tool | ||
166 | if(evt.keyCode === Keyboard.H ) { | ||
167 | evt.preventDefault(); | ||
168 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[14]}); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | // Zoom tool | ||
173 | if(evt.keyCode === Keyboard.Z ) { | ||
174 | evt.preventDefault(); | ||
175 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | // Check if cmd+a/ctrl+a for Select All | ||
180 | if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { | ||
181 | NJevent("selectAll"); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | if(evt.keyCode === Keyboard.ESCAPE){//ESC key | ||
186 | //console.log("ESC key pressed"); | ||
187 | if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleEscape(evt); | ||
188 | //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); | ||
189 | } | ||
190 | |||
191 | |||
192 | if((evt.keyCode == Keyboard.ENTER) && (evt.ctrlKey || evt.metaKey)) { | ||
193 | this.application.ninja.executeChromePreview(); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyPress(evt); | ||
97 | 198 | ||
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 | } | 199 | } |
105 | 200 | ||
106 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) | 201 | // Check if cmd+z/ctrl+z for Undo (Windows/Mac) |
@@ -110,6 +205,13 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
110 | return; | 205 | return; |
111 | } | 206 | } |
112 | 207 | ||
208 | // Check if cmd+s/ctrl+s for Save (Windows/Mac) | ||
209 | if ((evt.keyCode == Keyboard.S) && (evt.ctrlKey || evt.metaKey) && !evt.shiftKey) { | ||
210 | NJevent("executeSave"); | ||
211 | evt.preventDefault(); | ||
212 | return; | ||
213 | } | ||
214 | |||
113 | // Check if cmd+shift+z for Redo (Mac) | 215 | // Check if cmd+shift+z for Redo (Mac) |
114 | if ((evt.keyCode == Keyboard.Z) && evt.metaKey && evt.shiftKey) { | 216 | if ((evt.keyCode == Keyboard.Z) && evt.metaKey && evt.shiftKey) { |
115 | NJevent("executeRedo"); | 217 | NJevent("executeRedo"); |
@@ -124,97 +226,21 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
124 | return; | 226 | return; |
125 | } | 227 | } |
126 | 228 | ||
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"); | ||