From c60c02ebaaf53b55ead88517f03a0416cee823ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCng?= Date: Mon, 29 Apr 2024 19:53:43 +0200 Subject: [PATCH] sort the tab list popup shown from the button in the tab bar not alphabetically but by tab index closes #371 --- src/MainWindow.cpp | 31 +++++++++++++++++++++---------- src/MainWindow.h | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d52b539b..8b26814d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1110,7 +1110,7 @@ LRESULT CMainWindow::HandleTabBarEvents(const NMHDR& nmHdr, WPARAM /*wParam*/, L return 0; } -void CMainWindow::ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY) +void CMainWindow::ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY, bool sortByTab) { if (hWnd) { @@ -1128,9 +1128,10 @@ void CMainWindow::ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY) prepList.insert(std::make_pair(m_tabBar.GetTitle(i), i)); } std::multimap tablist; + std::map tablistTab; for (auto& [tabTitle, tabIndex] : prepList) { - auto count = std::count_if(prepList.begin(), prepList.end(), [&](const auto& item) -> bool { + auto count = std::ranges::count_if(prepList, [&](const auto& item) -> bool { return item.first == tabTitle; }); if (count > 1) @@ -1142,17 +1143,27 @@ void CMainWindow::ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY) tabTitle.c_str(), pathBuf); tablist.insert(std::make_pair(text, tabIndex + 1)); + tablistTab[tabIndex + 1] = text; } else + { tablist.insert(std::make_pair(tabTitle, tabIndex + 1)); + tablistTab[tabIndex + 1] = tabTitle; + } } - - for (auto& [tabTitle, tabIndex] : tablist) + if (sortByTab) { - if (tabIndex == (currentIndex + 1)) - AppendMenu(hMenu, MF_STRING | MF_CHECKED, tabIndex, tabTitle.c_str()); - else - AppendMenu(hMenu, MF_STRING, tabIndex, tabTitle.c_str()); + for (auto& [tabIndex, tabTitle] : tablistTab) + { + AppendMenu(hMenu, tabIndex == (currentIndex + 1) ? MF_STRING | MF_CHECKED : MF_STRING, tabIndex, tabTitle.c_str()); + } + } + else + { + for (auto& [tabTitle, tabIndex] : tablist) + { + AppendMenu(hMenu, tabIndex == (currentIndex + 1) ? MF_STRING | MF_CHECKED : MF_STRING, tabIndex, tabTitle.c_str()); + } } TPMPARAMS tpm{}; tpm.cbSize = sizeof(TPMPARAMS); @@ -1379,7 +1390,7 @@ void CMainWindow::HandleStatusBar(WPARAM wParam, LPARAM lParam) auto pos = GetMessagePos(); POINT pt = {GET_X_LPARAM(pos), GET_Y_LPARAM(pos)}; ScreenToClient(m_statusBar, &pt); - ShowTablistDropdown(m_statusBar, pt.x, pt.y); + ShowTablistDropdown(m_statusBar, pt.x, pt.y, false); } break; default: @@ -1561,7 +1572,7 @@ LRESULT CMainWindow::DoCommand(WPARAM wParam, LPARAM lParam) PasteHistory(); break; case cmdTabListDropdownMenu: - ShowTablistDropdown(reinterpret_cast(lParam), 0, 0); + ShowTablistDropdown(reinterpret_cast(lParam), 0, 0, true); break; case cmdAbout: About(); diff --git a/src/MainWindow.h b/src/MainWindow.h index d283b3ba..4cf702c9 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -69,7 +69,7 @@ class CMainWindow : public CWindow public: CMainWindow(HINSTANCE hInst, const WNDCLASSEX* wcx = nullptr); - virtual ~CMainWindow(); + ~CMainWindow() override; bool RegisterAndCreateWindow(); bool Initialize(); @@ -191,7 +191,7 @@ class CMainWindow : public CWindow LRESULT HandleEditorEvents(const NMHDR& nmHdr, WPARAM wParam, LPARAM lParam); LRESULT HandleFileTreeEvents(const NMHDR& nmHdr, WPARAM wParam, LPARAM lParam); LRESULT HandleTabBarEvents(const NMHDR& nmHdr, WPARAM wParam, LPARAM lParam); - void ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY); + void ShowTablistDropdown(HWND hWnd, int offsetX, int offsetY, bool sortByTab); int GetZoomPC() const; std::wstring GetZoomPC(int zoom) const; void SetZoomPC(int zoomPC) const;