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