OSDN Git Service

BrowseRefs: Sorting: Show sorting state in column header
authorJohan 't Hart <johanthart@gmail.com>
Sun, 24 May 2009 21:29:05 +0000 (23:29 +0200)
committerFrank Li <lznuaa@gmail.com>
Mon, 25 May 2009 07:04:32 +0000 (15:04 +0800)
src/TortoiseProc/BrowseRefsDlg.cpp

index 8e80a4c..7a02aae 100644 (file)
 #include "SinglePropSheetDlg.h"\r
 #include "MessageBox.h"\r
 \r
+void SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)\r
+{\r
+       if (control == NULL)\r
+               return;\r
+       // set the sort arrow\r
+       CHeaderCtrl * pHeader = control->GetHeaderCtrl();\r
+       HDITEM HeaderItem = {0};\r
+       HeaderItem.mask = HDI_FORMAT;\r
+       for (int i=0; i<pHeader->GetItemCount(); ++i)\r
+       {\r
+               pHeader->GetItem(i, &HeaderItem);\r
+               HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);\r
+               pHeader->SetItem(i, &HeaderItem);\r
+       }\r
+       if (nColumn >= 0)\r
+       {\r
+               pHeader->GetItem(nColumn, &HeaderItem);\r
+               HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);\r
+               pHeader->SetItem(nColumn, &HeaderItem);\r
+       }\r
+}\r
+\r
 // CBrowseRefsDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CBrowseRefsDlg, CResizableStandAloneDialog)\r
@@ -271,6 +293,9 @@ void CBrowseRefsDlg::OnTvnSelchangedTreeRef(NMHDR *pNMHDR, LRESULT *pResult)
 void CBrowseRefsDlg::FillListCtrlForTreeNode(HTREEITEM treeNode)\r
 {\r
        m_ListRefLeafs.DeleteAllItems();\r
+       m_currSortCol = -1;\r
+       m_currSortDesc = false;\r
+       SetSortArrow(&m_ListRefLeafs,-1,false);\r
 \r
        CShadowTree* pTree=(CShadowTree*)(m_RefTreeCtrl.GetItemData(treeNode));\r
        if(pTree==NULL)\r
@@ -578,6 +603,7 @@ public:
 \r
 };\r
 \r
+\r
 void CBrowseRefsDlg::OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult)\r
 {\r
        LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
@@ -593,4 +619,7 @@ void CBrowseRefsDlg::OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResul
 \r
        CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs, m_currSortCol, m_currSortDesc);\r
        m_ListRefLeafs.SortItemsEx(&CRefLeafListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc);\r
+\r
+       SetSortArrow(&m_ListRefLeafs,m_currSortCol,!m_currSortDesc);\r
 }\r
+\r