1 // MyLoadMenu.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../../Windows/Menu.h"
6 #include "../../../Windows/TimeUtils.h"
7 #include "../../../Windows/Control/Dialog.h"
8 
9 #include "../../PropID.h"
10 
11 #include "../Common/CompressCall.h"
12 
13 #include "AboutDialog.h"
14 #include "App.h"
15 #include "HelpUtils.h"
16 #include "LangUtils.h"
17 #include "MyLoadMenu.h"
18 #include "RegistryUtils.h"
19 
20 #include "resource.h"
21 
22 using namespace NWindows;
23 
24 static const UINT kOpenBookmarkMenuID = 830;
25 static const UINT kSetBookmarkMenuID = 810;
26 static const UINT kMenuID_Time_Parent = 760;
27 static const UINT kMenuID_Time = 761;
28 
29 extern HINSTANCE g_hInstance;
30 
31 #define kFMHelpTopic "FM/index.htm"
32 
33 extern void OptionsDialog(HWND hwndOwner, HINSTANCE hInstance);
34 
35 enum
36 {
37   kMenuIndex_File = 0,
38   kMenuIndex_Edit,
39   kMenuIndex_View,
40   kMenuIndex_Bookmarks
41 };
42 
43 static const UInt32 kTopMenuLangIDs[] = { 500, 501, 502, 503, 504, 505 };
44 
45 static const UInt32 kAddToFavoritesLangID = 800;
46 static const UInt32 kToolbarsLangID = 733;
47 
48 static const CIDLangPair kIDLangPairs[] =
49 {
50   { IDCLOSE, 557 },
51   { IDM_VIEW_ARANGE_BY_NAME, 1004 },
52   { IDM_VIEW_ARANGE_BY_TYPE, 1020 },
53   { IDM_VIEW_ARANGE_BY_DATE, 1012 },
54   { IDM_VIEW_ARANGE_BY_SIZE, 1007 }
55 };
56 
FindLangItem(unsigned controlID)57 static int FindLangItem(unsigned controlID)
58 {
59   for (unsigned i = 0; i < ARRAY_SIZE(kIDLangPairs); i++)
60     if (kIDLangPairs[i].ControlID == controlID)
61       return i;
62   return -1;
63 }
64 
GetSortControlID(PROPID propID)65 static int GetSortControlID(PROPID propID)
66 {
67   switch (propID)
68   {
69     case kpidName:       return IDM_VIEW_ARANGE_BY_NAME;
70     case kpidExtension:  return IDM_VIEW_ARANGE_BY_TYPE;
71     case kpidMTime:      return IDM_VIEW_ARANGE_BY_DATE;
72     case kpidSize:       return IDM_VIEW_ARANGE_BY_SIZE;
73     case kpidNoProperty: return IDM_VIEW_ARANGE_NO_SORT;
74   }
75   return -1;
76 }
77 
78 /*
79 static bool g_IsNew_fMask = true;
80 
81 class CInit_fMask
82 {
83 public:
84   CInit_fMask()
85   {
86     g_IsNew_fMask = false;
87     OSVERSIONINFO vi;
88     vi.dwOSVersionInfoSize = sizeof(vi);
89     if (::GetVersionEx(&vi))
90     {
91       g_IsNew_fMask = (vi.dwMajorVersion > 4 ||
92         (vi.dwMajorVersion == 4 && vi.dwMinorVersion > 0));
93     }
94     g_IsNew_fMask = false;
95   }
96 } g_Init_fMask;
97 
98 // it's hack for supporting Windows NT
99 // constants are from WinUser.h
100 
101 #if (WINVER < 0x0500)
102 #define MIIM_STRING      0x00000040
103 #define MIIM_BITMAP      0x00000080
104 #define MIIM_FTYPE       0x00000100
105 #endif
106 
107 static UINT Get_fMask_for_String()
108 {
109   return g_IsNew_fMask ? MIIM_STRING : MIIM_TYPE;
110 }
111 
112 static UINT Get_fMask_for_FType_and_String()
113 {
114   return g_IsNew_fMask ? (MIIM_STRING | MIIM_FTYPE) : MIIM_TYPE;
115 }
116 */
117 
Get_fMask_for_String()118 static inline UINT Get_fMask_for_String() { return MIIM_TYPE; }
Get_fMask_for_FType_and_String()119 static inline UINT Get_fMask_for_FType_and_String() { return MIIM_TYPE; }
120 
121 
MyChangeMenu(HMENU menuLoc,int level,int menuIndex)122 static void MyChangeMenu(HMENU menuLoc, int level, int menuIndex)
123 {
124   CMenu menu;
125   menu.Attach(menuLoc);
126 
127   for (unsigned i = 0;; i++)
128   {
129     CMenuItem item;
130     item.fMask = Get_fMask_for_String() | MIIM_SUBMENU | MIIM_ID;
131     item.fType = MFT_STRING;
132     if (!menu.GetItem(i, true, item))
133       break;
134     {
135       UString newString;
136       if (item.hSubMenu)
137       {
138         UInt32 langID = 0;
139         if (level == 1 && menuIndex == kMenuIndex_Bookmarks)
140           langID = kAddToFavoritesLangID;
141         else
142         {
143           MyChangeMenu(item.hSubMenu, level + 1, i);
144           if (level == 1 && menuIndex == kMenuIndex_View)
145           {
146             if (item.wID == kMenuID_Time_Parent || item.StringValue.IsPrefixedBy_Ascii_NoCase("20"))
147               continue;
148             else
149               langID = kToolbarsLangID;
150           }
151           else if (level == 0 && i < ARRAY_SIZE(kTopMenuLangIDs))
152             langID = kTopMenuLangIDs[i];
153           else
154             continue;
155         }
156 
157         LangString_OnlyFromLangFile(langID, newString);
158 
159         if (newString.IsEmpty())
160           continue;
161       }
162       else
163       {
164         if (item.IsSeparator())
165           continue;
166         int langPos = FindLangItem(item.wID);
167 
168         // we don't need lang change for CRC items!!!
169 
170         UInt32 langID = langPos >= 0 ? kIDLangPairs[langPos].LangID : item.wID;
171 
172         if (langID == IDM_OPEN_INSIDE_ONE || langID == IDM_OPEN_INSIDE_PARSER)
173         {
174           LangString_OnlyFromLangFile(IDM_OPEN_INSIDE, newString);
175           if (newString.IsEmpty())
176             continue;
177           newString.Replace(L"&", L"");
178           int tabPos = newString.Find(L"\t");
179           if (tabPos >= 0)
180             newString.DeleteFrom(tabPos);
181           newString += (langID == IDM_OPEN_INSIDE_ONE ? " *" : " #");
182         }
183         else if (langID == IDM_BENCHMARK2)
184         {
185           LangString_OnlyFromLangFile(IDM_BENCHMARK, newString);
186           if (newString.IsEmpty())
187             continue;
188           newString.Replace(L"&", L"");
189           int tabPos = newString.Find(L"\t");
190           if (tabPos >= 0)
191             newString.DeleteFrom(tabPos);
192           newString += " 2";
193         }
194         else
195           LangString_OnlyFromLangFile(langID, newString);
196 
197         if (newString.IsEmpty())
198           continue;
199 
200         int tabPos = item.StringValue.ReverseFind(L'\t');
201         if (tabPos >= 0)
202           newString += item.StringValue.Ptr(tabPos);
203       }
204 
205       {
206         item.StringValue = newString;
207         item.fMask = Get_fMask_for_String();
208         item.fType = MFT_STRING;
209         menu.SetItem(i, true, item);
210       }
211     }
212   }
213 }
214 
215 static CMenu g_FileMenu;
216 
217 static struct CFileMenuDestroyer
218 {
~CFileMenuDestroyerCFileMenuDestroyer219   ~CFileMenuDestroyer() { if ((HMENU)g_FileMenu != 0) g_FileMenu.Destroy(); }
220 } g_FileMenuDestroyer;
221 
222 
223 static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec);
224 
CopyPopMenu_IfRequired(CMenuItem & item)225 static void CopyPopMenu_IfRequired(CMenuItem &item)
226 {
227   if (item.hSubMenu)
228   {
229     CMenu popup;
230     popup.CreatePopup();
231     CopyMenu(item.hSubMenu, popup);
232     item.hSubMenu = popup;
233   }
234 }
235 
CopyMenu(HMENU srcMenuSpec,HMENU destMenuSpec)236 static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec)
237 {
238   CMenu srcMenu;
239   srcMenu.Attach(srcMenuSpec);
240   CMenu destMenu;
241   destMenu.Attach(destMenuSpec);
242   int startPos = 0;
243   for (int i = 0;; i++)
244   {
245     CMenuItem item;
246     item.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | Get_fMask_for_FType_and_String();
247     item.fType = MFT_STRING;
248 
249     if (!srcMenu.GetItem(i, true, item))
250       break;
251 
252     CopyPopMenu_IfRequired(item);
253     if (destMenu.InsertItem(startPos, true, item))
254       startPos++;
255   }
256 }
257 
MyLoadMenu()258 void MyLoadMenu()
259 {
260   HMENU baseMenu;
261 
262   #ifdef UNDER_CE
263 
264   HMENU oldMenu = g_App._commandBar.GetMenu(0);
265   if (oldMenu)
266     ::DestroyMenu(oldMenu);
267   /* BOOL b = */ g_App._commandBar.InsertMenubar(g_hInstance, IDM_MENU, 0);
268   baseMenu = g_App._commandBar.GetMenu(0);
269   // if (startInit)
270   // SetIdsForSubMenes(baseMenu, 0, 0);
271   if (!g_LangID.IsEmpty())
272     MyChangeMenu(baseMenu, 0, 0);
273   g_App._commandBar.DrawMenuBar(0);
274 
275   #else
276 
277   HWND hWnd = g_HWND;
278   HMENU oldMenu = ::GetMenu(hWnd);
279   ::SetMenu(hWnd, ::LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_MENU)));
280   ::DestroyMenu(oldMenu);
281   baseMenu = ::GetMenu(hWnd);
282   // if (startInit)
283   // SetIdsForSubMenes(baseMenu, 0, 0);
284   if (!g_LangID.IsEmpty())
285     MyChangeMenu(baseMenu, 0, 0);
286   ::DrawMenuBar(hWnd);
287 
288   #endif
289 
290   if ((HMENU)g_FileMenu != 0)
291     g_FileMenu.Destroy();
292   g_FileMenu.CreatePopup();
293   CopyMenu(::GetSubMenu(baseMenu, 0), g_FileMenu);
294 }
295 
OnMenuActivating(HWND,HMENU hMenu,int position)296 void OnMenuActivating(HWND /* hWnd */, HMENU hMenu, int position)
297 {
298   HMENU mainMenu =
299     #ifdef UNDER_CE
300     g_App._commandBar.GetMenu(0);
301     #else
302     ::GetMenu(g_HWND)
303     #endif
304     ;
305 
306   if (::GetSubMenu(mainMenu, position) != hMenu)
307     return;
308 
309   if (position == kMenuIndex_File)
310   {
311     CMenu menu;
312     menu.Attach(hMenu);
313     menu.RemoveAllItems();
314     g_App.GetFocusedPanel().CreateFileMenu(hMenu);
315   }
316   else if (position == kMenuIndex_Edit)
317   {
318     /*
319     CMenu menu;
320     menu.Attach(hMenu);
321     menu.EnableItem(IDM_EDIT_CUT, MF_ENABLED);
322     menu.EnableItem(IDM_EDIT_COPY, MF_ENABLED);
323     menu.EnableItem(IDM_EDIT_PASTE, IsClipboardFormatAvailableHDROP() ? MF_ENABLED : MF_GRAYED);
324     */
325   }
326   else if (position == kMenuIndex_View)
327   {
328     // View;
329     CMenu menu;
330     menu.Attach(hMenu);
331     menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS,
332       IDM_VIEW_LARGE_ICONS + g_App.GetListViewMode(), MF_BYCOMMAND);
333 
334     menu.CheckRadioItem(IDM_VIEW_ARANGE_BY_NAME, IDM_VIEW_ARANGE_NO_SORT,
335         GetSortControlID(g_App.GetSortID()), MF_BYCOMMAND);
336 
337     menu.CheckItemByID(IDM_VIEW_TWO_PANELS, g_App.NumPanels == 2);
338     menu.CheckItemByID(IDM_VIEW_FLAT_VIEW, g_App.GetFlatMode());
339     menu.CheckItemByID(IDM_VIEW_ARCHIVE_TOOLBAR, g_App.ShowArchiveToolbar);
340     menu.CheckItemByID(IDM_VIEW_STANDARD_TOOLBAR, g_App.ShowStandardToolbar);
341     menu.CheckItemByID(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, g_App.LargeButtons);
342     menu.CheckItemByID(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, g_App.ShowButtonsLables);
343     menu.CheckItemByID(IDM_VIEW_AUTO_REFRESH, g_App.Get_AutoRefresh_Mode());
344     // menu.CheckItemByID(IDM_VIEW_SHOW_STREAMS, g_App.Get_ShowNtfsStrems_Mode());
345     // menu.CheckItemByID(IDM_VIEW_SHOW_DELETED, g_App.ShowDeletedFiles);
346 
347     for (int i = 0;; i++)
348     {
349       CMenuItem item;
350       item.fMask = Get_fMask_for_String() | MIIM_SUBMENU | MIIM_ID;
351       item.fType = MFT_STRING;
352       if (!menu.GetItem(i, true, item))
353         break;
354       if (item.hSubMenu && (item.wID == kMenuID_Time_Parent
355           || item.StringValue.IsPrefixedBy_Ascii_NoCase("20")
356           ))
357       {
358         FILETIME ft;
359         NTime::GetCurUtcFileTime(ft);
360 
361         {
362           wchar_t s[64];
363           s[0] = 0;
364           if (ConvertUtcFileTimeToString(ft, s, kTimestampPrintLevel_DAY))
365             item.StringValue = s;
366         }
367 
368         item.fMask = Get_fMask_for_String() | MIIM_ID;
369         item.fType = MFT_STRING;
370         item.wID = kMenuID_Time_Parent;
371         menu.SetItem(i, true, item);
372 
373         CMenu subMenu;
374         subMenu.Attach(menu.GetSubMenu(i));
375         subMenu.RemoveAllItems();
376 
377         const int k_TimeLevels[] =
378         {
379           kTimestampPrintLevel_DAY,
380           kTimestampPrintLevel_MIN,
381           kTimestampPrintLevel_SEC,
382           // 1,2,3,4,5,6,
383           kTimestampPrintLevel_NTFS
384         };
385 
386         unsigned last = kMenuID_Time;
387         unsigned selectedCommand = 0;
388         g_App._timestampLevels.Clear();
389         unsigned id = kMenuID_Time;
390 
391         for (unsigned k = 0; k < ARRAY_SIZE(k_TimeLevels); k++)
392         {
393           wchar_t s[64];
394           s[0] = 0;
395           int timestampLevel = k_TimeLevels[k];
396           if (ConvertUtcFileTimeToString(ft, s, timestampLevel))
397           {
398             if (subMenu.AppendItem(MF_STRING, id, s))
399             {
400               last = id;
401               g_App._timestampLevels.Add(timestampLevel);
402               if (g_App.GetTimestampLevel() == timestampLevel)
403                 selectedCommand = id;
404               id++;
405             }
406           }
407         }
408         if (selectedCommand != 0)
409           menu.CheckRadioItem(kMenuID_Time, last, selectedCommand, MF_BYCOMMAND);
410       }
411     }
412   }
413   else if (position == kMenuIndex_Bookmarks)
414   {
415     CMenu menu;
416     menu.Attach(hMenu);
417 
418     CMenu subMenu;
419     subMenu.Attach(menu.GetSubMenu(0));
420     subMenu.RemoveAllItems();
421     int i;
422 
423     for (i = 0; i < 10; i++)
424     {
425       UString s = LangString(IDS_BOOKMARK);
426       s.Add_Space();
427       char c = (char)(L'0' + i);
428       s += c;
429       s += "\tAlt+Shift+";
430       s += c;
431       subMenu.AppendItem(MF_STRING, kSetBookmarkMenuID + i, s);
432     }
433 
434     menu.RemoveAllItemsFrom(2);
435 
436     for (i = 0; i < 10; i++)
437     {
438       UString s = g_App.AppState.FastFolders.GetString(i);
439       const int kMaxSize = 100;
440       const int kFirstPartSize = kMaxSize / 2;
441       if (s.Len() > kMaxSize)
442       {
443         s.Delete(kFirstPartSize, s.Len() - kMaxSize);
444         s.Insert(kFirstPartSize, L" ... ");
445       }
446       if (s.IsEmpty())
447         s = '-';
448       s += "\tAlt+";
449       s += (char)('0' + i);
450       menu.AppendItem(MF_STRING, kOpenBookmarkMenuID + i, s);
451     }
452   }
453 }
454 
455 /*
456 It doesn't help
457 void OnMenuUnActivating(HWND hWnd, HMENU hMenu, int id)
458 {
459   if (::GetSubMenu(::GetMenu(g_HWND), 0) != hMenu)
460     return;
461 }
462 */
463 
464 static const unsigned g_Zvc_IDs[] =
465 {
466   IDM_VER_EDIT,
467   IDM_VER_COMMIT,
468   IDM_VER_REVERT,
469   IDM_VER_DIFF
470 };
471 
472 static const char * const g_Zvc_Strings[] =
473 {
474     "Ver Edit (&1)"
475   , "Ver Commit"
476   , "Ver Revert"
477   , "Ver Diff (&0)"
478 };
479 
Load(HMENU hMenu,unsigned startPos)480 void CFileMenu::Load(HMENU hMenu, unsigned startPos)
481 {
482   CMenu destMenu;
483   destMenu.Attach(hMenu);
484 
485   UString diffPath;
486   ReadRegDiff(diffPath);
487 
488   unsigned numRealItems = startPos;
489 
490   const bool isBigScreen = NControl::IsDialogSizeOK(40, 200, g_HWND);
491 
492   for (unsigned i = 0;; i++)
493   {
494     CMenuItem item;
495 
496     item.fMask = MIIM_SUBMENU | MIIM_STATE | MIIM_ID | Get_fMask_for_FType_and_String();
497     item.fType = MFT_STRING;
498 
499     if (!g_FileMenu.GetItem(i, true, item))
500       break;
501 
502     {
503       if (!programMenu && item.wID == IDCLOSE)
504         continue;
505 
506       if (item.wID == IDM_DIFF && diffPath.IsEmpty())
507         continue;
508 
509       if (item.wID == IDM_OPEN_INSIDE_ONE || item.wID == IDM_OPEN_INSIDE_PARSER)
510       {
511         // We use diff as "super mode" marker for additional commands.
512         /*
513         if (diffPath.IsEmpty())
514           continue;
515         */
516       }
517 
518       if (item.wID == IDM_BENCHMARK2)
519       {
520         // We use diff as "super mode" marker for additional commands.
521         if (diffPath.IsEmpty())
522           continue;
523       }
524 
525       bool isOneFsFile = (isFsFolder && numItems == 1 && allAreFiles);
526       bool disable = (!isOneFsFile && (item.wID == IDM_SPLIT || item.wID == IDM_COMBINE));
527 
528       if (readOnly)
529       {
530         switch (item.wID)
531         {
532           case IDM_RENAME:
533           case IDM_MOVE_TO:
534           case IDM_DELETE:
535           case IDM_COMMENT:
536           case IDM_CREATE_FOLDER:
537           case IDM_CREATE_FILE:
538             disable = true;
539         }
540       }
541 
542       if (isHashFolder)
543       {
544         switch (item.wID)
545         {
546           case IDM_OPEN:
547           case IDM_OPEN_INSIDE:
548           case IDM_OPEN_INSIDE_ONE:
549           case IDM_OPEN_INSIDE_PARSER:
550           case IDM_OPEN_OUTSIDE:
551           case IDM_FILE_VIEW:
552           case IDM_FILE_EDIT:
553           // case IDM_RENAME:
554           case IDM_COPY_TO:
555           case IDM_MOVE_TO:
556           // case IDM_DELETE:
557           case IDM_COMMENT:
558           case IDM_CREATE_FOLDER:
559           case IDM_CREATE_FILE:
560           case IDM_LINK:
561           case IDM_DIFF:
562             disable = true;
563         }
564       }
565 
566 
567       if (item.wID == IDM_LINK && numItems != 1)
568         disable = true;
569 
570       if (item.wID == IDM_ALT_STREAMS)
571         disable = !isAltStreamsSupported;
572 
573       if (!isBigScreen && (disable || item.IsSeparator()))
574         continue;
575 
576       CopyPopMenu_IfRequired(item);
577       if (destMenu.InsertItem(startPos, true, item))
578       {
579         if (disable)
580           destMenu.EnableItem(startPos, MF_BYPOSITION | MF_GRAYED);
581         startPos++;
582       }
583 
584       if (!item.IsSeparator())
585         numRealItems = startPos;
586     }
587   }
588 
589   UString vercPath;
590   if (!diffPath.IsEmpty() && isFsFolder && allAreFiles && numItems == 1)
591     ReadReg_VerCtrlPath(vercPath);
592 
593   if (!vercPath.IsEmpty())
594   {
595     NFile::NFind::CFileInfo fi;
596     if (fi.Find(FilePath) && fi.Size < ((UInt32)1 << 31) && !fi.IsDir())
597     {
598       for (unsigned k = 0; k < ARRAY_SIZE(g_Zvc_IDs); k++)
599       {
600         const unsigned id = g_Zvc_IDs[k];
601         if (fi.IsReadOnly())
602         {
603           if (id == IDM_VER_COMMIT ||
604               id == IDM_VER_REVERT ||
605               id == IDM_VER_DIFF)
606             continue;
607         }
608         else
609         {
610           if (id == IDM_VER_EDIT)
611             continue;
612         }
613 
614         CMenuItem item;
615         UString s (g_Zvc_Strings[k]);
616         if (destMenu.AppendItem(MF_STRING, id, s))
617         {
618           startPos++;
619           numRealItems = startPos;
620         }
621       }
622     }
623   }
624 
625   destMenu.RemoveAllItemsFrom(numRealItems);
626 }
627 
ExecuteFileCommand(unsigned id)628 bool ExecuteFileCommand(unsigned id)
629 {
630   if (id >= kMenuCmdID_Plugin_Start)
631   {
632     g_App.GetFocusedPanel().InvokePluginCommand(id);
633     g_App.GetFocusedPanel()._sevenZipContextMenu.Release();
634     g_App.GetFocusedPanel()._systemContextMenu.Release();
635     return true;
636   }
637 
638   switch (id)
639   {
640     // File
641     case IDM_OPEN: g_App.OpenItem(); break;
642 
643     case IDM_OPEN_INSIDE:        g_App.OpenItemInside(NULL); break;
644     case IDM_OPEN_INSIDE_ONE:    g_App.OpenItemInside(L"*"); break;
645     case IDM_OPEN_INSIDE_PARSER: g_App.OpenItemInside(L"#"); break;
646 
647     case IDM_OPEN_OUTSIDE: g_App.OpenItemOutside(); break;
648     case IDM_FILE_VIEW: g_App.EditItem(false); break;
649     case IDM_FILE_EDIT: g_App.EditItem(true); break;
650     case IDM_RENAME: g_App.Rename(); break;
651     case IDM_COPY_TO: g_App.CopyTo(); break;
652     case IDM_MOVE_TO: g_App.MoveTo(); break;
653     case IDM_DELETE: g_App.Delete(!IsKeyDown(VK_SHIFT)); break;
654 
655     case IDM_HASH_ALL: g_App.CalculateCrc("*"); break;
656     case IDM_CRC32: g_App.CalculateCrc("CRC32"); break;
657     case IDM_CRC64: g_App.CalculateCrc("CRC64"); break;
658     case IDM_SHA1: g_App.CalculateCrc("SHA1"); break;
659     case IDM_SHA256: g_App.CalculateCrc("SHA256"); break;
660 
661     case IDM_DIFF: g_App.DiffFiles(); break;
662 
663     case IDM_VER_EDIT:
664     case IDM_VER_COMMIT:
665     case IDM_VER_REVERT:
666     case IDM_VER_DIFF:
667         g_App.VerCtrl(id); break;
668 
669     case IDM_SPLIT: g_App.Split(); break;
670     case IDM_COMBINE: g_App.Combine(); break;
671     case IDM_PROPERTIES: g_App.Properties(); break;
672     case IDM_COMMENT: g_App.Comment(); break;
673     case IDM_CREATE_FOLDER: g_App.CreateFolder(); break;
674     case IDM_CREATE_FILE: g_App.CreateFile(); break;
675     #ifndef UNDER_CE
676     case IDM_LINK: g_App.Link(); break;
677     case IDM_ALT_STREAMS: g_App.OpenAltStreams(); break;
678     #endif
679     default: return false;
680   }
681   return true;
682 }
683 
MyBenchmark(bool totalMode)684 static void MyBenchmark(bool totalMode)
685 {
686   CPanel::CDisableTimerProcessing disableTimerProcessing1(g_App.Panels[0]);
687   CPanel::CDisableTimerProcessing disableTimerProcessing2(g_App.Panels[1]);
688   Benchmark(totalMode);
689 }
690 
OnMenuCommand(HWND hWnd,unsigned id)691 bool OnMenuCommand(HWND hWnd, unsigned id)
692 {
693   if (ExecuteFileCommand(id))
694     return true;
695 
696   switch (id)
697   {
698     // File
699     case IDCLOSE:
700       SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
701       g_ExitEventLauncher.Exit(false);
702       SendMessage(hWnd, WM_CLOSE, 0, 0);
703       break;
704 
705     // Edit
706     /*
707     case IDM_EDIT_CUT:
708       g_App.EditCut();
709       break;
710     case IDM_EDIT_COPY:
711       g_App.EditCopy();
712       break;
713     case IDM_EDIT_PASTE:
714       g_App.EditPaste();
715       break;
716     */
717     case IDM_SELECT_ALL:
718       g_App.SelectAll(true);
719       g_App.Refresh_StatusBar();
720       break;
721     case IDM_DESELECT_ALL:
722       g_App.SelectAll(false);
723       g_App.Refresh_StatusBar();
724       break;
725     case IDM_INVERT_SELECTION:
726       g_App.InvertSelection();
727       g_App.Refresh_StatusBar();
728       break;
729     case IDM_SELECT:
730       g_App.SelectSpec(true);
731       g_App.Refresh_StatusBar();
732       break;
733     case IDM_DESELECT:
734       g_App.SelectSpec(false);
735       g_App.Refresh_StatusBar();
736       break;
737     case IDM_SELECT_BY_TYPE:
738       g_App.SelectByType(true);
739       g_App.Refresh_StatusBar();
740       break;
741     case IDM_DESELECT_BY_TYPE:
742       g_App.SelectByType(false);
743       g_App.Refresh_StatusBar();
744       break;
745 
746     //View
747     case IDM_VIEW_LARGE_ICONS:
748     case IDM_VIEW_SMALL_ICONS:
749     case IDM_VIEW_LIST:
750     case IDM_VIEW_DETAILS:
751     {
752       UINT index = id - IDM_VIEW_LARGE_ICONS;
753       if (index < 4)
754       {
755         g_App.SetListViewMode(index);
756         /*
757         CMenu menu;
758         menu.Attach(::GetSubMenu(::GetMenu(hWnd), kMenuIndex_View));
759         menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS,
760             id, MF_BYCOMMAND);
761         */
762       }
763       break;
764     }
765     case IDM_VIEW_ARANGE_BY_NAME: g_App.SortItemsWithPropID(kpidName); break;
766     case IDM_VIEW_ARANGE_BY_TYPE: g_App.SortItemsWithPropID(kpidExtension); break;
767     case IDM_VIEW_ARANGE_BY_DATE: g_App.SortItemsWithPropID(kpidMTime); break;
768     case IDM_VIEW_ARANGE_BY_SIZE: g_App.SortItemsWithPropID(kpidSize); break;
769     case IDM_VIEW_ARANGE_NO_SORT: g_App.SortItemsWithPropID(kpidNoProperty); break;
770 
771     case IDM_OPEN_ROOT_FOLDER:    g_App.OpenRootFolder(); break;
772     case IDM_OPEN_PARENT_FOLDER:  g_App.OpenParentFolder(); break;
773     case IDM_FOLDERS_HISTORY:     g_App.FoldersHistory(); break;
774     case IDM_VIEW_FLAT_VIEW:      g_App.ChangeFlatMode(); break;
775     case IDM_VIEW_REFRESH:        g_App.RefreshView(); break;
776     case IDM_VIEW_AUTO_REFRESH:   g_App.Change_AutoRefresh_Mode(); break;
777 
778     // case IDM_VIEW_SHOW_STREAMS:     g_App.Change_ShowNtfsStrems_Mode(); break;
779     /*
780     case IDM_VIEW_SHOW_DELETED:
781     {
782       g_App.Change_ShowDeleted();
783       bool isChecked = g_App.ShowDeletedFiles;
784       Save_ShowDeleted(isChecked);
785     }
786     */
787 
788     case IDM_VIEW_TWO_PANELS:       g_App.SwitchOnOffOnePanel(); break;
789     case IDM_VIEW_STANDARD_TOOLBAR: g_App.SwitchStandardToolbar(); break;
790     case IDM_VIEW_ARCHIVE_TOOLBAR:  g_App.SwitchArchiveToolbar(); break;
791 
792     case IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT: g_App.SwitchButtonsLables(); break;
793     case IDM_VIEW_TOOLBARS_LARGE_BUTTONS:     g_App.SwitchLargeButtons(); break;
794 
795     // Tools
796     case IDM_OPTIONS: OptionsDialog(hWnd, g_hInstance); break;
797 
798     case IDM_BENCHMARK: MyBenchmark(false); break;
799     case IDM_BENCHMARK2: MyBenchmark(true); break;
800 
801     // Help
802     case IDM_HELP_CONTENTS:
803       ShowHelpWindow(kFMHelpTopic);
804       break;
805     case IDM_ABOUT:
806     {
807       CAboutDialog dialog;
808       dialog.Create(hWnd);
809       break;
810     }
811     default:
812     {
813       if (id >= kOpenBookmarkMenuID && id <= kOpenBookmarkMenuID + 9)
814       {
815         g_App.OpenBookmark(id - kOpenBookmarkMenuID);
816         return true;
817       }
818       else if (id >= kSetBookmarkMenuID && id <= kSetBookmarkMenuID + 9)
819       {
820         g_App.SetBookmark(id - kSetBookmarkMenuID);
821         return true;
822       }
823       else if (id >= kMenuID_Time && (unsigned)id <= kMenuID_Time + g_App._timestampLevels.Size())
824       {
825         unsigned index = id - kMenuID_Time;
826         g_App.SetTimestampLevel(g_App._timestampLevels[index]);
827         return true;
828       }
829       return false;
830     }
831   }
832   return true;
833 }
834