some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / BranchCombox.h
blobab55ded22cec98fb14d362725c727252056ea9fd
1 #pragma once
2 #include "afxwin.h"
3 #include "LogDlg.h"
4 #include "BrowseRefsDlg.h"
5 #include "HistoryCombo.h"
6 #include "Balloon.h"
7 #include "HistoryCombo.h"
8 #include "AppUtils.h"
9 #include "UnicodeUtils.h"
11 class CBranchCombox
13 public:
14 CBranchCombox()
16 m_LocalBranchFilter = gPickRef_Head;
17 m_RemoteBranchFilter = gPickRef_Remote;
18 m_DialogName=_T("sync");
19 m_pTooltip=NULL;
21 protected:
22 CHistoryCombo m_ctrlLocalBranch;
23 CHistoryCombo m_ctrlRemoteBranch;
24 int m_LocalBranchFilter;
25 int m_RemoteBranchFilter;
27 CBalloon *m_pTooltip;
29 CString m_DialogName;
31 CString m_RegKeyRemoteBranch;
33 void CbnSelchangeLocalBranch()
35 //Select pull-remote from current branch
36 CString configName;
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);
50 if(found >= 0)
52 m_ctrlRemoteBranch.SetCurSel(found);
54 else if(!pullBranch.IsEmpty())
56 int index=m_ctrlRemoteBranch.FindStringExact(0,pullBranch);
57 if( index<0 )
58 m_ctrlRemoteBranch.AddString(pullBranch);
59 else
60 m_ctrlRemoteBranch.SetCurSel(index);
62 //else if(!this->m_RegKeyRemoteBranch.IsEmpty())
63 else
65 m_ctrlRemoteBranch.SetCurSel(-1);
68 this->AddBranchToolTips(&this->m_ctrlLocalBranch,this->m_pTooltip);
70 LocalBranchChange();
72 void CbnSelchangeRemoteBranch()
74 if(this->m_RegKeyRemoteBranch.IsEmpty())
75 this->AddBranchToolTips(&this->m_ctrlRemoteBranch,this->m_pTooltip);
77 RemoteBranchChange();
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;
89 CString remoteName;
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())
95 return; //Canceled
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/')
102 //Select remote
103 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
104 //if(remoteSel >= 0)
105 // m_Remote.SetCurSel(remoteSel);
106 this->SetRemote(remoteName);
108 //Select branch
109 m_ctrlRemoteBranch.AddString(remoteBranchName);
110 CbnSelchangeRemoteBranch();
112 }else
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)
125 if(pBranch&&tip)
127 CString text=pBranch->GetString();
128 CString tooltip;
129 GitRev rev;
131 if(rev.GetCommit(text))
133 ASSERT(FALSE);
134 return;
137 tooltip.Format(_T("CommitHash:%s\nCommit by: %s %s\n <b>%s</b> \n %s"),
138 rev.m_CommitHash.ToString(),
139 rev.GetAuthorName(),
140 CAppUtils::FormatDateAndTime(rev.GetAuthorDate(),DATE_LONGDATE),
141 rev.GetSubject(),
142 rev.GetBody());
144 pBranch->DisableTooltip();
146 tip->AddTool(pBranch->GetComboBoxCtrl(),tooltip);
150 void LoadBranchInfo()
152 m_ctrlLocalBranch.SetMaxHistoryItems(0x0FFFFFFF);
153 m_ctrlRemoteBranch.SetMaxHistoryItems(0x0FFFFFFF);
155 STRING_VECTOR list;
156 list.clear();
157 int current=0;
158 m_ctrlLocalBranch.Reset();
159 m_ctrlRemoteBranch.Reset();
161 g_Git.GetBranchList(list,&current,CGit::BRANCH_LOCAL_F);
163 m_ctrlLocalBranch.AddString(list);
165 CString currentBranch = g_Git.GetSymbolicRef();
167 if(this->m_RegKeyRemoteBranch.IsEmpty())
169 list.clear();
170 g_Git.GetBranchList(list,&current,CGit::BRANCH_REMOTE);
172 m_ctrlRemoteBranch.AddString(list);
174 }else
176 m_ctrlRemoteBranch.LoadHistory(m_RegKeyRemoteBranch,_T("sync"));
179 if(!this->m_strLocalBranch.IsEmpty())
181 m_ctrlLocalBranch.AddString(m_strLocalBranch);
182 currentBranch = m_strLocalBranch;
184 else
186 m_ctrlLocalBranch.SetCurSel(current);
189 if(!m_strRemoteBranch.IsEmpty())
191 m_ctrlRemoteBranch.AddString(m_strRemoteBranch);
192 m_ctrlRemoteBranch.SetCurSel(m_ctrlRemoteBranch.GetCount()-1);
194 else
196 CbnSelchangeLocalBranch();
199 this->LocalBranchChange();
200 this->RemoteBranchChange();
203 public:
204 CString m_strLocalBranch;
205 CString m_strRemoteBranch;
207 void SaveHistory()
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();}