1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2015 - 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.
21 #include "BrowseRefsDlg.h"
22 #include "HistoryCombo.h"
23 #include "LoglistUtils.h"
24 #include "UnicodeUtils.h"
32 m_LocalBranchFilter
= gPickRef_Head
;
33 m_RemoteBranchFilter
= gPickRef_Remote
;
34 m_DialogName
=_T("sync");
38 CHistoryCombo m_ctrlLocalBranch
;
39 CHistoryCombo m_ctrlRemoteBranch
;
40 int m_LocalBranchFilter
;
41 int m_RemoteBranchFilter
;
43 CToolTips
*m_pTooltip
;
47 CString m_RegKeyRemoteBranch
;
49 void CbnSelchangeLocalBranch()
51 //Select pull-remote from current branch
52 CString pullRemote
, pullBranch
;
53 g_Git
.GetRemoteTrackedBranch(m_ctrlLocalBranch
.GetString(), pullRemote
, pullBranch
);
55 this->SetRemote(pullRemote
);
57 CString defaultUpstream
;
58 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
59 int found
= m_ctrlRemoteBranch
.FindStringExact(0, defaultUpstream
);
62 m_ctrlRemoteBranch
.SetCurSel(found
);
64 else if(!pullBranch
.IsEmpty())
66 int index
=m_ctrlRemoteBranch
.FindStringExact(0,pullBranch
);
68 m_ctrlRemoteBranch
.AddString(pullBranch
);
70 m_ctrlRemoteBranch
.SetCurSel(index
);
74 m_ctrlRemoteBranch
.SetCurSel(-1);
77 this->AddBranchToolTips(&this->m_ctrlLocalBranch
,this->m_pTooltip
);
81 void CbnSelchangeRemoteBranch()
83 if(this->m_RegKeyRemoteBranch
.IsEmpty())
84 this->AddBranchToolTips(&this->m_ctrlRemoteBranch
,this->m_pTooltip
);
88 void BnClickedButtonBrowseLocalBranch()
90 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch
, m_LocalBranchFilter
))
91 CbnSelchangeLocalBranch();
93 void BnClickedButtonBrowseRemoteBranch()
95 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
97 CString remoteBranchName
;
99 this->m_ctrlRemoteBranch
.GetWindowText(remoteBranchName
);
100 //remoteName = m_Remote.GetString();
101 //remoteBranchName = remoteName + '/' + remoteBranchName;
102 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
103 if(remoteBranchName
.IsEmpty())
106 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
107 int slashPlace
= remoteBranchName
.Find('/');
108 remoteName
= remoteBranchName
.Left(slashPlace
);
109 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
112 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
114 // m_Remote.SetCurSel(remoteSel);
115 this->SetRemote(remoteName
);
118 m_ctrlRemoteBranch
.AddString(remoteBranchName
);
119 CbnSelchangeRemoteBranch();
124 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch
, m_RemoteBranchFilter
))
125 CbnSelchangeRemoteBranch();
129 virtual void LocalBranchChange(){};
130 virtual void RemoteBranchChange(){};
131 virtual void SetRemote(CString remote
){};
133 void AddBranchToolTips(CHistoryCombo
*pBranch
, CToolTips
*tip
)
137 CString text
=pBranch
->GetString();
142 pBranch
->DisableTooltip();
147 if (rev
.GetCommit(text
))
149 pBranch
->DisableTooltip();
150 MessageBox(nullptr, rev
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
154 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
155 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
156 rev
.m_CommitHash
.ToString(),
157 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
159 rev
.GetAuthorEmail(),
160 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
161 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
162 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
166 pBranch
->DisableTooltip();
168 tip
->AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
172 void LoadBranchInfo()
174 m_ctrlLocalBranch
.SetMaxHistoryItems(0x0FFFFFFF);
175 m_ctrlRemoteBranch
.SetMaxHistoryItems(0x0FFFFFFF);
181 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_LOCAL_F
);
183 m_ctrlLocalBranch
.SetList(list
);
185 if(this->m_RegKeyRemoteBranch
.IsEmpty())
188 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_REMOTE
);
190 m_ctrlRemoteBranch
.SetList(list
);
195 m_ctrlRemoteBranch
.Reset();
196 m_ctrlRemoteBranch
.LoadHistory(m_RegKeyRemoteBranch
,_T("sync"));
199 if(!this->m_strLocalBranch
.IsEmpty())
201 m_ctrlLocalBranch
.AddString(m_strLocalBranch
);
205 m_ctrlLocalBranch
.SetCurSel(current
);
208 if(!m_strRemoteBranch
.IsEmpty())
210 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
211 m_ctrlRemoteBranch
.SetCurSel(m_ctrlRemoteBranch
.GetCount()-1);
215 CbnSelchangeLocalBranch();
218 this->LocalBranchChange();
219 this->RemoteBranchChange();
223 CString m_strLocalBranch
;
224 CString m_strRemoteBranch
;
228 if(!this->m_RegKeyRemoteBranch
.IsEmpty())
230 m_ctrlRemoteBranch
.AddString(m_strRemoteBranch
);
231 m_ctrlRemoteBranch
.SaveHistory();
236 #define BRANCH_COMBOX_DDX \
237 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_ctrlLocalBranch); \
238 DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH, m_ctrlRemoteBranch); \
240 #define BRANCH_COMBOX_EVENT \
241 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH, OnCbnSelchangeLocalBranch) \
242 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, OnCbnSelchangeRemoteBranch) \
243 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, OnBnClickedButtonBrowseLocalBranch) \
244 ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH, OnBnClickedButtonBrowseRemoteBranch) \
246 #define BRANCH_COMBOX_ADD_ANCHOR() \
247 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\
248 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\
249 AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\
250 AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\
251 AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);
253 #define BRANCH_COMBOX_EVENT_HANDLE() \
254 afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \
255 afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\
256 afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\
257 afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}