1 |
|
---|
2 | namespace Netron.Diagramming.Core {
|
---|
3 | /// <summary>
|
---|
4 | /// This class implementing the <see cref="IKeyboardListener"/> collects all the hotkeys.
|
---|
5 | /// </summary>
|
---|
6 | class HotKeys : IKeyboardListener {
|
---|
7 | // ------------------------------------------------------------------
|
---|
8 | /// <summary>
|
---|
9 | /// Specifies if the Control key is pressed. This is set in the
|
---|
10 | /// KeyPress and KeyUp methods.
|
---|
11 | /// </summary>
|
---|
12 | // ------------------------------------------------------------------
|
---|
13 | bool controlIsPressed = false;
|
---|
14 |
|
---|
15 | private IController mController;
|
---|
16 |
|
---|
17 | public IController Controller {
|
---|
18 | get { return mController; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public HotKeys(IController controller) {
|
---|
22 | mController = controller;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void KeyUp(System.Windows.Forms.KeyEventArgs e) {
|
---|
26 | switch (e.KeyCode) {
|
---|
27 | case System.Windows.Forms.Keys.A:
|
---|
28 | if (controlIsPressed) {
|
---|
29 | this.Controller.SelectAll();
|
---|
30 | }
|
---|
31 | break;
|
---|
32 | case System.Windows.Forms.Keys.Add:
|
---|
33 | break;
|
---|
34 | case System.Windows.Forms.Keys.Alt:
|
---|
35 | break;
|
---|
36 |
|
---|
37 | case System.Windows.Forms.Keys.Attn:
|
---|
38 | break;
|
---|
39 | case System.Windows.Forms.Keys.B:
|
---|
40 | break;
|
---|
41 | case System.Windows.Forms.Keys.Back:
|
---|
42 | break;
|
---|
43 | case System.Windows.Forms.Keys.BrowserBack:
|
---|
44 | break;
|
---|
45 | case System.Windows.Forms.Keys.BrowserFavorites:
|
---|
46 | break;
|
---|
47 | case System.Windows.Forms.Keys.BrowserForward:
|
---|
48 | break;
|
---|
49 | case System.Windows.Forms.Keys.BrowserHome:
|
---|
50 | break;
|
---|
51 | case System.Windows.Forms.Keys.BrowserRefresh:
|
---|
52 | break;
|
---|
53 | case System.Windows.Forms.Keys.BrowserSearch:
|
---|
54 | break;
|
---|
55 | case System.Windows.Forms.Keys.BrowserStop:
|
---|
56 | break;
|
---|
57 | case System.Windows.Forms.Keys.C:
|
---|
58 | if (controlIsPressed) {
|
---|
59 | this.Controller.ActivateTool(
|
---|
60 | ControllerBase.CopyToolName);
|
---|
61 | }
|
---|
62 | break;
|
---|
63 | case System.Windows.Forms.Keys.Cancel:
|
---|
64 | break;
|
---|
65 | case System.Windows.Forms.Keys.Capital:
|
---|
66 | break;
|
---|
67 |
|
---|
68 | case System.Windows.Forms.Keys.Clear:
|
---|
69 | break;
|
---|
70 | case System.Windows.Forms.Keys.Control:
|
---|
71 | break;
|
---|
72 | case System.Windows.Forms.Keys.ControlKey:
|
---|
73 | break;
|
---|
74 | case System.Windows.Forms.Keys.Crsel:
|
---|
75 | break;
|
---|
76 | case System.Windows.Forms.Keys.D:
|
---|
77 | break;
|
---|
78 | case System.Windows.Forms.Keys.D0:
|
---|
79 | break;
|
---|
80 | case System.Windows.Forms.Keys.D1:
|
---|
81 | break;
|
---|
82 | case System.Windows.Forms.Keys.D2:
|
---|
83 | break;
|
---|
84 | case System.Windows.Forms.Keys.D3:
|
---|
85 | break;
|
---|
86 | case System.Windows.Forms.Keys.D4:
|
---|
87 | break;
|
---|
88 | case System.Windows.Forms.Keys.D5:
|
---|
89 | break;
|
---|
90 | case System.Windows.Forms.Keys.D6:
|
---|
91 | break;
|
---|
92 | case System.Windows.Forms.Keys.D7:
|
---|
93 | break;
|
---|
94 | case System.Windows.Forms.Keys.D8:
|
---|
95 | break;
|
---|
96 | case System.Windows.Forms.Keys.D9:
|
---|
97 | break;
|
---|
98 | case System.Windows.Forms.Keys.Decimal:
|
---|
99 | break;
|
---|
100 | case System.Windows.Forms.Keys.Delete:
|
---|
101 | // The following code was moved to the DeleteTool.
|
---|
102 | //cmd = new DeleteCommand(
|
---|
103 | // this.mController,
|
---|
104 | // Selection.SelectedItems.Copy());
|
---|
105 | //this.Controller.UndoManager.AddUndoCommand(cmd);
|
---|
106 | //cmd.Redo();
|
---|
107 |
|
---|
108 | Controller.ActivateTool(ControllerBase.DeleteToolName);
|
---|
109 | break;
|
---|
110 | case System.Windows.Forms.Keys.Divide:
|
---|
111 | break;
|
---|
112 | case System.Windows.Forms.Keys.Down:
|
---|
113 | break;
|
---|
114 | case System.Windows.Forms.Keys.E:
|
---|
115 | break;
|
---|
116 | case System.Windows.Forms.Keys.End:
|
---|
117 | break;
|
---|
118 | case System.Windows.Forms.Keys.Enter:
|
---|
119 | break;
|
---|
120 | case System.Windows.Forms.Keys.EraseEof:
|
---|
121 | break;
|
---|
122 | case System.Windows.Forms.Keys.Escape:
|
---|
123 | break;
|
---|
124 | case System.Windows.Forms.Keys.Execute:
|
---|
125 | break;
|
---|
126 |
|
---|
127 | case System.Windows.Forms.Keys.F:
|
---|
128 | break;
|
---|
129 | case System.Windows.Forms.Keys.F1:
|
---|
130 | break;
|
---|
131 | case System.Windows.Forms.Keys.F10:
|
---|
132 | break;
|
---|
133 | case System.Windows.Forms.Keys.F11:
|
---|
134 | break;
|
---|
135 | case System.Windows.Forms.Keys.F12:
|
---|
136 | break;
|
---|
137 | case System.Windows.Forms.Keys.F13:
|
---|
138 | break;
|
---|
139 | case System.Windows.Forms.Keys.F14:
|
---|
140 | break;
|
---|
141 | case System.Windows.Forms.Keys.F15:
|
---|
142 | break;
|
---|
143 | case System.Windows.Forms.Keys.F16:
|
---|
144 | break;
|
---|
145 | case System.Windows.Forms.Keys.F17:
|
---|
146 | break;
|
---|
147 | case System.Windows.Forms.Keys.F18:
|
---|
148 | break;
|
---|
149 | case System.Windows.Forms.Keys.F19:
|
---|
150 | break;
|
---|
151 | case System.Windows.Forms.Keys.F2:
|
---|
152 | break;
|
---|
153 | case System.Windows.Forms.Keys.F20:
|
---|
154 | break;
|
---|
155 | case System.Windows.Forms.Keys.F21:
|
---|
156 | break;
|
---|
157 | case System.Windows.Forms.Keys.F22:
|
---|
158 | break;
|
---|
159 | case System.Windows.Forms.Keys.F23:
|
---|
160 | break;
|
---|
161 | case System.Windows.Forms.Keys.F24:
|
---|
162 | break;
|
---|
163 | case System.Windows.Forms.Keys.F3:
|
---|
164 | break;
|
---|
165 | case System.Windows.Forms.Keys.F4:
|
---|
166 | break;
|
---|
167 | case System.Windows.Forms.Keys.F5:
|
---|
168 | break;
|
---|
169 | case System.Windows.Forms.Keys.F6:
|
---|
170 | break;
|
---|
171 | case System.Windows.Forms.Keys.F7:
|
---|
172 | break;
|
---|
173 | case System.Windows.Forms.Keys.F8:
|
---|
174 | break;
|
---|
175 | case System.Windows.Forms.Keys.F9:
|
---|
176 | break;
|
---|
177 | case System.Windows.Forms.Keys.FinalMode:
|
---|
178 | break;
|
---|
179 | case System.Windows.Forms.Keys.G:
|
---|
180 | break;
|
---|
181 | case System.Windows.Forms.Keys.H:
|
---|
182 | break;
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 | case System.Windows.Forms.Keys.Help:
|
---|
187 | break;
|
---|
188 | case System.Windows.Forms.Keys.Home:
|
---|
189 | break;
|
---|
190 | case System.Windows.Forms.Keys.I:
|
---|
191 | break;
|
---|
192 |
|
---|
193 | case System.Windows.Forms.Keys.Insert:
|
---|
194 | break;
|
---|
195 | case System.Windows.Forms.Keys.J:
|
---|
196 | break;
|
---|
197 |
|
---|
198 | case System.Windows.Forms.Keys.K:
|
---|
199 | break;
|
---|
200 |
|
---|
201 | case System.Windows.Forms.Keys.KeyCode:
|
---|
202 | break;
|
---|
203 | case System.Windows.Forms.Keys.L:
|
---|
204 | break;
|
---|
205 | case System.Windows.Forms.Keys.LButton:
|
---|
206 | break;
|
---|
207 | case System.Windows.Forms.Keys.LControlKey:
|
---|
208 | break;
|
---|
209 | case System.Windows.Forms.Keys.LMenu:
|
---|
210 | break;
|
---|
211 | case System.Windows.Forms.Keys.LShiftKey:
|
---|
212 | break;
|
---|
213 | case System.Windows.Forms.Keys.LWin:
|
---|
214 | break;
|
---|
215 |
|
---|
216 | case System.Windows.Forms.Keys.Left:
|
---|
217 | break;
|
---|
218 | case System.Windows.Forms.Keys.LineFeed:
|
---|
219 | break;
|
---|
220 | case System.Windows.Forms.Keys.M:
|
---|
221 | break;
|
---|
222 | case System.Windows.Forms.Keys.MButton:
|
---|
223 | break;
|
---|
224 |
|
---|
225 | case System.Windows.Forms.Keys.Menu:
|
---|
226 | break;
|
---|
227 | case System.Windows.Forms.Keys.Modifiers:
|
---|
228 | break;
|
---|
229 | case System.Windows.Forms.Keys.Multiply:
|
---|
230 | break;
|
---|
231 | case System.Windows.Forms.Keys.N:
|
---|
232 | if (controlIsPressed)
|
---|
233 | this.Controller.ParentControl.NewDocument();
|
---|
234 | break;
|
---|
235 | case System.Windows.Forms.Keys.Next:
|
---|
236 | break;
|
---|
237 | case System.Windows.Forms.Keys.NoName:
|
---|
238 | break;
|
---|
239 | case System.Windows.Forms.Keys.None:
|
---|
240 | break;
|
---|
241 | case System.Windows.Forms.Keys.NumLock:
|
---|
242 | break;
|
---|
243 | case System.Windows.Forms.Keys.NumPad0:
|
---|
244 | break;
|
---|
245 | case System.Windows.Forms.Keys.NumPad1:
|
---|
246 |
|
---|
247 | break;
|
---|
248 | case System.Windows.Forms.Keys.NumPad2:
|
---|
249 | break;
|
---|
250 | case System.Windows.Forms.Keys.NumPad3:
|
---|
251 | break;
|
---|
252 | case System.Windows.Forms.Keys.NumPad4:
|
---|
253 | break;
|
---|
254 | case System.Windows.Forms.Keys.NumPad5:
|
---|
255 | break;
|
---|
256 | case System.Windows.Forms.Keys.NumPad6:
|
---|
257 | break;
|
---|
258 | case System.Windows.Forms.Keys.NumPad7:
|
---|
259 | break;
|
---|
260 | case System.Windows.Forms.Keys.NumPad8:
|
---|
261 | break;
|
---|
262 | case System.Windows.Forms.Keys.NumPad9:
|
---|
263 | break;
|
---|
264 | case System.Windows.Forms.Keys.O:
|
---|
265 | this.Controller.ParentControl.Open();
|
---|
266 | break;
|
---|
267 |
|
---|
268 |
|
---|
269 | case System.Windows.Forms.Keys.Oemcomma:
|
---|
270 | break;
|
---|
271 | case System.Windows.Forms.Keys.Oemplus:
|
---|
272 | break;
|
---|
273 |
|
---|
274 | case System.Windows.Forms.Keys.P:
|
---|
275 |
|
---|
276 | break;
|
---|
277 |
|
---|
278 | case System.Windows.Forms.Keys.Packet:
|
---|
279 | break;
|
---|
280 |
|
---|
281 | case System.Windows.Forms.Keys.PageUp:
|
---|
282 | break;
|
---|
283 | case System.Windows.Forms.Keys.Pause:
|
---|
284 | break;
|
---|
285 | case System.Windows.Forms.Keys.Play:
|
---|
286 | break;
|
---|
287 | case System.Windows.Forms.Keys.Print:
|
---|
288 | break;
|
---|
289 | case System.Windows.Forms.Keys.PrintScreen:
|
---|
290 | break;
|
---|
291 |
|
---|
292 | case System.Windows.Forms.Keys.ProcessKey:
|
---|
293 | break;
|
---|
294 | case System.Windows.Forms.Keys.Q:
|
---|
295 | break;
|
---|
296 | case System.Windows.Forms.Keys.R:
|
---|
297 | break;
|
---|
298 | case System.Windows.Forms.Keys.RButton:
|
---|
299 | break;
|
---|
300 | case System.Windows.Forms.Keys.RControlKey:
|
---|
301 | break;
|
---|
302 | case System.Windows.Forms.Keys.RMenu:
|
---|
303 | break;
|
---|
304 | case System.Windows.Forms.Keys.RShiftKey:
|
---|
305 | break;
|
---|
306 | case System.Windows.Forms.Keys.RWin:
|
---|
307 | break;
|
---|
308 |
|
---|
309 | case System.Windows.Forms.Keys.Right:
|
---|
310 | break;
|
---|
311 | case System.Windows.Forms.Keys.S:
|
---|
312 | this.Controller.ParentControl.Save();
|
---|
313 | break;
|
---|
314 | case System.Windows.Forms.Keys.Scroll:
|
---|
315 | break;
|
---|
316 | case System.Windows.Forms.Keys.Select:
|
---|
317 | break;
|
---|
318 | case System.Windows.Forms.Keys.SelectMedia:
|
---|
319 | break;
|
---|
320 | case System.Windows.Forms.Keys.Separator:
|
---|
321 | break;
|
---|
322 | case System.Windows.Forms.Keys.Shift:
|
---|
323 | break;
|
---|
324 | case System.Windows.Forms.Keys.ShiftKey:
|
---|
325 | break;
|
---|
326 | case System.Windows.Forms.Keys.Sleep:
|
---|
327 | break;
|
---|
328 |
|
---|
329 | case System.Windows.Forms.Keys.Space:
|
---|
330 | break;
|
---|
331 | case System.Windows.Forms.Keys.Subtract:
|
---|
332 | break;
|
---|
333 | case System.Windows.Forms.Keys.T:
|
---|
334 | break;
|
---|
335 | case System.Windows.Forms.Keys.Tab:
|
---|
336 | break;
|
---|
337 | case System.Windows.Forms.Keys.U:
|
---|
338 | break;
|
---|
339 | case System.Windows.Forms.Keys.Up:
|
---|
340 | break;
|
---|
341 | case System.Windows.Forms.Keys.V:
|
---|
342 | if (controlIsPressed) {
|
---|
343 | this.Controller.ActivateTool(
|
---|
344 | ControllerBase.PasteToolName);
|
---|
345 | }
|
---|
346 | break;
|
---|
347 | case System.Windows.Forms.Keys.VolumeDown:
|
---|
348 | break;
|
---|
349 | case System.Windows.Forms.Keys.VolumeMute:
|
---|
350 | break;
|
---|
351 | case System.Windows.Forms.Keys.VolumeUp:
|
---|
352 | break;
|
---|
353 | case System.Windows.Forms.Keys.W:
|
---|
354 | break;
|
---|
355 | case System.Windows.Forms.Keys.X:
|
---|
356 | if (controlIsPressed) {
|
---|
357 | this.Controller.ActivateTool(
|
---|
358 | ControllerBase.CutToolName);
|
---|
359 | }
|
---|
360 | break;
|
---|
361 |
|
---|
362 | case System.Windows.Forms.Keys.Y:
|
---|
363 | if (controlIsPressed) {
|
---|
364 | if (this.Controller.UndoManager.CanRedo()) {
|
---|
365 | this.Controller.Redo();
|
---|
366 | }
|
---|
367 | }
|
---|
368 | break;
|
---|
369 | case System.Windows.Forms.Keys.Z:
|
---|
370 | if (controlIsPressed) {
|
---|
371 | if (this.Controller.UndoManager.CanUndo()) {
|
---|
372 | this.Controller.Undo();
|
---|
373 | }
|
---|
374 | }
|
---|
375 | break;
|
---|
376 | case System.Windows.Forms.Keys.Zoom:
|
---|
377 | break;
|
---|
378 | default:
|
---|
379 | break;
|
---|
380 | }
|
---|
381 |
|
---|
382 | this.controlIsPressed = e.Control;
|
---|
383 | }
|
---|
384 |
|
---|
385 | public void KeyDown(System.Windows.Forms.KeyEventArgs e) {
|
---|
386 | this.controlIsPressed = e.Control;
|
---|
387 | }
|
---|
388 |
|
---|
389 | public void KeyPress(System.Windows.Forms.KeyPressEventArgs e) {
|
---|
390 |
|
---|
391 | }
|
---|
392 | }
|
---|
393 | }
|
---|