4 #include "BrowseRefsDlg.h"
5 #include "HistoryCombo.h"
7 #include "HistoryCombo.h"
9 #include "UnicodeUtils.h"
16 m_LocalBranchFilter
= gPickRef_Head
;
17 m_RemoteBranchFilter
= gPickRef_Remote
;
18 m_DialogName
=_T("sync");
22 CHistoryCombo m_ctrlLocalBranch
;
23 CHistoryCombo m_ctrlRemoteBranch
;
24 int m_LocalBranchFilter
;
25 int m_RemoteBranchFilter
;
31 CString m_RegKeyRemoteBranch
;
33 void CbnSelchangeLocalBranch()
35 //Select pull-remote from current branch
37 CString currentBranch
=this->m_ctrlLocalBranch
.GetString();
38 configName
.Format(L
"branch.%s.remote", currentBranch
);
39 CString pullRemote
= g_Git
.GetConfigValue(configName
);
41 this->SetRemote(pullRemote
);
43 //Select pull-branch from current branch
44 configName
.Format(L
"branch.%s.merge", currentBranch
);
45 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
47 CString defaultUpstream
;
48 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
49 int found
= m_ctrlRemoteBranch
.FindStringExact(0, defaultUpstream
);
52 m_ctrlRemoteBranch
.SetCurSel(found
);
54 else if(!pullBranch
.IsEmpty())
56 int index
=m_ctrlRemoteBranch
.FindStringExact(0,pullBranch
);
58 m_ctrlRemoteBranch
.AddString(pullBranch
);
60 m_ctrlRemoteBranch
.SetCurSel(index
);
62 //else if(!this->m_RegKeyRemoteBranch.IsEmpty())
65 m_ctrlRemoteBranch
.SetCurSel(-1);
68 this->AddBranchToolTips(&this->m_ctrlLocalBranch
,this->m_pTooltip
);
72 void CbnSelchangeRemoteBranch()
74 if(this->m_RegKeyRemoteBranch
.IsEmpty())
75 this->AddBranchToolTips(&this->m_ctrlRemoteBranch
,this->m_pTooltip
);
79 void BnClickedButtonBrowseLocalBranch()
81 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch
, m_LocalBranchFilter
))
82 CbnSelchangeLocalBranch();
84 void BnClickedButtonBrowseRemoteBranch()
86 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
88 CString remoteBranchName
;
90 this->m_ctrlRemoteBranch
.GetWindowText(remoteBranchName
);
91 //remoteName = m_Remote.GetString();
92 //remoteBranchName = remoteName + '/' + remoteBranchName;
93 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
94 if(remoteBranchName
.IsEmpty())
97 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
98 int slashPlace
= remoteBranchName
.Find('/');
99 remoteName
= remoteBranchName
.Left(slashPlace
);
100 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
103 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
105 // m_Remote.SetCurSel(remoteSel);
106 this->SetRemote(remoteName
);
109 m_ctrlRemoteBranch
.AddString(remoteBranchName
);
110 CbnSelchangeRemoteBranch();
114 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch
, m_RemoteBranchFilter
))
115 CbnSelchangeRemoteBranch();
119 virtual void LocalBranchChange(){};
120 virtual void RemoteBranchChange(){};
121 virtual void SetRemote(CString remote
){};
123 void AddBranchToolTips(CHistoryCombo
*pBranch
,CBalloon
*tip
)
127 CString text
=pBranch
->GetString();
131 if(rev
.GetCommit(text
))
137 tooltip
.Format(_T("CommitHash:%s\nCommit by: %s %s\n <b>%s</b> \n %s"),
138 rev
.m_CommitHash
.ToString(),
140 CAppUtils::FormatDateAndTime(rev
.GetAuthorDate(),DATE_LONGDATE
),
144 pBranch
->DisableTooltip();
146 tip
->AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
150 void LoadBranchInfo()
152 m_ctrlLocalBranch
.SetMaxHistoryItems(0x0FFFFFFF);
153 m_ctrlRemoteBranch
.SetMaxHistoryItems(0x0FFFFFFF);
158 m_ctrlLocalBranch
.Reset();
159 m_ctrlRemoteBranch
.Reset();
161 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_LOCAL_F
);
163 m_ctrlLocalBranch
.AddString(list
);
165 CString currentBranch
= g_Git
.GetSymbolicRef();
167 if(this->m_RegKeyRemoteBranch
.IsEmpty())
170 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_REMOTE
);
172 m_ctrlRemoteBranch
.AddString(list
);
176 m_ctrlRemoteBranch
.LoadHistory(m_RegKeyRemoteBranch
,_T("sync"));
179 if(!this->m_strLocalBranch
.IsEmpty())
181 m_ctrlLocalBranch
.AddString(m_strLocalBranch
);
182 currentBranch
= m_strLocalBranch
;
186 m_ctrlLocalBranch
.SetCurSel(current
);
189 if(!m_strRemoteBranch
.IsEmpty())
191 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
192 m_ctrlRemoteBranch
.SetCurSel(m_ctrlRemoteBranch
.GetCount()-1);
196 CbnSelchangeLocalBranch();
199 this->LocalBranchChange();
200 this->RemoteBranchChange();
204 CString m_strLocalBranch
;
205 CString m_strRemoteBranch
;
209 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
211 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
212 m_ctrlRemoteBranch
.SaveHistory();
217 #define BRANCH_COMBOX_DDX \
218 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_ctrlLocalBranch); \
219 DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH, m_ctrlRemoteBranch); \
221 #define BRANCH_COMBOX_EVENT \
222 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH, OnCbnSelchangeLocalBranch) \
223 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, OnCbnSelchangeRemoteBranch) \
224 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, OnBnClickedButtonBrowseLocalBranch) \
225 ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH, OnBnClickedButtonBrowseRemoteBranch) \
227 #define BRANCH_COMBOX_ADD_ANCHOR() \
228 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\
229 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\
230 AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\
231 AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\
232 AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);
234 #define BRANCH_COMBOX_EVENT_HANDLE() \
235 afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \
236 afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\
237 afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\
238 afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}