OSDN Git Service

BrowseRefs: Sorting: Also backward sorting
authorJohan 't Hart <johanthart@gmail.com>
Sun, 24 May 2009 13:42:07 +0000 (15:42 +0200)
committerFrank Li <lznuaa@gmail.com>
Mon, 25 May 2009 07:04:31 +0000 (15:04 +0800)
src/TortoiseProc/BrowseRefsDlg.cpp
src/TortoiseProc/BrowseRefsDlg.h

index 0727ae2..8e80a4c 100644 (file)
@@ -17,7 +17,9 @@ IMPLEMENT_DYNAMIC(CBrowseRefsDlg, CResizableStandAloneDialog)
 \r
 CBrowseRefsDlg::CBrowseRefsDlg(CString cmdPath, CWnd* pParent /*=NULL*/)\r
 :      CResizableStandAloneDialog(CBrowseRefsDlg::IDD, pParent),\r
-       m_cmdPath(cmdPath)\r
+       m_cmdPath(cmdPath),\r
+       m_currSortCol(-1),\r
+       m_currSortDesc(false)\r
 {\r
 \r
 }\r
@@ -535,7 +537,7 @@ BOOL CBrowseRefsDlg::PreTranslateMessage(MSG* pMsg)
 class CRefLeafListCompareFunc\r
 {\r
 public:\r
-       CRefLeafListCompareFunc(CListCtrl* pList, int col):m_col(col),m_pList(pList){}\r
+       CRefLeafListCompareFunc(CListCtrl* pList, int col, bool desc):m_col(col),m_desc(desc),m_pList(pList){}\r
 \r
        static int CALLBACK StaticCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)\r
        {\r
@@ -551,21 +553,26 @@ public:
 \r
        int Compare(CShadowTree* pLeft, CShadowTree* pRight)\r
        {\r
+               int result=CompareNoDesc(pLeft,pRight);\r
+               if(m_desc)\r
+                       return -result;\r
+               return result;\r
+       }\r
+\r
+       int CompareNoDesc(CShadowTree* pLeft, CShadowTree* pRight)\r
+       {\r
                switch(m_col)\r
                {\r
                case CBrowseRefsDlg::eCol_Name: return pLeft->GetRefName().CompareNoCase(pRight->GetRefName());\r
-                       break;\r
                case CBrowseRefsDlg::eCol_Date: return pLeft->m_csDate_Iso8601.CompareNoCase(pRight->m_csDate_Iso8601);\r
-                       break;\r
                case CBrowseRefsDlg::eCol_Msg:  return pLeft->m_csSubject.CompareNoCase(pRight->m_csSubject);\r
-                       break;\r
                case CBrowseRefsDlg::eCol_Hash: return pLeft->m_csRefHash.CompareNoCase(pRight->m_csRefHash);\r
-                       break;\r
                }\r
                return 0;\r
        }\r
 \r
        int m_col;\r
+       bool m_desc;\r
        CListCtrl* m_pList;\r
 \r
 \r
@@ -576,6 +583,14 @@ void CBrowseRefsDlg::OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResul
        LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
        *pResult = 0;\r
 \r
-       CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs,pNMLV->iSubItem);\r
+       if(m_currSortCol == pNMLV->iSubItem)\r
+               m_currSortDesc = !m_currSortDesc;\r
+       else\r
+       {\r
+               m_currSortCol  = pNMLV->iSubItem;\r
+               m_currSortDesc = false;\r
+       }\r
+\r
+       CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs, m_currSortCol, m_currSortDesc);\r
        m_ListRefLeafs.SortItemsEx(&CRefLeafListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc);\r
 }\r
index 98f4fac..1f85df2 100644 (file)
@@ -97,6 +97,9 @@ private:
        CShadowTree             m_TreeRoot;\r
        CTreeCtrl               m_RefTreeCtrl;\r
        CListCtrl               m_ListRefLeafs;\r
+\r
+       int                             m_currSortCol;\r
+       bool                    m_currSortDesc;\r
        afx_msg void OnTvnSelchangedTreeRef(NMHDR *pNMHDR, LRESULT *pResult);\r
 public:\r
 \r