1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "BrowseRefsDlg.h"
23 #include "HistoryCombo.h"
24 #include "LoglistUtils.h"
25 #include "UnicodeUtils.h"
33 m_LocalBranchFilter
= gPickRef_Head
;
34 m_RemoteBranchFilter
= gPickRef_Remote
;
35 m_DialogName
=_T("sync");
39 CHistoryCombo m_ctrlLocalBranch
;
40 CHistoryCombo m_ctrlRemoteBranch
;
41 int m_LocalBranchFilter
;
42 int m_RemoteBranchFilter
;
44 CToolTips
*m_pTooltip
;
48 CString m_RegKeyRemoteBranch
;
50 void CbnSelchangeLocalBranch()
52 //Select pull-remote from current branch
54 CString currentBranch
=this->m_ctrlLocalBranch
.GetString();
55 configName
.Format(L
"branch.%s.remote", currentBranch
);
56 CString pullRemote
= g_Git
.GetConfigValue(configName
);
58 this->SetRemote(pullRemote
);
60 //Select pull-branch from current branch
61 configName
.Format(L
"branch.%s.merge", currentBranch
);
62 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
64 CString defaultUpstream
;
65 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
66 int found
= m_ctrlRemoteBranch
.FindStringExact(0, defaultUpstream
);
69 m_ctrlRemoteBranch
.SetCurSel(found
);
71 else if(!pullBranch
.IsEmpty())
73 int index
=m_ctrlRemoteBranch
.FindStringExact(0,pullBranch
);
75 m_ctrlRemoteBranch
.AddString(pullBranch
);
77 m_ctrlRemoteBranch
.SetCurSel(index
);
81 m_ctrlRemoteBranch
.SetCurSel(-1);
84 this->AddBranchToolTips(&this->m_ctrlLocalBranch
,this->m_pTooltip
);
88 void CbnSelchangeRemoteBranch()
90 if(this->m_RegKeyRemoteBranch
.IsEmpty())
91 this->AddBranchToolTips(&this->m_ctrlRemoteBranch
,this->m_pTooltip
);
95 void BnClickedButtonBrowseLocalBranch()
97 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch
, m_LocalBranchFilter
))
98 CbnSelchangeLocalBranch();
100 void BnClickedButtonBrowseRemoteBranch()
102 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
104 CString remoteBranchName
;
106 this->m_ctrlRemoteBranch
.GetWindowText(remoteBranchName
);
107 //remoteName = m_Remote.GetString();
108 //remoteBranchName = remoteName + '/' + remoteBranchName;
109 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
110 if(remoteBranchName
.IsEmpty())
113 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
114 int slashPlace
= remoteBranchName
.Find('/');
115 remoteName
= remoteBranchName
.Left(slashPlace
);
116 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
119 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
121 // m_Remote.SetCurSel(remoteSel);
122 this->SetRemote(remoteName
);
125 m_ctrlRemoteBranch
.AddString(remoteBranchName
);
126 CbnSelchangeRemoteBranch();
131 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch
, m_RemoteBranchFilter
))
132 CbnSelchangeRemoteBranch();
136 virtual void LocalBranchChange(){};
137 virtual void RemoteBranchChange(){};
138 virtual void SetRemote(CString remote
){};
140 void AddBranchToolTips(CHistoryCombo
*pBranch
, CToolTips
*tip
)
144 CString text
=pBranch
->GetString();
150 if (rev
.GetCommit(text
))
159 MessageBox(NULL
, _T("Could not get commit \"") + text
+ _T("\".\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
163 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
164 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
165 rev
.m_CommitHash
.ToString(),
166 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
168 rev
.GetAuthorEmail(),
169 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
170 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
171 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
175 pBranch
->DisableTooltip();
177 tip
->AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
181 void LoadBranchInfo()
183 m_ctrlLocalBranch
.SetMaxHistoryItems(0x0FFFFFFF);
184 m_ctrlRemoteBranch
.SetMaxHistoryItems(0x0FFFFFFF);
189 m_ctrlLocalBranch
.Reset();
190 m_ctrlRemoteBranch
.Reset();
192 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_LOCAL_F
);
194 m_ctrlLocalBranch
.AddString(list
);
196 CString currentBranch
= g_Git
.GetSymbolicRef();
198 if(this->m_RegKeyRemoteBranch
.IsEmpty())
201 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_REMOTE
);
203 m_ctrlRemoteBranch
.AddString(list
);
208 m_ctrlRemoteBranch
.LoadHistory(m_RegKeyRemoteBranch
,_T("sync"));
211 if(!this->m_strLocalBranch
.IsEmpty())
213 m_ctrlLocalBranch
.AddString(m_strLocalBranch
);
214 currentBranch
= m_strLocalBranch
;
218 m_ctrlLocalBranch
.SetCurSel(current
);
221 if(!m_strRemoteBranch
.IsEmpty())
223 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
224 m_ctrlRemoteBranch
.SetCurSel(m_ctrlRemoteBranch
.GetCount()-1);
228 CbnSelchangeLocalBranch();
231 this->LocalBranchChange();
232 this->RemoteBranchChange();
236 CString m_strLocalBranch
;
237 CString m_strRemoteBranch
;
241 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
243 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
244 m_ctrlRemoteBranch
.SaveHistory();
249 #define BRANCH_COMBOX_DDX \
250 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_ctrlLocalBranch); \
251 DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH, m_ctrlRemoteBranch); \
253 #define BRANCH_COMBOX_EVENT \
254 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH, OnCbnSelchangeLocalBranch) \
255 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, OnCbnSelchangeRemoteBranch) \
256 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, OnBnClickedButtonBrowseLocalBranch) \
257 ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH, OnBnClickedButtonBrowseRemoteBranch) \
259 #define BRANCH_COMBOX_ADD_ANCHOR() \
260 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\
261 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\
262 AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\
263 AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\
264 AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);
266 #define BRANCH_COMBOX_EVENT_HANDLE() \
267 afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \
268 afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\
269 afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\
270 afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}