--- /dev/null
+#pragma once\r
+#include "afxwin.h"\r
+#include "LogDlg.h"\r
+#include "BrowseRefsDlg.h"\r
+#include "HistoryCombo.h"\r
+#include "Balloon.h"\r
+#include "HistoryCombo.h"\r
+#include "AppUtils.h"\r
+\r
+class CBranchCombox\r
+{\r
+public:\r
+ CBranchCombox()\r
+ {\r
+ m_LocalBranchFilter = gPickRef_Head;\r
+ m_RemoteBranchFilter = gPickRef_Remote;\r
+ m_DialogName=_T("sync");\r
+ m_pTooltip=NULL;\r
+ \r
+ }\r
+protected:\r
+ CHistoryCombo m_ctrlLocalBranch;\r
+ CHistoryCombo m_ctrlRemoteBranch;\r
+ int m_LocalBranchFilter;\r
+ int m_RemoteBranchFilter;\r
+\r
+ CBalloon *m_pTooltip;\r
+ \r
+ CString m_DialogName;\r
+ \r
+ CString m_RegKeyRemoteBranch;\r
+\r
+ void CbnSelchangeLocalBranch()\r
+ {\r
+ //Select pull-remote from current branch\r
+ CString configName;\r
+ CString currentBranch=this->m_ctrlLocalBranch.GetString();\r
+ configName.Format(L"branch.%s.remote", currentBranch);\r
+ CString pullRemote = g_Git.GetConfigValue(configName);\r
+\r
+ this->SetRemote(pullRemote);\r
+\r
+ //Select pull-branch from current branch\r
+ configName.Format(L"branch.%s.merge", currentBranch);\r
+ CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
+\r
+ CString defaultUpstream;\r
+ defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch);\r
+ int found = m_ctrlRemoteBranch.FindStringExact(0, defaultUpstream);\r
+ if(found >= 0)\r
+ {\r
+ m_ctrlRemoteBranch.SetCurSel(found);\r
+ }\r
+ else if(!pullBranch.IsEmpty())\r
+ {\r
+ m_ctrlRemoteBranch.AddString(pullBranch);\r
+ }\r
+ else if(!this->m_RegKeyRemoteBranch.IsEmpty())\r
+ {\r
+ m_ctrlRemoteBranch.AddString(currentBranch);\r
+ }\r
+ \r
+ this->AddBranchToolTips(&this->m_ctrlLocalBranch,this->m_pTooltip);\r
+\r
+ LocalBranchChange();\r
+ };\r
+ void CbnSelchangeRemoteBranch()\r
+ {\r
+ if(this->m_RegKeyRemoteBranch.IsEmpty())\r
+ this->AddBranchToolTips(&this->m_ctrlRemoteBranch,this->m_pTooltip);\r
+\r
+ RemoteBranchChange();\r
+ }\r
+ void BnClickedButtonBrowseLocalBranch()\r
+ {\r
+ if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch, m_LocalBranchFilter)) \r
+ CbnSelchangeLocalBranch();\r
+ }\r
+ void BnClickedButtonBrowseRemoteBranch()\r
+ {\r
+ if(!this->m_RegKeyRemoteBranch.IsEmpty())\r
+ {\r
+ CString remoteBranchName;\r
+ CString remoteName;\r
+ this->m_ctrlRemoteBranch.GetWindowText(remoteBranchName);\r
+ //remoteName = m_Remote.GetString();\r
+ //remoteBranchName = remoteName + '/' + remoteBranchName;\r
+ remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
+ if(remoteBranchName.IsEmpty())\r
+ return; //Canceled\r
+\r
+ remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
+ int slashPlace = remoteBranchName.Find('/');\r
+ remoteName = remoteBranchName.Left(slashPlace);\r
+ remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')\r
+\r
+ //Select remote\r
+ //int remoteSel = m_Remote.FindStringExact(0,remoteName);\r
+ //if(remoteSel >= 0)\r
+ // m_Remote.SetCurSel(remoteSel);\r
+ this->SetRemote(remoteName);\r
+\r
+ //Select branch\r
+ m_ctrlRemoteBranch.AddString(remoteBranchName);\r
+ CbnSelchangeRemoteBranch();\r
+\r
+ }else\r
+ {\r
+ if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch, m_RemoteBranchFilter)) \r
+ CbnSelchangeRemoteBranch();\r
+ }\r
+ }\r
+\r
+ virtual void LocalBranchChange(){};\r
+ virtual void RemoteBranchChange(){};\r
+ virtual void SetRemote(CString remote){};\r
+\r
+ void AddBranchToolTips(CHistoryCombo *pBranch,CBalloon *tip)\r
+ {\r
+ if(pBranch&&tip)\r
+ {\r
+ CString text=pBranch->GetString();\r
+ CString tooltip;\r
+ BYTE_VECTOR data;\r
+ g_Git.GetLog(data,text,NULL,1,0);\r
+ GitRev rev;\r
+ rev.ParserFromLog(data);\r
+ tooltip.Format(_T("CommitHash:%s\nCommit by: %s %s\n <b>%s</b> \n %s"),\r
+ rev.m_CommitHash,\r
+ rev.m_AuthorName,\r
+ CAppUtils::FormatDateAndTime(rev.m_AuthorDate,DATE_LONGDATE),\r
+ rev.m_Subject,\r
+ rev.m_Body);\r
+\r
+ pBranch->DisableTooltip();\r
+ \r
+ tip->AddTool(pBranch->GetComboBoxCtrl(),tooltip);\r
+ }\r
+ }\r
+ \r
+ void LoadBranchInfo()\r
+ {\r
+ m_ctrlLocalBranch.SetMaxHistoryItems(0x7FFFFFFF);\r
+ m_ctrlRemoteBranch.SetMaxHistoryItems(0x7FFFFFFF);\r
+\r
+ STRING_VECTOR list;\r
+ list.clear();\r
+ int current;\r
+ g_Git.GetBranchList(list,¤t,CGit::BRANCH_LOCAL);\r
+ m_ctrlLocalBranch.AddString(list);\r
+\r
+ CString currentBranch = g_Git.GetSymbolicRef();\r
+ \r
+ if(this->m_RegKeyRemoteBranch.IsEmpty())\r
+ {\r
+ list.clear();\r
+ g_Git.GetBranchList(list,¤t,CGit::BRANCH_REMOTE);\r
+ \r
+ m_ctrlRemoteBranch.AddString(list);\r
+\r
+ }else\r
+ {\r
+ m_ctrlRemoteBranch.LoadHistory(m_RegKeyRemoteBranch,_T("sync"));\r
+ }\r
+\r
+ if(!this->m_strLocalBranch.IsEmpty())\r
+ {\r
+ m_ctrlLocalBranch.AddString(m_strLocalBranch);\r
+ currentBranch = m_strLocalBranch;\r
+ }\r
+ else\r
+ {\r
+ m_ctrlLocalBranch.SetCurSel(current);\r
+ }\r
+\r
+ if(!m_strRemoteBranch.IsEmpty())\r
+ {\r
+ m_ctrlRemoteBranch.AddString(m_strRemoteBranch);\r
+ m_ctrlRemoteBranch.SetCurSel(m_ctrlRemoteBranch.GetCount()-1);\r
+ }\r
+ else\r
+ {\r
+ CbnSelchangeLocalBranch();\r
+ }\r
+\r
+ this->LocalBranchChange();\r
+ this->RemoteBranchChange();\r
+ }\r
+ \r
+public:\r
+ CString m_strLocalBranch;\r
+ CString m_strRemoteBranch;\r
+};\r
+\r
+#define BRANCH_COMBOX_DDX \\r
+ DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_ctrlLocalBranch); \\r
+ DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH, m_ctrlRemoteBranch); \\r
+\r
+#define BRANCH_COMBOX_EVENT \\r
+ ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH, OnCbnSelchangeLocalBranch) \\r
+ ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, OnCbnSelchangeRemoteBranch) \\r
+ ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, OnBnClickedButtonBrowseLocalBranch) \\r
+ ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH, OnBnClickedButtonBrowseRemoteBranch) \\r
+\r
+#define BRANCH_COMBOX_ADD_ANCHOR() \\r
+ AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\\r
+ AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\\r
+ AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\\r
+ AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\\r
+ AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);\r
+\r
+#define BRANCH_COMBOX_EVENT_HANDLE() \\r
+ afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \\r
+ afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\\r
+ afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\\r
+ afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}\r
+\r