1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014 - 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
53 CString pullRemote
, pullBranch
;
54 g_Git
.GetRemoteTrackedBranch(m_ctrlLocalBranch
.GetString(), pullRemote
, pullBranch
);
56 this->SetRemote(pullRemote
);
58 CString defaultUpstream
;
59 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
60 int found
= m_ctrlRemoteBranch
.FindStringExact(0, defaultUpstream
);
63 m_ctrlRemoteBranch
.SetCurSel(found
);
65 else if(!pullBranch
.IsEmpty())
67 int index
=m_ctrlRemoteBranch
.FindStringExact(0,pullBranch
);
69 m_ctrlRemoteBranch
.AddString(pullBranch
);
71 m_ctrlRemoteBranch
.SetCurSel(index
);
75 m_ctrlRemoteBranch
.SetCurSel(-1);
78 this->AddBranchToolTips(&this->m_ctrlLocalBranch
,this->m_pTooltip
);
82 void CbnSelchangeRemoteBranch()
84 if(this->m_RegKeyRemoteBranch
.IsEmpty())
85 this->AddBranchToolTips(&this->m_ctrlRemoteBranch
,this->m_pTooltip
);
89 void BnClickedButtonBrowseLocalBranch()
91 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch
, m_LocalBranchFilter
))
92 CbnSelchangeLocalBranch();
94 void BnClickedButtonBrowseRemoteBranch()
96 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
98 CString remoteBranchName
;
100 this->m_ctrlRemoteBranch
.GetWindowText(remoteBranchName
);
101 //remoteName = m_Remote.GetString();
102 //remoteBranchName = remoteName + '/' + remoteBranchName;
103 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
104 if(remoteBranchName
.IsEmpty())
107 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
108 int slashPlace
= remoteBranchName
.Find('/');
109 remoteName
= remoteBranchName
.Left(slashPlace
);
110 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
113 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
115 // m_Remote.SetCurSel(remoteSel);
116 this->SetRemote(remoteName
);
119 m_ctrlRemoteBranch
.AddString(remoteBranchName
);
120 CbnSelchangeRemoteBranch();
125 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch
, m_RemoteBranchFilter
))
126 CbnSelchangeRemoteBranch();
130 virtual void LocalBranchChange(){};
131 virtual void RemoteBranchChange(){};
132 virtual void SetRemote(CString remote
){};
134 void AddBranchToolTips(CHistoryCombo
*pBranch
, CToolTips
*tip
)
138 CString text
=pBranch
->GetString();
144 if (rev
.GetCommit(text
))
153 MessageBox(NULL
, _T("Could not get commit \"") + text
+ _T("\".\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
157 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
158 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
159 rev
.m_CommitHash
.ToString(),
160 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
162 rev
.GetAuthorEmail(),
163 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
164 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
165 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
169 pBranch
->DisableTooltip();
171 tip
->AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
175 void LoadBranchInfo()
177 m_ctrlLocalBranch
.SetMaxHistoryItems(0x0FFFFFFF);
178 m_ctrlRemoteBranch
.SetMaxHistoryItems(0x0FFFFFFF);
184 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_LOCAL_F
);
186 m_ctrlLocalBranch
.SetList(list
);
188 if(this->m_RegKeyRemoteBranch
.IsEmpty())
191 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_REMOTE
);
193 m_ctrlRemoteBranch
.SetList(list
);
198 m_ctrlRemoteBranch
.Reset();
199 m_ctrlRemoteBranch
.LoadHistory(m_RegKeyRemoteBranch
,_T("sync"));
202 if(!this->m_strLocalBranch
.IsEmpty())
204 m_ctrlLocalBranch
.AddString(m_strLocalBranch
);
208 m_ctrlLocalBranch
.SetCurSel(current
);
211 if(!m_strRemoteBranch
.IsEmpty())
213 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
214 m_ctrlRemoteBranch
.SetCurSel(m_ctrlRemoteBranch
.GetCount()-1);
218 CbnSelchangeLocalBranch();
221 this->LocalBranchChange();
222 this->RemoteBranchChange();
226 CString m_strLocalBranch
;
227 CString m_strRemoteBranch
;
231 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
233 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
234 m_ctrlRemoteBranch
.SaveHistory();
239 #define BRANCH_COMBOX_DDX \
240 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_ctrlLocalBranch); \
241 DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH, m_ctrlRemoteBranch); \
243 #define BRANCH_COMBOX_EVENT \
244 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH, OnCbnSelchangeLocalBranch) \
245 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, OnCbnSelchangeRemoteBranch) \
246 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, OnBnClickedButtonBrowseLocalBranch) \
247 ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH, OnBnClickedButtonBrowseRemoteBranch) \
249 #define BRANCH_COMBOX_ADD_ANCHOR() \
250 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\
251 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\
252 AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\
253 AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\
254 AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);
256 #define BRANCH_COMBOX_EVENT_HANDLE() \
257 afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \
258 afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\
259 afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\
260 afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}