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
|
// MyLoadMenu.cpp
#include "StdAfx.h"
#include "../../../Windows/Menu.h"
#include "../../../Windows/Control/Dialog.h"
#include "../../PropID.h"
#include "../Common/CompressCall.h"
#include "AboutDialog.h"
#include "App.h"
#include "HelpUtils.h"
#include "LangUtils.h"
#include "MyLoadMenu.h"
#include "RegistryUtils.h"
#include "resource.h"
using namespace NWindows;
static const UINT kOpenBookmarkMenuID = 830;
static const UINT kSetBookmarkMenuID = 810;
extern HINSTANCE g_hInstance;
static LPCWSTR kFMHelpTopic = L"FM/index.htm";
extern void OptionsDialog(HWND hwndOwner, HINSTANCE hInstance);
enum
{
kMenuIndex_File = 0,
kMenuIndex_Edit,
kMenuIndex_View,
kMenuIndex_Bookmarks
};
static const UInt32 kTopMenuLangIDs[] = { 500, 501, 502, 503, 504, 505 };
static const UInt32 kAddToFavoritesLangID = 800;
static const UInt32 kToolbarsLangID = 733;
static const CIDLangPair kIDLangPairs[] =
{
{ IDCLOSE, 557 },
{ IDM_VIEW_ARANGE_BY_NAME, 1004 },
{ IDM_VIEW_ARANGE_BY_TYPE, 1020 },
{ IDM_VIEW_ARANGE_BY_DATE, 1012 },
{ IDM_VIEW_ARANGE_BY_SIZE, 1007 }
};
static int FindLangItem(unsigned controlID)
{
for (unsigned i = 0; i < ARRAY_SIZE(kIDLangPairs); i++)
if (kIDLangPairs[i].ControlID == controlID)
return i;
return -1;
}
static int GetSortControlID(PROPID propID)
{
switch (propID)
{
case kpidName: return IDM_VIEW_ARANGE_BY_NAME;
case kpidExtension: return IDM_VIEW_ARANGE_BY_TYPE;
case kpidMTime: return IDM_VIEW_ARANGE_BY_DATE;
case kpidSize: return IDM_VIEW_ARANGE_BY_SIZE;
case kpidNoProperty: return IDM_VIEW_ARANGE_NO_SORT;
}
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_fMask_for_String()
{
return g_IsNew_fMask ? MIIM_STRING : MIIM_TYPE;
}
static UINT Get_fMask_for_FType_and_String()
{
return g_IsNew_fMask ? (MIIM_STRING | MIIM_FTYPE) : MIIM_TYPE;
}
*/
static inline UINT Get_fMask_for_String() { return MIIM_TYPE; }
static inline UINT Get_fMask_for_FType_and_String() { return MIIM_TYPE; }
static void MyChangeMenu(HMENU menuLoc, int level, int menuIndex)
{
CMenu menu;
menu.Attach(menuLoc);
for (int i = 0;; i++)
{
CMenuItem item;
item.fMask = Get_fMask_for_String() | MIIM_SUBMENU | MIIM_ID;
item.fType = MFT_STRING;
if (!menu.GetItem(i, true, item))
break;
{
UString newString;
if (item.hSubMenu)
{
UInt32 langID = 0;
if (level == 1 && menuIndex == kMenuIndex_Bookmarks)
langID = kAddToFavoritesLangID;
else
{
MyChangeMenu(item.hSubMenu, level + 1, i);
if (level == 1 && menuIndex == kMenuIndex_View)
langID = kToolbarsLangID;
else if (level == 0 && i < ARRAY_SIZE(kTopMenuLangIDs))
langID = kTopMenuLangIDs[i];
else
continue;
}
LangString_OnlyFromLangFile(langID, newString);
if (newString.IsEmpty())
continue;
}
else
{
if (item.IsSeparator())
continue;
int langPos = FindLangItem(item.wID);
// we don't need lang change for CRC items!!!
UInt32 langID = langPos >= 0 ? kIDLangPairs[langPos].LangID : item.wID;
if (langID == IDM_OPEN_INSIDE_ONE || langID == IDM_OPEN_INSIDE_PARSER)
{
LangString_OnlyFromLangFile(IDM_OPEN_INSIDE, newString);
if (newString.IsEmpty())
continue;
newString.Replace(L"&", L"");
int tabPos = newString.Find(L"\t");
if (tabPos >= 0)
newString.DeleteFrom(tabPos);
newString += (langID == IDM_OPEN_INSIDE_ONE ? L" *" : L" #");
}
else
LangString_OnlyFromLangFile(langID, newString);
if (newString.IsEmpty())
continue;
int tabPos = item.StringValue.ReverseFind(L'\t');
if (tabPos >= 0)
newString += item.StringValue.Ptr(tabPos);
}
{
item.StringValue = newString;
item.fMask = Get_fMask_for_String();
item.fType = MFT_STRING;
menu.SetItem(i, true, item);
}
}
}
}
static CMenu g_FileMenu;
struct CFileMenuDestroyer
{
~CFileMenuDestroyer() { if ((HMENU)g_FileMenu != 0) g_FileMenu.Destroy(); }
} g_FileMenuDestroyer;
static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec);
static void CopyPopMenu_IfRequired(CMenuItem &item)
{
if (item.hSubMenu)
{
CMenu popup;
popup.CreatePopup();
CopyMenu(item.hSubMenu, popup);
item.hSubMenu = popup;
}
}
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++)
{
CMenuItem item;
item.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | Get_fMask_for_FType_and_String();
item.fType = MFT_STRING;
if (!srcMenu.GetItem(i, true, item))
break;
CopyPopMenu_IfRequired(item);
if (destMenu.InsertItem(startPos, true, item))
startPos++;
}
}
void MyLoadMenu()
{
HMENU baseMenu;
#ifdef UNDER_CE
HMENU oldMenu = g_App._commandBar.GetMenu(0);
if (oldMenu)
::DestroyMenu(oldMenu);
/* BOOL b = */ g_App._commandBar.InsertMenubar(g_hInstance, IDM_MENU, 0);
baseMenu = g_App._commandBar.GetMenu(0);
if (!g_LangID.IsEmpty())
MyChangeMenu(baseMenu, 0, 0);
g_App._commandBar.DrawMenuBar(0);
#else
HWND hWnd = g_HWND;
HMENU oldMenu = ::GetMenu(hWnd);
::SetMenu(hWnd, ::LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_MENU)));
::DestroyMenu(oldMenu);
baseMenu = ::GetMenu(hWnd);
if (!g_LangID.IsEmpty())
MyChangeMenu(baseMenu, 0, 0);
::DrawMenuBar(hWnd);
#endif
if ((HMENU)g_FileMenu != 0)
g_FileMenu.Destroy();
g_FileMenu.CreatePopup();
CopyMenu(::GetSubMenu(baseMenu, 0), g_FileMenu);
}
void OnMenuActivating(HWND /* hWnd */, HMENU hMenu, int position)
{
HMENU mainMenu =
#ifdef UNDER_CE
g_App._commandBar.GetMenu(0);
#else
::GetMenu(g_HWND)
#endif
;
if (::GetSubMenu(mainMenu, position) != hMenu)
return;
if (position == kMenuIndex_File)
{
CMenu menu;
menu.Attach(hMenu);
menu.RemoveAllItems();
g_App.GetFocusedPanel().CreateFileMenu(hMenu);
}
else if (position == kMenuIndex_Edit)
{
/*
CMenu menu;
menu.Attach(hMenu);
menu.EnableItem(IDM_EDIT_CUT, MF_ENABLED);
menu.EnableItem(IDM_EDIT_COPY, MF_ENABLED);
menu.EnableItem(IDM_EDIT_PASTE, IsClipboardFormatAvailableHDROP() ? MF_ENABLED : MF_GRAYED);
*/
}
else if (position == kMenuIndex_View)
{
// 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.CheckRadioItem(IDM_VIEW_ARANGE_BY_NAME, IDM_VIEW_ARANGE_NO_SORT,
GetSortControlID(g_App.GetSortID()), MF_BYCOMMAND);
menu.CheckItemByID(IDM_VIEW_TWO_PANELS, g_App.NumPanels == 2);
menu.CheckItemByID(IDM_VIEW_FLAT_VIEW, g_App.GetFlatMode());
menu.CheckItemByID(IDM_VIEW_ARCHIVE_TOOLBAR, g_App.ShowArchiveToolbar);
menu.CheckItemByID(IDM_VIEW_STANDARD_TOOLBAR, g_App.ShowStandardToolbar);
menu.CheckItemByID(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, g_App.LargeButtons);
menu.CheckItemByID(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, g_App.ShowButtonsLables);
menu.CheckItemByID(IDM_VIEW_AUTO_REFRESH, g_App.Get_AutoRefresh_Mode());
// menu.CheckItemByID(IDM_VIEW_SHOW_STREAMS, g_App.Get_ShowNtfsStrems_Mode());
// menu.CheckItemByID(IDM_VIEW_SHOW_DELETED, g_App.ShowDeletedFiles);
}
else if (position == kMenuIndex_Bookmarks)
{
CMenu menu;
menu.Attach(hMenu);
CMenu subMenu;
subMenu.Attach(menu.GetSubMenu(0));
subMenu.RemoveAllItems();
int i;
for (i = 0; i < 10; i++)
{
UString s = LangString(IDS_BOOKMARK);
s.Add_Space();
wchar_t c = (wchar_t)(L'0' + i);
s += c;
s.AddAscii("\tAlt+Shift+");
s += c;
subMenu.AppendItem(MF_STRING, kSetBookmarkMenuID + i, s);
}
menu.RemoveAllItemsFrom(2);
for (i = 0; i < 10; i++)
{
UString s = g_App.AppState.FastFolders.GetString(i);
const int kMaxSize = 100;
const int kFirstPartSize = kMaxSize / 2;
if (s.Len() > kMaxSize)
{
s.Delete(kFirstPartSize, s.Len() - kMaxSize);
s.Insert(kFirstPartSize, L" ... ");
}
if (s.IsEmpty())
s = L'-';
s.AddAscii("\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;
}
*/
void CFileMenu::Load(HMENU hMenu, unsigned startPos)
{
CMenu destMenu;
destMenu.Attach(hMenu);
UString diffPath;
ReadRegDiff(diffPath);
unsigned numRealItems = startPos;
for (unsigned i = 0;; i++)
{
CMenuItem item;
item.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | Get_fMask_for_FType_and_String();
item.fType = MFT_STRING;
if (!g_FileMenu.GetItem(i, true, item))
break;
{
if (!programMenu && item.wID == IDCLOSE)
continue;
if (item.wID == IDM_DIFF && diffPath.IsEmpty())
continue;
if (item.wID == IDM_OPEN_INSIDE_ONE || item.wID == IDM_OPEN_INSIDE_PARSER)
{
// We use diff as "super mode" marker for additional commands.
if (diffPath.IsEmpty())
continue;
}
bool isOneFsFile = (isFsFolder && numItems == 1 && allAreFiles);
bool disable = (!isOneFsFile && (item.wID == IDM_SPLIT || item.wID == IDM_COMBINE));
if (readOnly)
{
switch (item.wID)
{
case IDM_RENAME:
case IDM_MOVE_TO:
case IDM_DELETE:
case IDM_COMMENT:
case IDM_CREATE_FOLDER:
case IDM_CREATE_FILE:
disable = true;
}
}
if (item.wID == IDM_LINK && numItems != 1)
disable = true;
if (item.wID == IDM_ALT_STREAMS)
disable = !isAltStreamsSupported;
bool isBigScreen = NControl::IsDialogSizeOK(40, 200);
if (!isBigScreen && (disable || item.IsSeparator()))
continue;
CopyPopMenu_IfRequired(item);
if (destMenu.InsertItem(startPos, true, item))
{
if (disable)
destMenu.EnableItem(startPos, MF_BYPOSITION | MF_GRAYED);
startPos++;
}
if (!item.IsSeparator())
numRealItems = startPos;
}
}
destMenu.RemoveAllItemsFrom(numRealItems);
}
bool ExecuteFileCommand(int id)
{
if (id >= kMenuCmdID_Plugin_Start)
{
g_App.GetFocusedPanel().InvokePluginCommand(id);
g_App.GetFocusedPanel()._sevenZipContextMenu.Release();
g_App.GetFocusedPanel()._systemContextMenu.Release();
return true;
}
switch (id)
{
// File
case IDM_OPEN: g_App.OpenItem(); break;
case IDM_OPEN_INSIDE: g_App.OpenItemInside(NULL); break;
case IDM_OPEN_INSIDE_ONE: g_App.OpenItemInside(L"*"); break;
case IDM_OPEN_INSIDE_PARSER: g_App.OpenItemInside(L"#"); break;
case IDM_OPEN_OUTSIDE: g_App.OpenItemOutside(); break;
case IDM_FILE_VIEW: g_App.EditItem(false); break;
case IDM_FILE_EDIT: g_App.EditItem(true); 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: g_App.Delete(!IsKeyDown(VK_SHIFT)); break;
case IDM_HASH_ALL: g_App.CalculateCrc(L"*"); break;
case IDM_CRC32: g_App.CalculateCrc(L"CRC32"); break;
case IDM_CRC64: g_App.CalculateCrc(L"CRC64"); break;
case IDM_SHA1: g_App.CalculateCrc(L"SHA1"); break;
case IDM_SHA256: g_App.CalculateCrc(L"SHA256"); break;
case IDM_DIFF: g_App.DiffFiles(); break;
case IDM_SPLIT: g_App.Split(); break;
case IDM_COMBINE: g_App.Combine(); break;
case IDM_PROPERTIES: g_App.Properties(); break;
case IDM_COMMENT: g_App.Comment(); break;
case IDM_CREATE_FOLDER: g_App.CreateFolder(); break;
case IDM_CREATE_FILE: g_App.CreateFile(); break;
#ifndef UNDER_CE
case IDM_LINK: g_App.Link(); break;
case IDM_ALT_STREAMS: g_App.OpenAltStreams(); break;
#endif
default: return false;
}
return true;
}
static void MyBenchmark(bool totalMode)
{
CPanel::CDisableTimerProcessing disableTimerProcessing1(g_App.Panels[0]);
CPanel::CDisableTimerProcessing disableTimerProcessing2(g_App.Panels[1]);
Benchmark(totalMode);
}
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_CUT:
g_App.EditCut();
break;
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.Refresh_StatusBar();
break;
case IDM_DESELECT_ALL:
g_App.SelectAll(false);
g_App.Refresh_StatusBar();
break;
case IDM_INVERT_SELECTION:
g_App.InvertSelection();
g_App.Refresh_StatusBar();
break;
case IDM_SELECT:
g_App.SelectSpec(true);
g_App.Refresh_StatusBar();
break;
case IDM_DESELECT:
g_App.SelectSpec(false);
g_App.Refresh_StatusBar();
break;
case IDM_SELECT_BY_TYPE:
g_App.SelectByType(true);
g_App.Refresh_StatusBar();
break;
case IDM_DESELECT_BY_TYPE:
g_App.SelectByType(false);
g_App.Refresh_StatusBar();
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), kMenuIndex_View));
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(kpidMTime); 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_FLAT_VIEW: g_App.ChangeFlatMode(); break;
case IDM_VIEW_REFRESH: g_App.RefreshView(); break;
case IDM_VIEW_AUTO_REFRESH: g_App.Change_AutoRefresh_Mode(); break;
// case IDM_VIEW_SHOW_STREAMS: g_App.Change_ShowNtfsStrems_Mode(); break;
/*
case IDM_VIEW_SHOW_DELETED:
{
g_App.Change_ShowDeleted();
bool isChecked = g_App.ShowDeletedFiles;
Save_ShowDeleted(isChecked);
}
*/
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: MyBenchmark(false); break;
case IDM_BENCHMARK2: MyBenchmark(true); 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;
}
|