OSDN Git Service

Pick Ref: Implemented ref picking for push dialog
authorJohan 't Hart <johanthart@gmail.com>
Thu, 28 May 2009 18:03:46 +0000 (20:03 +0200)
committerFrank Li <lznuaa@gmail.com>
Fri, 29 May 2009 08:30:10 +0000 (16:30 +0800)
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/BrowseRefsDlg.cpp
src/TortoiseProc/BrowseRefsDlg.h
src/TortoiseProc/PushDlg.cpp
src/TortoiseProc/PushDlg.h
src/TortoiseProc/RebaseDlg.cpp
src/TortoiseProc/resource.h

index 522f9bb..950b0a6 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
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
index f383265..16391be 100644 (file)
@@ -134,4 +134,5 @@ public:
        CString m_pickedRef;\r
 \r
        static CString  PickRef(bool returnAsHash = false, CString initialRef = CString(), int pickRef_Kind = gPickRef_All); \r
+       static bool             PickRefForCombo(CComboBoxEx* pComboBox, int pickRef_Kind = gPickRef_All); \r
 };\r
index 7022c2a..e26b462 100644 (file)
@@ -8,6 +8,7 @@
 #include "Git.h"\r
 #include "registry.h"\r
 #include "AppUtils.h"\r
+#include "BrowseRefsDlg.h"\r
 \r
 // CPushDlg dialog\r
 \r
@@ -44,6 +45,8 @@ BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)
        ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)\r
        ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)\r
     ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)\r
+       ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)\r
+       ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)\r
 END_MESSAGE_MAP()\r
 \r
 BOOL CPushDlg::OnInitDialog()\r
@@ -57,7 +60,9 @@ BOOL CPushDlg::OnInitDialog()
        AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);\r
 \r
        AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);\r
+       AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);\r
        AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);\r
+       AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);\r
 \r
        AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);\r
        AddAnchor(IDC_RD_REMOTE, TOP_LEFT);\r
@@ -185,3 +190,22 @@ void CPushDlg::OnBnClickedRemoteManage()
     // TODO: Add your control notification handler code here\r
     CAppUtils::LaunchRemoteSetting();\r
 }\r
+\r
+void CPushDlg::OnBnClickedButtonBrowseSourceBranch()\r
+{\r
+       if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))\r
+               OnCbnSelchangeBranchSource();\r
+}\r
+\r
+void CPushDlg::OnBnClickedButtonBrowseDestBranch()\r
+{\r
+       CString remoteBranchName;\r
+       m_BranchRemote.GetWindowText(remoteBranchName);\r
+       remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
+       if(remoteBranchName.IsEmpty())\r
+               return; //Canceled\r
+       remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
+       remoteBranchName = remoteBranchName.Mid(remoteBranchName.Find('/') + 1); //Strip remote name (for example 'origin/')\r
+\r
+       m_BranchRemote.SetWindowText(remoteBranchName);\r
+}\r
index e753a66..72cb135 100644 (file)
@@ -41,4 +41,6 @@ public:
        afx_msg void OnCbnSelchangeBranchSource();\r
        afx_msg void OnBnClickedOk();\r
     afx_msg void OnBnClickedRemoteManage();\r
+       afx_msg void OnBnClickedButtonBrowseSourceBranch();\r
+       afx_msg void OnBnClickedButtonBrowseDestBranch();\r
 };\r
index 465ab4b..7665567 100644 (file)
@@ -1211,15 +1211,5 @@ void CRebaseDlg::OnBnClickedAbort()
 \r
 void CRebaseDlg::OnBnClickedButtonBrowse()\r
 {\r
-       CString origRef;\r
-       m_UpstreamCtrl.GetLBText(m_UpstreamCtrl.GetCurSel(), origRef);\r
-       CString resultRef = CBrowseRefsDlg::PickRef(false,origRef,gPickRef_NoTag);\r
-       if(resultRef.IsEmpty())\r
-               return;\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
-       m_UpstreamCtrl.SetCurSel(m_UpstreamCtrl.FindStringExact(0,resultRef));\r
-\r
+       CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl, gPickRef_NoTag);\r
 }\r
index d0f02e9..d1dc252 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