Skip to content

Commit

Permalink
sort the tab list popup shown from the button in the tab bar not alph…
Browse files Browse the repository at this point in the history
…abetically but by tab index

closes #371
  • Loading branch information
stefankueng committed Apr 29, 2024
1 parent 8ae410b commit c60c02e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
31 changes: 21 additions & 10 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<std::wstring, int, ci_lessW> tablist;
std::map<int, std::wstring> 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)
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1561,7 +1572,7 @@ LRESULT CMainWindow::DoCommand(WPARAM wParam, LPARAM lParam)
PasteHistory();
break;
case cmdTabListDropdownMenu:
ShowTablistDropdown(reinterpret_cast<HWND>(lParam), 0, 0);
ShowTablistDropdown(reinterpret_cast<HWND>(lParam), 0, 0, true);
break;
case cmdAbout:
About();
Expand Down
4 changes: 2 additions & 2 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CMainWindow : public CWindow

public:
CMainWindow(HINSTANCE hInst, const WNDCLASSEX* wcx = nullptr);
virtual ~CMainWindow();
~CMainWindow() override;

bool RegisterAndCreateWindow();
bool Initialize();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c60c02e

Please sign in to comment.