Skip to content

Commit

Permalink
Main Menu toggle Show/Hide (#2509)
Browse files Browse the repository at this point in the history
* Main Menu toggle Show/Hide

* Temporarily display the main menu when Alt or F10 is pressed

* Remove toggle main menu shortcut
  • Loading branch information
lededev authored Nov 8, 2024
1 parent 7ef24b1 commit 8cb4c33
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
72 changes: 71 additions & 1 deletion Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_ACTIVATEAPP()
ON_WM_NCCALCSIZE()
ON_WM_SIZE()
ON_WM_SYSCOMMAND()
ON_WM_ENTERMENULOOP()
ON_WM_EXITMENULOOP()
ON_UPDATE_COMMAND_UI_RANGE(CMenuBar::FIRST_MENUID, CMenuBar::FIRST_MENUID + 10, OnUpdateMenuBarMenuItem)
// [File] menu
ON_COMMAND(ID_FILE_NEW, (OnFileNew<2, ID_MERGE_COMPARE_TEXT>))
Expand Down Expand Up @@ -322,6 +325,9 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_MESSAGE(WMU_CHILDFRAMEREMOVED, &CMainFrame::OnChildFrameRemoved)
ON_MESSAGE(WMU_CHILDFRAMEACTIVATE, &CMainFrame::OnChildFrameActivate)
ON_MESSAGE(WMU_CHILDFRAMEACTIVATED, &CMainFrame::OnChildFrameActivated)
// Main menu toggle switch
ON_COMMAND(ID_VIEW_MAIN_MENU, OnToggleMainMenu)
ON_UPDATE_COMMAND_UI(ID_VIEW_MAIN_MENU, OnUpdateToggleMainMenu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand Down Expand Up @@ -462,6 +468,8 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

m_wndMDIClient.ModifyStyleEx(WS_EX_CLIENTEDGE, 0);

UpdateSystemMenu();

return 0;
}

Expand Down Expand Up @@ -2612,7 +2620,10 @@ BOOL CMainFrame::CreateToolbar()
__super::ShowControlBar(&m_wndToolBar, false, 0);
}

__super::ShowControlBar(&m_wndMenuBar, true, 0);
if (GetOptionsMgr()->GetBool(OPT_HIDE_MAINMENU))
{
__super::ShowControlBar(&m_wndMenuBar, false, 0);
}

m_wndReBar.LoadStateFromString(GetOptionsMgr()->GetString(OPT_REBAR_STATE).c_str());

Expand Down Expand Up @@ -3716,3 +3727,62 @@ LRESULT CMainFrame::OnChildFrameActivated(WPARAM wParam, LPARAM lParam)

return 1;
}

void CMainFrame::OnToggleMainMenu()
{
const bool bMenuVisible = static_cast<bool>(m_wndMenuBar.IsVisible());
__super::ShowControlBar(&m_wndMenuBar, !bMenuVisible, 0);
GetOptionsMgr()->SaveOption(OPT_HIDE_MAINMENU, bMenuVisible);
UpdateSystemMenu();
}

void CMainFrame::OnUpdateToggleMainMenu(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(!GetOptionsMgr()->GetBool(OPT_HIDE_MAINMENU));
}

void CMainFrame::UpdateSystemMenu()
{
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu == nullptr)
return;
BOOL bChecked = !GetOptionsMgr()->GetBool(OPT_HIDE_MAINMENU);
const int cnt = pSysMenu->GetMenuItemCount();
for (int i = 0; i < cnt; ++i)
if (pSysMenu->GetMenuItemID(i) == ID_SHOW_MAIN_MENU)
{
pSysMenu->CheckMenuItem(i, MF_BYPOSITION | (bChecked ? MF_CHECKED : MF_UNCHECKED));
return; // Add only once
}
String menuTxt = theApp.LoadString(static_cast<UINT>(IDS_SHOW_MAIN_MENU));
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, ID_SHOW_MAIN_MENU, menuTxt.c_str());
pSysMenu->CheckMenuItem(ID_SHOW_MAIN_MENU, MF_BYCOMMAND | (bChecked ? MF_CHECKED : MF_UNCHECKED));
}

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if (nID == ID_SHOW_MAIN_MENU) {
OnToggleMainMenu();
return;
}
__super::OnSysCommand(nID, lParam);
}

void CMainFrame::OnEnterMenuLoop(BOOL bMainMenu)
{
__super::OnEnterMenuLoop(bMainMenu);
if (!bMainMenu)
return;
if (GetOptionsMgr()->GetBool(OPT_HIDE_MAINMENU) && !m_wndMenuBar.IsVisible())
__super::ShowControlBar(&m_wndMenuBar, true, 0);
}

