1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
// MyLoadMenu
#include "StdAfx.h"
#include "Common/StringConvert.h"
#include "Windows/Menu.h"
#include "Windows/Error.h"
#include "../PropID.h"
#include "resource.h"
#include "App.h"
#include "Resource/AboutDialog/AboutDialog.h"
#include "../UI/Common/CompressCall.h"
#include "HelpUtils.h"
#include "LangUtils.h"
#include "PluginInterface.h"
static const UINT kOpenBookmarkMenuID = 730;
static const UINT kSetBookmarkMenuID = 740;
extern HINSTANCE g_hInstance;
static LPCWSTR kFMHelpTopic = L"FM/index.htm";
extern void OptionsDialog(HWND hwndOwner, HINSTANCE hInstance);
using namespace NWindows;
static const int kFileMenuIndex = 0;
static const int kViewMenuIndex = 2;
static const int kBookmarksMenuIndex = kViewMenuIndex + 1;
struct CStringLangPair
{
wchar_t *String;
UINT32 LangID;
};
static CStringLangPair kStringLangPairs[] =
{
{ L"&File", 0x03000102 },
{ L"&Edit", 0x03000103 },
{ L"&View", 0x03000104 },
{ L"&Bookmarks", 0x03000107 },
{ L"&Tools", 0x03000105 },
{ L"&Help", 0x03000106 },
};
UINT32 kAddToFavoritesLangID = 0x03000710;
UINT32 kToolbarsLangID = 0x03000451;
/*
static int FindStringLangItem(const UString &anItem)
{
for (int i = 0; i < sizeof(kStringLangPairs) /
sizeof(kStringLangPairs[0]); i++)
if (anItem.CompareNoCase(kStringLangPairs[i].String) == 0)
return i;
return -1;
}
*/
static CIDLangPair kIDLangPairs[] =
{
// File
{ IDM_FILE_OPEN, 0x03000210 },
{ IDM_FILE_OPEN_INSIDE, 0x03000211 },
{ IDM_FILE_OPEN_OUTSIDE, 0x03000212 },
{ IDM_FILE_VIEW, 0x03000220 },
{ IDM_FILE_EDIT, 0x03000221 },
{ IDM_RENAME, 0x03000230 },
{ IDM_COPY_TO, 0x03000231 },
{ IDM_MOVE_TO, 0x03000232 },
{ IDM_DELETE, 0x03000233 },
{ IDM_FILE_PROPERTIES, 0x03000240 },
{ IDM_FILE_COMMENT, 0x03000241 },
{ IDM_FILE_CRC, 0x03000242 },
{ IDM_FILE_SPLIT, 0x03000270 },
{ IDM_FILE_COMBINE, 0x03000271 },
{ IDM_CREATE_FOLDER, 0x03000250 },
{ IDM_CREATE_FILE, 0x03000251 },
{ IDCLOSE, 0x03000260 },
// Edit
{ IDM_EDIT_CUT, 0x03000320 },
{ IDM_EDIT_COPY, 0x03000321 },
{ IDM_EDIT_PASTE, 0x03000322 },
{ IDM_SELECT_ALL, 0x03000330 },
{ IDM_DESELECT_ALL, 0x03000331 },
{ IDM_INVERT_SELECTION, 0x03000332 },
{ IDM_SELECT, 0x03000333 },
{ IDM_DESELECT, 0x03000334 },
{ IDM_SELECT_BY_TYPE, 0x03000335 },
{ IDM_DESELECT_BY_TYPE, 0x03000336 },
{ IDM_VIEW_LARGE_ICONS, 0x03000410 },
{ IDM_VIEW_SMALL_ICONS, 0x03000411 },
{ IDM_VIEW_LIST, 0x03000412 },
{ IDM_VIEW_DETAILS, 0x03000413 },
{ IDM_VIEW_ARANGE_BY_NAME, 0x02000204 },
{ IDM_VIEW_ARANGE_BY_TYPE, 0x02000214 },
{ IDM_VIEW_ARANGE_BY_DATE, 0x0200020C },
{ IDM_VIEW_ARANGE_BY_SIZE, 0x02000207 },
{ IDM_VIEW_ARANGE_NO_SORT, 0x03000420 },
{ IDM_OPEN_ROOT_FOLDER, 0x03000430 },
{ IDM_OPEN_PARENT_FOLDER, 0x03000431 },
{ IDM_FOLDERS_HISTORY, 0x03000432 },
{ IDM_VIEW_REFRESH, 0x03000440 },
{ IDM_VIEW_FLAT_VIEW, 0x03000449 },
{ IDM_VIEW_TWO_PANELS, 0x03000450 },
{ IDM_VIEW_ARCHIVE_TOOLBAR, 0x03000460 },
{ IDM_VIEW_STANDARD_TOOLBAR, 0x03000461 },
{ IDM_VIEW_TOOLBARS_LARGE_BUTTONS, 0x03000462 },
{ IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, 0x03000463 },
{ IDM_OPTIONS, 0x03000510 },
{ IDM_BENCHMARK, 0x03000511 },
{ IDM_HELP_CONTENTS, 0x03000610 },
{ IDM_ABOUT, 0x03000620 }
};
static int FindLangItem(int ControlID)
{
for (int i = 0; i < sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]); i++)
if (kIDLangPairs[i].ControlID == ControlID)
return i;
return -1;
}
/*
static bool g_IsNew_fMask = true;
class CInit_fMask
{
public:
CInit_fMask()
{
g_IsNew_fMask = false;
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (::GetVersionEx(&vi))
{
g_IsNew_fMask = (vi.dwMajorVersion > 4 ||
(vi.dwMajorVersion == 4 && vi.dwMinorVersion > 0));
}
g_IsNew_fMask = false;
}
} g_Init_fMask;
// it's hack for supporting Windows NT
// constants are from WinUser.h
#if(WINVER < 0x0500)
#define MIIM_STRING 0x00000040
#define MIIM_BITMAP 0x00000080
#define MIIM_FTYPE 0x00000100
#endif
static UINT Get_fMaskForString()
{
return g_IsNew_fMask ? MIIM_STRING : MIIM_TYPE;
}
static UINT Get_fMaskForFTypeAndString()
{
return g_IsNew_fMask ? (MIIM_STRING | MIIM_FTYPE) : MIIM_TYPE;
}
*/
static UINT Get_fMaskForString()
{
return MIIM_TYPE;
}
static UINT Get_fMaskForFTypeAndString()
{
return MIIM_TYPE;
}
static void MyChangeMenu(HMENU menuLoc, int level, int menuIndex)
{
CMenu menu;
menu.Attach(menuLoc);
for (int i = 0; i < menu.GetItemCount(); i++)
{
CMenuItem item;
item.fMask = Get_fMaskForString() | MIIM_SUBMENU | MIIM_ID;
item.fType = MFT_STRING;
if (menu.GetItem(i, true, item))
{
UString newString;
if (item.hSubMenu)
{
if (level == 1 && menuIndex == kBookmarksMenuIndex)
newString = LangString(kAddToFavoritesLangID);
else
{
MyChangeMenu(item.hSubMenu, level + 1, i);
if (level == 1 && menuIndex == kViewMenuIndex)
{
newString = LangString(kToolbarsLangID);
}
else
{
if (level == 0 && i < sizeof(kStringLangPairs) /
sizeof(kStringLangPairs[0]))
newString = LangString(kStringLangPairs[i].LangID);
else
continue;
}
}
if (newString.IsEmpty())
continue;
}
else
{
int langPos = FindLangItem(item.wID);
if (langPos < 0)
continue;
newString = LangString(kIDLangPairs[langPos].LangID);
if (newString.IsEmpty())
continue;
UString shorcutString = item.StringValue;
int tabPos = shorcutString.ReverseFind(wchar_t('\t'));
if (tabPos >= 0)
newString += shorcutString.Mid(tabPos);
}
{
item.StringValue = newString;
item.fMask = Get_fMaskForString();
item.fType = MFT_STRING;
menu.SetItem(i, true, item);
}
}
}
}
CMenu g_FileMenu;
class CFileMenuDestroyer
{
public:
~CFileMenuDestroyer()
{
if ((HMENU)g_FileMenu != 0)
g_FileMenu.Destroy();
}
} g_FileMenuDestroyer;
void MyLoadMenu(HWND hWnd)
{
if ((HMENU)g_FileMenu != 0)
g_FileMenu.Destroy();
HMENU oldMenu = ::GetMenu(hWnd);
HMENU baseMenu = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_MENU));
::SetMenu(hWnd, baseMenu);
::DestroyMenu(oldMenu);
if (!g_LangID.IsEmpty())
{
HMENU menuOld = ::GetMenu(hWnd);
MyChangeMenu(menuOld, 0, 0);
}
::DrawMenuBar(hWnd);
}
extern HWND g_HWND;
void MyLoadMenu()
{
MyLoadMenu(g_HWND);
}
static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec)
{
CMenu srcMenu;
srcMenu.Attach(srcMenuSpec);
CMenu destMenu;
destMenu.Attach(destMenuSpec);
int startPos = 0;
for (int i = 0; i < srcMenu.GetItemCount(); i++)
{
CMenuItem item;
item.fMask = MIIM_STATE | MIIM_ID | Get_fMaskForFTypeAndString();
item.fType = MFT_STRING;
if (srcMenu.GetItem(i, true, item))
if (destMenu.InsertItem(startPos, true, item))
startPos++;
}
}
void OnMenuActivating(HWND /* hWnd */, HMENU hMenu, int position)
{
if (::GetSubMenu(::GetMenu(g_HWND), position) != hMenu)
return;
if (position == kFileMenuIndex)
{
if ((HMENU)g_FileMenu == 0)
{
g_FileMenu.CreatePopup();
CopyMenu(hMenu, g_FileMenu);
}
CMenu menu;
menu.Attach(hMenu);
while (menu.GetItemCount() > 0)
{
if (!menu.RemoveItem(0, MF_BYPOSITION))
break;
}
// CopyMenu(g_FileMenu, hMenu);
g_App.GetFocusedPanel().CreateFileMenu(hMenu);
}
else if (position == kViewMenuIndex)
{
// View;
CMenu menu;
menu.Attach(hMenu);
menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS,
IDM_VIEW_LARGE_ICONS + g_App.GetListViewMode(), MF_BYCOMMAND);
menu.CheckItem(IDM_VIEW_TWO_PANELS, MF_BYCOMMAND |
((g_App.NumPanels == 2) ? MF_CHECKED : MF_UNCHECKED));
menu.CheckItem(IDM_VIEW_FLAT_VIEW, MF_BYCOMMAND |
((g_App.GetFlatMode()) ? MF_CHECKED : MF_UNCHECKED));
menu.CheckItem(IDM_VIEW_ARCHIVE_TOOLBAR, MF_BYCOMMAND |
(g_App.ShowArchiveToolbar ? MF_CHECKED : MF_UNCHECKED));
menu.CheckItem(IDM_VIEW_STANDARD_TOOLBAR, MF_BYCOMMAND |
(g_App.ShowStandardToolbar ? MF_CHECKED : MF_UNCHECKED));
menu.CheckItem(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, MF_BYCOMMAND |
(g_App.LargeButtons ? MF_CHECKED : MF_UNCHECKED));
menu.CheckItem(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, MF_BYCOMMAND |
(g_App.ShowButtonsLables ? MF_CHECKED : MF_UNCHECKED));
}
else if (position == kBookmarksMenuIndex)
{
CMenu menu;
menu.Attach(hMenu);
CMenu subMenu;
subMenu.Attach(menu.GetSubMenu(0));
while (subMenu.GetItemCount() > 0)
subMenu.RemoveItem(subMenu.GetItemCount() - 1, MF_BYPOSITION);
int i;
for (i = 0; i < 10; i++)
{
UString s = LangString(IDS_BOOKMARK, 0x03000720);
s += L" ";
wchar_t c = (wchar_t)(L'0' + i);
s += c;
s += L"\tAlt+Shift+";
s += c;
subMenu.AppendItem(MF_STRING, kSetBookmarkMenuID + i, s);
}
while (menu.GetItemCount() > 2)
menu.RemoveItem(menu.GetItemCount() - 1, MF_BYPOSITION);
for (i = 0; i < 10; i++)
{
UString path = g_App.AppState.FastFolders.GetString(i);
const int kMaxSize = 100;
const int kFirstPartSize = kMaxSize / 2;
if (path.Length() > kMaxSize)
{
path = path.Left(kFirstPartSize) + UString(L" ... ") +
path.Right(kMaxSize - kFirstPartSize);
}
UString s = path;
if (s.IsEmpty())
s = L"-";
s += L"\tAlt+";
s += (wchar_t)(L'0' + i);
menu.AppendItem(MF_STRING, kOpenBookmarkMenuID + i, s);
}
}
}
/*
It doesn't help
void OnMenuUnActivating(HWND hWnd, HMENU hMenu, int id)
{
if (::GetSubMenu(::GetMenu(g_HWND), 0) != hMenu)
return;
// g_App.GetFocusedPanel()._contextMenu.Release();
}
void OnMenuUnActivating(HWND hWnd)
{
}
*/
void LoadFileMenu(HMENU hMenu, int startPos, bool /* forFileMode */, bool programMenu)
{
{
CMenu srcMenu;
srcMenu.Attach(::GetSubMenu(::GetMenu(g_HWND), 0));
if ((HMENU)g_FileMenu == 0)
{
g_FileMenu.CreatePopup();
CopyMenu(srcMenu, g_FileMenu);
}
}
CMenu destMenu;
destMenu.Attach(hMenu);
for (int i = 0; i < g_FileMenu.GetItemCount(); i++)
{
CMenuItem item;
item.fMask = MIIM_STATE | MIIM_ID | Get_fMaskForFTypeAndString();
item.fType = MFT_STRING;
if (g_FileMenu.GetItem(i, true, item))
{
if (!programMenu)
if (item.wID == IDCLOSE)
continue;
/*
bool createItem = (item.wID == IDM_CREATE_FOLDER || item.wID == IDM_CREATE_FILE);
if (forFileMode)
{
if (createItem)
continue;
}
else
{
if (!createItem)
continue;
}
*/
if (destMenu.InsertItem(startPos, true, item))
startPos++;
}
}
while (destMenu.GetItemCount() > 0)
{
CMenuItem item;
item.fMask = MIIM_TYPE;
item.fType = 0;
// item.dwTypeData = 0;
int lastIndex = destMenu.GetItemCount() - 1;
if (!destMenu.GetItem(lastIndex, true, item))
break;
if(item.fType != MFT_SEPARATOR)
break;
if (!destMenu.RemoveItem(lastIndex, MF_BYPOSITION))
break;
}
}
bool ExecuteFileCommand(int id)
{
if (id >= kPluginMenuStartID)
{
g_App.GetFocusedPanel().InvokePluginCommand(id);
g_App.GetFocusedPanel()._sevenZipContextMenu.Release();
g_App.GetFocusedPanel()._systemContextMenu.Release();
return true;
}
switch (id)
{
// File
case IDM_FILE_OPEN:
g_App.OpenItem();
break;
case IDM_FILE_OPEN_INSIDE:
g_App.OpenItemInside();
break;
case IDM_FILE_OPEN_OUTSIDE:
g_App.OpenItemOutside();
break;
case IDM_FILE_VIEW:
break;
case IDM_FILE_EDIT:
g_App.EditItem();
break;
case IDM_RENAME:
g_App.Rename();
break;
case IDM_COPY_TO:
g_App.CopyTo();
break;
case IDM_MOVE_TO:
g_App.MoveTo();
break;
case IDM_DELETE:
{
bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
g_App.Delete(!shift);
break;
}
case IDM_FILE_CRC:
g_App.CalculateCrc();
break;
case IDM_FILE_SPLIT:
g_App.Split();
break;
case IDM_FILE_COMBINE:
g_App.Combine();
break;
case IDM_FILE_PROPERTIES:
g_App.Properties();
break;
case IDM_FILE_COMMENT:
g_App.Comment();
break;
case IDM_CREATE_FOLDER:
g_App.CreateFolder();
break;
case IDM_CREATE_FILE:
g_App.CreateFile();
break;
default:
return false;
}
return true;
}
bool OnMenuCommand(HWND hWnd, int id)
{
if (ExecuteFileCommand(id))
return true;
switch (id)
{
// File
case IDCLOSE:
SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
// Edit
case IDM_EDIT_COPY:
g_App.EditCopy();
break;
case IDM_EDIT_PASTE:
g_App.EditPaste();
break;
case IDM_SELECT_ALL:
g_App.SelectAll(true);
g_App.RefreshStatusBar();
break;
case IDM_DESELECT_ALL:
g_App.SelectAll(false);
g_App.RefreshStatusBar();
break;
case IDM_INVERT_SELECTION:
g_App.InvertSelection();
g_App.RefreshStatusBar();
break;
case IDM_SELECT:
g_App.SelectSpec(true);
g_App.RefreshStatusBar();
break;
case IDM_DESELECT:
g_App.SelectSpec(false);
g_App.RefreshStatusBar();
break;
case IDM_SELECT_BY_TYPE:
g_App.SelectByType(true);
g_App.RefreshStatusBar();
break;
case IDM_DESELECT_BY_TYPE:
g_App.SelectByType(false);
g_App.RefreshStatusBar();
break;
//View
case IDM_VIEW_LARGE_ICONS:
case IDM_VIEW_SMALL_ICONS:
case IDM_VIEW_LIST:
case IDM_VIEW_DETAILS:
{
UINT index = id - IDM_VIEW_LARGE_ICONS;
if (index < 4)
{
g_App.SetListViewMode(index);
/*
CMenu menu;
menu.Attach(::GetSubMenu(::GetMenu(hWnd), kViewMenuIndex));
menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS,
id, MF_BYCOMMAND);
*/
}
break;
}
case IDM_VIEW_ARANGE_BY_NAME:
{
g_App.SortItemsWithPropID(kpidName);
break;
}
case IDM_VIEW_ARANGE_BY_TYPE:
{
g_App.SortItemsWithPropID(kpidExtension);
break;
}
case IDM_VIEW_ARANGE_BY_DATE:
{
g_App.SortItemsWithPropID(kpidLastWriteTime);
break;
}
case IDM_VIEW_ARANGE_BY_SIZE:
{
g_App.SortItemsWithPropID(kpidSize);
break;
}
case IDM_VIEW_ARANGE_NO_SORT:
{
g_App.SortItemsWithPropID(kpidNoProperty);
break;
}
case IDM_OPEN_ROOT_FOLDER:
g_App.OpenRootFolder();
break;
case IDM_OPEN_PARENT_FOLDER:
g_App.OpenParentFolder();
break;
case IDM_FOLDERS_HISTORY:
g_App.FoldersHistory();
break;
case IDM_VIEW_REFRESH:
g_App.RefreshView();
break;
case IDM_VIEW_FLAT_VIEW:
g_App.ChangeFlatMode();
break;
case IDM_VIEW_TWO_PANELS:
g_App.SwitchOnOffOnePanel();
break;
case IDM_VIEW_STANDARD_TOOLBAR:
g_App.SwitchStandardToolbar();
break;
case IDM_VIEW_ARCHIVE_TOOLBAR:
g_App.SwitchArchiveToolbar();
break;
case IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT:
g_App.SwitchButtonsLables();
break;
case IDM_VIEW_TOOLBARS_LARGE_BUTTONS:
g_App.SwitchLargeButtons();
break;
// Tools
case IDM_OPTIONS:
OptionsDialog(hWnd, g_hInstance);
break;
case IDM_BENCHMARK:
Benchmark();
break;
// Help
case IDM_HELP_CONTENTS:
ShowHelpWindow(NULL, kFMHelpTopic);
break;
case IDM_ABOUT:
{
CAboutDialog dialog;
dialog.Create(hWnd);
break;
}
default:
{
if (id >= kOpenBookmarkMenuID && id <= kOpenBookmarkMenuID + 9)
{
g_App.OpenBookmark(id - kOpenBookmarkMenuID);
return true;
}
else if (id >= kSetBookmarkMenuID && id <= kSetBookmarkMenuID + 9)
{
g_App.SetBookmark(id - kSetBookmarkMenuID);
return true;
}
return false;
}
}
return true;
}
|