diff options
author | George Hazan <george.hazan@gmail.com> | 2023-12-18 16:40:06 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-12-18 16:40:06 +0300 |
commit | 8d085456281fcf540c79e24b06cb8f9148f1c44a (patch) | |
tree | 95abbfdeef9311fd44864a1942ca362b9a691c9d /protocols/IRCG/src/channelList.cpp | |
parent | 3c06454f9c477704520939e233a483e94e3bc525 (diff) |
fixes #4065 (IRC: Mode header sorting channel by number of users)
Diffstat (limited to 'protocols/IRCG/src/channelList.cpp')
-rw-r--r-- | protocols/IRCG/src/channelList.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/protocols/IRCG/src/channelList.cpp b/protocols/IRCG/src/channelList.cpp index bac7b3e0bc..d2d7ac8237 100644 --- a/protocols/IRCG/src/channelList.cpp +++ b/protocols/IRCG/src/channelList.cpp @@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. struct ListViewSortParam { CCtrlListView *pList; - int iSubItem; + int iSubItem, iSortOrder; }; static int CALLBACK ListViewSort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) @@ -29,32 +29,33 @@ static int CALLBACK ListViewSort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSo if (!param->pList->GetHwnd()) return 0; - wchar_t temp1[512]; - wchar_t temp2[512]; LVITEM lvm; lvm.mask = LVIF_TEXT; - lvm.iItem = lParam1; lvm.iSubItem = param->iSubItem; + + wchar_t temp1[512]; + lvm.iItem = lParam1; lvm.pszText = temp1; lvm.cchTextMax = _countof(temp1); param->pList->GetItem(&lvm); + + wchar_t temp2[512]; lvm.iItem = lParam2; lvm.pszText = temp2; param->pList->GetItem(&lvm); - if (param->iSubItem != 1) { - if (mir_wstrlen(temp1) != 0 && mir_wstrlen(temp2) != 0) - return mir_wstrcmpi(temp1, temp2); + + if (param->iSubItem != 1) + return mir_wstrcmpi(temp1, temp2) * param->iSortOrder; - return (*temp1 == 0) ? 1 : -1; - } - - return (_wtoi(temp1) < _wtoi(temp2)) ? 1 : -1; + int res = (_wtoi(temp1) < _wtoi(temp2)) ? 1 : -1; + return res * param->iSortOrder; } ///////////////////////////////////////////////////////////////////////////////////////// class CListDlg : public CIrcBaseDlg { + int iPrevCol = -1, iPrevSort = 1; CTimer m_timer; CCtrlButton m_Join; CCtrlEdit m_filter, m_status; @@ -247,6 +248,12 @@ public: void onColumnClick_List(CCtrlListView::TEventInfo *ev) { ListViewSortParam param = { &m_list, ev->nmlv->iSubItem }; + if (param.iSubItem != iPrevCol) { + param.iSortOrder = iPrevSort = 1; + iPrevCol = param.iSubItem; + } + else param.iSortOrder = iPrevSort = iPrevSort * -1; + m_list.SortItems(ListViewSort, (LPARAM)¶m); UpdateList(); } |