void CMainFrame::OnExitMenuLoop(BOOL bMainMenu)
{
__super::OnExitMenuLoop(bMainMenu);
if (!bMainMenu)
return;
if (GetOptionsMgr()->GetBool(OPT_HIDE_MAINMENU) && m_wndMenuBar.IsVisible())
__super::ShowControlBar(&m_wndMenuBar, false, 0);
}
6 changes: 6 additions & 0 deletions Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ class CMainFrame : public CMDIFrameWnd
afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
afx_msg void OnUpdateMenuBarMenuItem(CCmdUI* pCmdUI);
afx_msg void OnToggleMainMenu();
afx_msg void OnUpdateToggleMainMenu(CCmdUI* pCmdUI);
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnEnterMenuLoop(BOOL bMainMenu);
afx_msg void OnExitMenuLoop(BOOL bMainMenu);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand All @@ -452,6 +457,7 @@ class CMainFrame : public CMDIFrameWnd
void LoadToolbarImages();
HMENU NewMenu( int view, int ID );
bool CompareFilesIfFilesAreLarge(IDirDoc* pDirDoc, int nFiles, const FileLocation ifileloc[]);
void UpdateSystemMenu();
std::unique_ptr<WCHAR[]> m_upszLongTextW;
std::unique_ptr<CHAR[]> m_upszLongTextA;
};
2 changes: 2 additions & 0 deletions Src/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ void CMenuBar::OnSetFocus(CWnd* pOldWnd)
m_bActive = true;
m_hwndOldFocus = pOldWnd->m_hWnd;
__super::OnSetFocus(pOldWnd);
::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WM_ENTERMENULOOP, 1, 0);
}

void CMenuBar::OnKillFocus(CWnd* pNewWnd)
{
LoseFocus();
__super::OnKillFocus(pNewWnd);
::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WM_EXITMENULOOP, 1, 0);
}

void CMenuBar::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
Expand Down
8 changes: 8 additions & 0 deletions Src/Merge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ BEGIN
MENUITEM "&Big", ID_TOOLBAR_BIG
MENUITEM "&Huge", ID_TOOLBAR_HUGE
END
MENUITEM "Main Men&u", ID_VIEW_MAIN_MENU
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
END
POPUP "&Tools"
Expand Down Expand Up @@ -507,6 +508,7 @@ BEGIN
MENUITEM "&Big", ID_TOOLBAR_BIG
MENUITEM "&Huge", ID_TOOLBAR_HUGE
END
MENUITEM "Main Men&u", ID_VIEW_MAIN_MENU
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
MENUITEM SEPARATOR
MENUITEM "Com&pare Statistics...", ID_VIEW_DIR_STATISTICS
Expand Down Expand Up @@ -748,6 +750,7 @@ BEGIN
MENUITEM "&Big", ID_TOOLBAR_BIG
MENUITEM "&Huge", ID_TOOLBAR_HUGE
END
MENUITEM "Main Men&u", ID_VIEW_MAIN_MENU
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
MENUITEM "Diff &Pane", ID_VIEW_DETAIL_BAR
MENUITEM "Lo&cation Pane", ID_VIEW_LOCATION_BAR
Expand Down Expand Up @@ -4572,6 +4575,11 @@ BEGIN
ID_MICE_R2LNEXT "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
END

STRINGTABLE
BEGIN
IDS_SHOW_MAIN_MENU "Main Men&u"
END

#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions Src/OptionsDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ inline const String OPT_SHOW_MISSING_LEFT_ONLY {_T("Settings/ShowMissingLeftOnly
inline const String OPT_SHOW_MISSING_MIDDLE_ONLY {_T("Settings/ShowMissingMiddleOnly"s)};
inline const String OPT_SHOW_MISSING_RIGHT_ONLY {_T("Settings/ShowMissingRightOnly"s)};
inline const String OPT_TREE_MODE {_T("Settings/TreeMode"s)};
inline const String OPT_HIDE_MAINMENU {_T("Settings/HideMainMenu"s)};

// Show/hide toolbar/statusbar/tabbar
inline const String OPT_SHOW_TOOLBAR {_T("Settings/ShowToolbar"s)};
Expand Down
1 change: 1 addition & 0 deletions Src/OptionsInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void Init(COptionsMgr *pOptions)
pOptions->InitOption(OPT_SHOW_MISSING_LEFT_ONLY, true);
pOptions->InitOption(OPT_SHOW_MISSING_MIDDLE_ONLY, true);
pOptions->InitOption(OPT_SHOW_MISSING_RIGHT_ONLY, true);
pOptions->InitOption(OPT_HIDE_MAINMENU, false);

pOptions->InitOption(OPT_SHOW_TOOLBAR, true);
pOptions->InitOption(OPT_SHOW_STATUSBAR, true);
Expand Down
3 changes: 3 additions & 0 deletions Src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@
#define ID_SEL_DIFF_COPY_2ND_3WAY 33274
#define ID_MICE_L2RNEXT 33275
#define ID_MICE_R2LNEXT 33276
#define ID_VIEW_MAIN_MENU 33277
#define ID_SHOW_MAIN_MENU 33278
#define IDS_SHOW_MAIN_MENU 33279
#define ID_TABBAR_AUTO_MAXWIDTH 33351
#define ID_IMG_VIEWDIFFERENCES 33353
#define ID_IMG_ZOOM_25 33354
Expand Down

0 comments on commit 8cb4c33

Please sign in to comment.