1 // PanelKey.cpp
2
3 #include "StdAfx.h"
4
5 #include "Panel.h"
6 #include "HelpUtils.h"
7
8 #include "../../PropID.h"
9 #include "App.h"
10
11 using namespace NWindows;
12
13 // #define kHelpTopic "FM/index.htm"
14
15 struct CVKeyPropIDPair
16 {
17 WORD VKey;
18 PROPID PropID;
19 };
20
21 static const CVKeyPropIDPair g_VKeyPropIDPairs[] =
22 {
23 { VK_F3, kpidName },
24 { VK_F4, kpidExtension },
25 { VK_F5, kpidMTime },
26 { VK_F6, kpidSize },
27 { VK_F7, kpidNoProperty }
28 };
29
FindVKeyPropIDPair(WORD vKey)30 static int FindVKeyPropIDPair(WORD vKey)
31 {
32 for (unsigned i = 0; i < Z7_ARRAY_SIZE(g_VKeyPropIDPairs); i++)
33 if (g_VKeyPropIDPairs[i].VKey == vKey)
34 return (int)i;
35 return -1;
36 }
37
38
OnKeyDown(LPNMLVKEYDOWN keyDownInfo,LRESULT & result)39 bool CPanel::OnKeyDown(LPNMLVKEYDOWN keyDownInfo, LRESULT &result)
40 {
41 if (keyDownInfo->wVKey == VK_TAB && keyDownInfo->hdr.hwndFrom == _listView)
42 {
43 _panelCallback->OnTab();
44 return false;
45 }
46 const bool alt = IsKeyDown(VK_MENU);
47 const bool ctrl = IsKeyDown(VK_CONTROL);
48 // const bool leftCtrl = IsKeyDown(VK_LCONTROL);
49 const bool rightCtrl = IsKeyDown(VK_RCONTROL);
50 const bool shift = IsKeyDown(VK_SHIFT);
51 result = 0;
52
53 if (keyDownInfo->wVKey >= '0' &&
54 keyDownInfo->wVKey <= '9' &&
55 (rightCtrl || alt))
56 {
57 const unsigned index = (unsigned)(keyDownInfo->wVKey - '0');
58 if (shift)
59 {
60 SetBookmark(index);
61 return true;
62 }
63 else
64 {
65 OpenBookmark(index);
66 return true;
67 }
68 }
69
70 if ((keyDownInfo->wVKey == VK_F2 ||
71 keyDownInfo->wVKey == VK_F1)
72 && alt && !ctrl && !shift)
73 {
74 _panelCallback->SetFocusToPath(keyDownInfo->wVKey == VK_F1 ? 0 : 1);
75 return true;
76 }
77
78 if ((keyDownInfo->wVKey == VK_F9) && !alt && !ctrl && !shift)
79 {
80 g_App.SwitchOnOffOnePanel();
81 }
82
83 if (keyDownInfo->wVKey >= VK_F3 && keyDownInfo->wVKey <= VK_F12 && ctrl)
84 {
85 const int index = FindVKeyPropIDPair(keyDownInfo->wVKey);
86 if (index >= 0)
87 SortItemsWithPropID(g_VKeyPropIDPairs[index].PropID);
88 }
89
90 switch (keyDownInfo->wVKey)
91 {
92 case VK_SHIFT:
93 {
94 _selectionIsDefined = false;
95 _prevFocusedItem = _listView.GetFocusedItem();
96 break;
97 }
98 /*
99 case VK_F1:
100 {
101 // ShowHelpWindow(NULL, kHelpTopic);
102 break;
103 }
104 */
105 case VK_F2:
106 {
107 if (!alt && !ctrl &&!shift)
108 {
109 RenameFile();
110 return true;
111 }
112 break;
113 }
114 case VK_F3:
115 {
116 if (!alt && !ctrl && !shift)
117 {
118 EditItem(false);
119 return true;
120 }
121 break;
122 }
123 case VK_F4:
124 {
125 if (!alt && !ctrl && !shift)
126 {
127 EditItem(true);
128 return true;
129 }
130 if (!alt && !ctrl && shift)
131 {
132 CreateFile();
133 return true;
134 }
135 break;
136 }
137 case VK_F5:
138 {
139 if (!alt && !ctrl)
140 {
141 _panelCallback->OnCopy(false, shift);
142 return true;
143 }
144 break;
145 }
146 case VK_F6:
147 {
148 if (!alt && !ctrl)
149 {
150 _panelCallback->OnCopy(true, shift);
151 return true;
152 }
153 break;
154 }
155 case VK_F7:
156 {
157 if (!alt && !ctrl && !shift)
158 {
159 /* we can process F7 via menu ACCELERATOR.
160 But menu loading can be slow in case of UNC paths and system menu.
161 So we use don't use ACCELERATOR */
162 CreateFolder();
163 return true;
164 }
165 break;
166 }
167 case VK_DELETE:
168 {
169 DeleteItems(!shift);
170 return true;
171 }
172 case VK_INSERT:
173 {
174 if (!alt)
175 {
176 if (ctrl && !shift)
177 {
178 EditCopy();
179 return true;
180 }
181 if (shift && !ctrl)
182 {
183 EditPaste();
184 return true;
185 }
186 if (!shift && !ctrl && _mySelectMode)
187 {
188 OnInsert();
189 return true;
190 }
191 }
192 return false;
193 }
194 case VK_DOWN:
195 {
196 if (shift)
197 OnArrowWithShift();
198 return false;
199 }
200 case VK_UP:
201 {
202 if (alt)
203 _panelCallback->OnSetSameFolder();
204 else if (shift)
205 OnArrowWithShift();
206 return false;
207 }
208 case VK_RIGHT:
209 {
210 if (alt)
211 _panelCallback->OnSetSubFolder();
212 else if (shift)
213 OnArrowWithShift();
214 return false;
215 }
216 case VK_LEFT:
217 {
218 if (alt)
219 _panelCallback->OnSetSubFolder();
220 else if (shift)
221 OnArrowWithShift();
222 return false;
223 }
224 case VK_NEXT:
225 {
226 if (ctrl && !alt && !shift)
227 {
228 // EnterToFocused();
229 return true;
230 }
231 break;
232 }
233 case VK_ADD:
234 {
235 if (alt)
236 SelectByType(true);
237 else if (shift)
238 SelectAll(true);
239 else if (!ctrl)
240 SelectSpec(true);
241 return true;
242 }
243 case VK_SUBTRACT:
244 {
245 if (alt)
246 SelectByType(false);
247 else if (shift)
248 SelectAll(false);
249 else
250 SelectSpec(false);
251 return true;
252 }
253 /*
254 case VK_DELETE:
255 CommandDelete();
256 return 0;
257 case VK_F1:
258 CommandHelp();
259 return 0;
260 */
261 case VK_BACK:
262 OpenParentFolder();
263 return true;
264 /*
265 case VK_DIVIDE:
266 case '\\':
267 case '/':
268 case VK_OEM_5:
269 {
270 // OpenRootFolder();
271 OpenDrivesFolder();
272
273 return true;
274 }
275 */
276 case 'A':
277 if (ctrl)
278 {
279 SelectAll(true);
280 return true;
281 }
282 return false;
283 case 'X':
284 if (ctrl)
285 {
286 EditCut();
287 return true;
288 }
289 return false;
290 case 'C':
291 if (ctrl)
292 {
293 EditCopy();
294 return true;
295 }
296 return false;
297 case 'V':
298 if (ctrl)
299 {
300 EditPaste();
301 return true;
302 }
303 return false;
304 case 'N':
305 if (ctrl)
306 {
307 CreateFile();
308 return true;
309 }
310 return false;
311 case 'R':
312 if (ctrl)
313 {
314 OnReload();
315 return true;
316 }
317 return false;
318 case 'W':
319 if (ctrl)
320 {
321 // SendMessage();
322 PostMessage(g_HWND, WM_COMMAND, IDCLOSE, 0);
323 return true;
324 }
325 return false;
326 case 'Z':
327 if (ctrl)
328 {
329 ChangeComment();
330 return true;
331 }
332 return false;
333 case '1':
334 case '2':
335 case '3':
336 case '4':
337 if (ctrl)
338 {
339 const unsigned styleIndex = (unsigned)(keyDownInfo->wVKey - '1');
340 SetListViewMode(styleIndex);
341 return true;
342 }
343 return false;
344 case VK_MULTIPLY:
345 {
346 InvertSelection();
347 return true;
348 }
349 case VK_F12:
350 if (alt && !ctrl && !shift)
351 {
352 FoldersHistory();
353 return true;
354 }
355 }
356 return false;
357 }
358