OSDN Git Service

Pick Ref: Implemented ref picking for push dialog
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BrowseRefsDlg.cpp
index 0f6dac1..ef93ba1 100644 (file)
@@ -711,3 +711,35 @@ CString CBrowseRefsDlg::PickRef(bool returnAsHash, CString initialRef, int pickR
        return dlg.m_pickedRef;\r
 }\r
 \r
+bool CBrowseRefsDlg::PickRefForCombo(CComboBoxEx* pComboBox, int pickRef_Kind)\r
+{\r
+       CString origRef;\r
+       pComboBox->GetLBText(pComboBox->GetCurSel(), origRef);\r
+       CString resultRef = PickRef(false,origRef,pickRef_Kind);\r
+       if(resultRef.IsEmpty())\r
+               return false;\r
+       if(wcsncmp(resultRef,L"refs/",5)==0)\r
+               resultRef = resultRef.Mid(5);\r
+//     if(wcsncmp(resultRef,L"heads/",6)==0)\r
+//             resultRef = resultRef.Mid(6);\r
+\r
+       //Find closest match of choice in combobox\r
+       int ixFound = -1;\r
+       int matchLength = 0;\r
+       CString comboRefName;\r
+       for(int i = 0; i < pComboBox->GetCount(); ++i)\r
+       {\r
+               pComboBox->GetLBText(i, comboRefName);\r
+               if(matchLength < comboRefName.GetLength() && resultRef.Right(comboRefName.GetLength()) == comboRefName)\r
+               {\r
+                       matchLength = comboRefName.GetLength();\r
+                       ixFound = i;\r
+               }\r
+       }\r
+       if(ixFound >= 0)\r
+               pComboBox->SetCurSel(ixFound);\r
+       else\r
+               ASSERT(FALSE);//No match found. So either pickRef_Kind is wrong or the combobox does not contain the ref specified in the picker (which it should unless the repo has changed before creating the CBrowseRef dialog)\r
+\r
+       return true;\r
+}\r