OSDN Git Service

BrowseRefs: Initial branch selection also possible with partial ref-name
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BrowseRefsDlg.cpp
index c6862b0..d24bb47 100644 (file)
@@ -95,7 +95,8 @@ BOOL CBrowseRefsDlg::OnInitDialog()
        Refresh(m_initialRef);\r
 \r
 \r
-       return TRUE;\r
+       m_ListRefLeafs.SetFocus();\r
+       return FALSE;\r
 }\r
 \r
 CShadowTree* CShadowTree::GetNextSub(CString& nameLeft, bool bCreateIfNotExist)\r
@@ -124,6 +125,34 @@ CShadowTree* CShadowTree::GetNextSub(CString& nameLeft, bool bCreateIfNotExist)
        return &nextNode;\r
 }\r
 \r
+CShadowTree* CShadowTree::FindLeaf(CString partialRefName)\r
+{\r
+       if(IsLeaf())\r
+       {\r
+               if(m_csRefName.GetLength() > partialRefName.GetLength())\r
+                       return NULL;\r
+               if(partialRefName.Right(m_csRefName.GetLength()) == m_csRefName)\r
+               {\r
+                       //Match of leaf name. Try match on total name.\r
+                       CString totalRefName = GetRefName();\r
+                       if(totalRefName.Right(partialRefName.GetLength()) == partialRefName)\r
+                               return this; //Also match. Found.\r
+               }\r
+       }\r
+       else\r
+       {\r
+               //Not a leaf. Search all nodes.\r
+               for(TShadowTreeMap::iterator itShadowTree = m_ShadowTree.begin(); itShadowTree != m_ShadowTree.end(); ++itShadowTree)\r
+               {\r
+                       CShadowTree* pSubtree = itShadowTree->second.FindLeaf(partialRefName);\r
+                       if(pSubtree != NULL)\r
+                               return pSubtree; //Found\r
+               }\r
+       }\r
+       return NULL;//Not found\r
+}\r
+\r
+\r
 typedef std::map<CString,CString> MAP_STRING_STRING;\r
 \r
 CString CBrowseRefsDlg::GetSelectedRef(bool onlyIfLeaf)\r
@@ -222,14 +251,16 @@ void CBrowseRefsDlg::Refresh(CString selectRef)
        }\r
 \r
 \r
-       if(selectRef.IsEmpty() || !SelectRef(selectRef))\r
+       if(selectRef.IsEmpty() || !SelectRef(selectRef, false))\r
                //Probably not on a branch. Select root node.\r
                m_RefTreeCtrl.Expand(m_TreeRoot.m_hTree,TVE_EXPAND);\r
 \r
 }\r
 \r
-bool CBrowseRefsDlg::SelectRef(CString refName)\r
+bool CBrowseRefsDlg::SelectRef(CString refName, bool bExactMatch)\r
 {\r
+       if(!bExactMatch)\r
+               refName = GetFullRefName(refName);\r
        if(wcsnicmp(refName,L"refs/",5)!=0)\r
                return false; // Not a ref name\r
 \r
@@ -422,6 +453,15 @@ bool CBrowseRefsDlg::DoDeleteRef(CString completeRefName, bool bForce)
        return true;\r
 }\r
 \r
+CString CBrowseRefsDlg::GetFullRefName(CString partialRefName)\r
+{\r
+       CShadowTree* pLeaf = m_TreeRoot.FindLeaf(partialRefName);\r
+       if(pLeaf == NULL)\r
+               return CString();\r
+       return pLeaf->GetRefName();\r
+}\r
+\r
+\r
 void CBrowseRefsDlg::OnContextMenu(CWnd* pWndFrom, CPoint point)\r
 {\r
        if(pWndFrom==&m_RefTreeCtrl)       OnContextMenu_RefTreeCtrl(point);\r