Do not report libgit2 warnings
[TortoiseGit.git] / src / TortoiseProc / BranchCombox.h
blobc32e57a2accb944742381845aaddc2a10acbfed3
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.
19 #pragma once
20 #include "LogDlg.h"
21 #include "BrowseRefsDlg.h"
22 #include "HistoryCombo.h"
23 #include "LoglistUtils.h"
24 #include "UnicodeUtils.h"
25 #include "Tooltip.h"
27 class CBranchCombox
29 public:
30 CBranchCombox()
32 m_LocalBranchFilter = gPickRef_Head;
33 m_RemoteBranchFilter = gPickRef_Remote;
34 m_DialogName=_T("sync");
35 m_pTooltip=NULL;
37 protected:
38 CHistoryCombo m_ctrlLocalBranch;
39 CHistoryCombo m_ctrlRemoteBranch;
40 int m_LocalBranchFilter;
41 int m_RemoteBranchFilter;
43 CToolTips *m_pTooltip;
45 CString m_DialogName;
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);
60 if(found >= 0)
62 m_ctrlRemoteBranch.SetCurSel(found);
64 else if(!pullBranch.IsEmpty())
66 int index=m_ctrlRemoteBranch.FindStringExact(0,pullBranch);
67 if( index<0 )
68 m_ctrlRemoteBranch.AddString(pullBranch);
69 else
70 m_ctrlRemoteBranch.SetCurSel(index);
72 else
74 m_ctrlRemoteBranch.SetCurSel(-1);
77 this->AddBranchToolTips(&this->m_ctrlLocalBranch,this->m_pTooltip);
79 LocalBranchChange();
81 void CbnSelchangeRemoteBranch()
83 if(this->m_RegKeyRemoteBranch.IsEmpty())
84 this->AddBranchToolTips(&this->m_ctrlRemoteBranch,this->m_pTooltip);
86 RemoteBranchChange();
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;
98 CString remoteName;
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())
104 return; //Canceled
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/')
111 //Select remote
112 //int remoteSel = m_Remote.FindStringExact(0,remoteName);
113 //if(remoteSel >= 0)
114 // m_Remote.SetCurSel(remoteSel);
115 this->SetRemote(remoteName);
117 //Select branch
118 m_ctrlRemoteBranch.AddString(remoteBranchName);
119 CbnSelchangeRemoteBranch();
122 else
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)
135 if(pBranch&&tip)
137 CString text=pBranch->GetString();
138 CString tooltip;
140 if (text.IsEmpty())
142 pBranch->DisableTooltip();
143 return;
146 GitRev rev;
147 if (rev.GetCommit(text))
149 pBranch->DisableTooltip();
150 MessageBox(nullptr, rev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
151 return;
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)),
158 rev.GetAuthorName(),
159 rev.GetAuthorEmail(),
160 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
161 CLoglistUtils::FormatDateAndTime(rev.GetAuthorDate(), DATE_LONGDATE),
162 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE)),
163 rev.GetSubject(),
164 rev.GetBody());
166 pBranch->DisableTooltip();
168 tip->AddTool(pBranch->GetComboBoxCtrl(),tooltip);
172 void LoadBranchInfo()
174 m_ctrlLocalBranch.SetMaxHistoryItems(0x0FFFFFFF);
175 m_ctrlRemoteBranch.SetMaxHistoryItems(0x0FFFFFFF);
177 STRING_VECTOR list;
178 list.clear();
179 int current=0;
181 g_Git.GetBranchList(list,&current,CGit::BRANCH_LOCAL_F);
183 m_ctrlLocalBranch.SetList(list);
185 if(this->m_RegKeyRemoteBranch.IsEmpty())
187 list.clear();
188 g_Git.GetBranchList(list, NULL, CGit::BRANCH_REMOTE);
190 m_ctrlRemoteBranch.SetList(list);
193 else
195 m_ctrlRemoteBranch.Reset();
196 m_ctrlRemoteBranch.LoadHistory(m_RegKeyRemoteBranch,_T("sync"));
199 if(!this->m_strLocalBranch.IsEmpty())
201 m_ctrlLocalBranch.AddString(m_strLocalBranch);
203 else
205 m_ctrlLocalBranch.SetCurSel(current);
208 if(!m_strRemoteBranch.IsEmpty())
210 m_ctrlRemoteBranch.AddString(m_strRemoteBranch);
211 m_ctrlRemoteBranch.SetCurSel(m_ctrlRemoteBranch.GetCount()-1);
213 else
215 CbnSelchangeLocalBranch();
218 this->LocalBranchChange();
219 this->RemoteBranchChange();
222 public:
223 CString m_strLocalBranch;
224 CString m_strRemoteBranch;
226 void SaveHistory()
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();}