OSDN Git Service

BrowseRefs: Started with refs list sorting
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BrowseRefsDlg.cpp
index 051de43..0727ae2 100644 (file)
@@ -38,6 +38,7 @@ BEGIN_MESSAGE_MAP(CBrowseRefsDlg, CResizableStandAloneDialog)
        ON_BN_CLICKED(IDOK, &CBrowseRefsDlg::OnBnClickedOk)\r
        ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_REF, &CBrowseRefsDlg::OnTvnSelchangedTreeRef)\r
        ON_WM_CONTEXTMENU()\r
+       ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_REF_LEAFS, &CBrowseRefsDlg::OnLvnColumnclickListRefLeafs)\r
 END_MESSAGE_MAP()\r
 \r
 \r
@@ -56,10 +57,10 @@ BOOL CBrowseRefsDlg::OnInitDialog()
        AddAnchor(IDC_LIST_REF_LEAFS, TOP_LEFT, BOTTOM_RIGHT);\r
 \r
        m_ListRefLeafs.SetExtendedStyle(m_ListRefLeafs.GetExtendedStyle()|LVS_EX_FULLROWSELECT);\r
-       m_ListRefLeafs.InsertColumn(0,L"Name",0,150);\r
-       m_ListRefLeafs.InsertColumn(1,L"Date Last Commit",0,100);\r
-       m_ListRefLeafs.InsertColumn(2,L"Last Commit",0,300);\r
-       m_ListRefLeafs.InsertColumn(3,L"Hash",0,80);\r
+       m_ListRefLeafs.InsertColumn(eCol_Name,  L"Name",0,150);\r
+       m_ListRefLeafs.InsertColumn(eCol_Date,  L"Date Last Commit",0,100);\r
+       m_ListRefLeafs.InsertColumn(eCol_Msg,   L"Last Commit",0,300);\r
+       m_ListRefLeafs.InsertColumn(eCol_Hash,  L"Hash",0,80);\r
 \r
        AddAnchor(IDOK,BOTTOM_RIGHT);\r
        AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
@@ -145,7 +146,8 @@ void CBrowseRefsDlg::Refresh(bool bSelectCurHead)
                          L"%(objectname)%04"\r
                          L"%(authordate:relative)%04"\r
                          L"%(subject)%04"\r
-                         L"%(authorname)",\r
+                         L"%(authorname)%04"\r
+                         L"%(authordate:iso8601)",\r
                          &allRefs,CP_UTF8);\r
 \r
        int linePos=0;\r
@@ -175,10 +177,11 @@ void CBrowseRefsDlg::Refresh(bool bSelectCurHead)
                CString values=iterRefMap->second;\r
 \r
                int valuePos=0;\r
-               treeLeaf.m_csRefHash= values.Tokenize(L"\04",valuePos);\r
-               treeLeaf.m_csDate=    values.Tokenize(L"\04",valuePos);\r
-               treeLeaf.m_csSubject= values.Tokenize(L"\04",valuePos);\r
-               treeLeaf.m_csAuthor=  values.Tokenize(L"\04",valuePos);\r
+               treeLeaf.m_csRefHash=           values.Tokenize(L"\04",valuePos);\r
+               treeLeaf.m_csDate=                      values.Tokenize(L"\04",valuePos);\r
+               treeLeaf.m_csSubject=           values.Tokenize(L"\04",valuePos);\r
+               treeLeaf.m_csAuthor=            values.Tokenize(L"\04",valuePos);\r
+               treeLeaf.m_csDate_Iso8601=      values.Tokenize(L"\04",valuePos);\r
        }\r
 \r
 \r
@@ -283,10 +286,10 @@ void CBrowseRefsDlg::FillListCtrlForShadowTree(CShadowTree* pTree, CString refNa
                int indexItem=m_ListRefLeafs.InsertItem(m_ListRefLeafs.GetItemCount(),L"");\r
 \r
                m_ListRefLeafs.SetItemData(indexItem,(DWORD_PTR)pTree);\r
-               m_ListRefLeafs.SetItemText(indexItem,0,refNamePrefix+pTree->m_csRefName);\r
-               m_ListRefLeafs.SetItemText(indexItem,1,pTree->m_csDate);\r
-               m_ListRefLeafs.SetItemText(indexItem,2,pTree->m_csSubject);\r
-               m_ListRefLeafs.SetItemText(indexItem,3,pTree->m_csRefHash);\r
+               m_ListRefLeafs.SetItemText(indexItem,eCol_Name, refNamePrefix+pTree->m_csRefName);\r
+               m_ListRefLeafs.SetItemText(indexItem,eCol_Date, pTree->m_csDate);\r
+               m_ListRefLeafs.SetItemText(indexItem,eCol_Msg,  pTree->m_csSubject);\r
+               m_ListRefLeafs.SetItemText(indexItem,eCol_Hash, pTree->m_csRefHash);\r
        }\r
        else\r
        {\r
@@ -528,3 +531,51 @@ BOOL CBrowseRefsDlg::PreTranslateMessage(MSG* pMsg)
 \r
        return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
 }\r
+\r
+class CRefLeafListCompareFunc\r
+{\r
+public:\r
+       CRefLeafListCompareFunc(CListCtrl* pList, int col):m_col(col),m_pList(pList){}\r
+\r
+       static int CALLBACK StaticCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)\r
+       {\r
+               return ((CRefLeafListCompareFunc*)lParamSort)->Compare(lParam1,lParam2);\r
+       }\r
+\r
+       int Compare(LPARAM lParam1, LPARAM lParam2)\r
+       {\r
+               return Compare(\r
+                       (CShadowTree*)m_pList->GetItemData(lParam1), \r
+                       (CShadowTree*)m_pList->GetItemData(lParam2));\r
+       }\r
+\r
+       int Compare(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
+       CListCtrl* m_pList;\r
+\r
+\r
+};\r
+\r
+void CBrowseRefsDlg::OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult)\r
+{\r
+       LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
+       *pResult = 0;\r
+\r
+       CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs,pNMLV->iSubItem);\r
+       m_ListRefLeafs.SortItemsEx(&CRefLeafListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc);\r
+}\r