DeleteRemoteTagDlg: Allow to delete multiple tags at once
[TortoiseGit.git] / src / TortoiseProc / ChooseVersion.h
blobc45059ec10f0e90d31b75f5cd28f33974636c41c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-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.
19 #pragma once
20 #include "afxwin.h"
21 #include "LogDlg.h"
22 #include "BrowseRefsDlg.h"
23 #include "MessageBox.h"
25 class CChooseVersion
27 public:
28 CString m_initialRefName;
30 private:
31 CWnd * m_pWin;
32 CWinThread* m_pLoadingThread;
33 static UINT LoadingThreadEntry(LPVOID pVoid)
35 return ((CChooseVersion*)pVoid)->LoadingThread();
37 volatile LONG m_bLoadingThreadRunning;
39 protected:
40 CHistoryCombo m_ChooseVersioinBranch;
41 CHistoryCombo m_ChooseVersioinTags;
42 CHistoryCombo m_ChooseVersioinVersion;
43 CButton m_RadioBranch;
44 CButton m_RadioTag;
46 //Notification when version changed. Can be implemented in derived classes.
47 virtual void OnVersionChanged(){}
49 afx_msg void OnBnClickedChooseRadio()
51 this->m_ChooseVersioinTags.EnableWindow(FALSE);
52 this->m_ChooseVersioinBranch.EnableWindow(FALSE);
53 this->m_ChooseVersioinVersion.EnableWindow(FALSE);
54 m_pWin->GetDlgItem(IDC_BUTTON_BROWSE_REF)->EnableWindow(FALSE);
55 m_pWin->GetDlgItem(IDC_BUTTON_SHOW)->EnableWindow(FALSE);
56 m_bIsBranch = false;
57 int radio=m_pWin->GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
58 switch (radio)
60 case IDC_RADIO_HEAD:
61 break;
62 case IDC_RADIO_BRANCH:
63 this->m_ChooseVersioinBranch.EnableWindow(TRUE);
64 m_pWin->GetDlgItem(IDC_BUTTON_BROWSE_REF)->EnableWindow(TRUE);
65 m_bIsBranch = true;
66 break;
67 case IDC_RADIO_TAGS:
68 this->m_ChooseVersioinTags.EnableWindow(TRUE);
69 break;
70 case IDC_RADIO_VERSION:
71 this->m_ChooseVersioinVersion.EnableWindow(TRUE);
72 m_pWin->GetDlgItem(IDC_BUTTON_SHOW)->EnableWindow(TRUE);
73 break;
75 // enable version browse button if Version is selected
76 m_pWin->GetDlgItem(IDC_BUTTON_SHOW)->EnableWindow(radio == IDC_RADIO_VERSION);
77 OnVersionChanged();
80 void OnBnClickedChooseVersion()
82 // use the git log to allow selection of a version
83 CLogDlg dlg;
84 // tell the dialog to use mode for selecting revisions
85 dlg.SetSelect(true);
86 // only one revision must be selected however
87 dlg.SingleSelection(true);
88 if ( dlg.DoModal() == IDOK )
90 // get selected hash if any
91 CString selectedHash = dlg.GetSelectedHash();
92 // load into window, do this even if empty so that it is clear that nothing has been selected
93 m_ChooseVersioinVersion.SetWindowText( selectedHash );
94 OnVersionChanged();
98 void UpdateRevsionName()
100 int radio=m_pWin->GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
101 switch (radio)
103 case IDC_RADIO_HEAD:
104 this->m_VersionName=_T("HEAD");
105 break;
106 case IDC_RADIO_BRANCH:
107 this->m_VersionName=m_ChooseVersioinBranch.GetString();
108 if (!g_Git.IsBranchTagNameUnique(this->m_VersionName))
109 this->m_VersionName = L"refs/heads/" + this->m_VersionName;
110 break;
111 case IDC_RADIO_TAGS:
112 this->m_VersionName = m_ChooseVersioinTags.GetString();
113 if (!g_Git.IsBranchTagNameUnique(this->m_VersionName))
114 this->m_VersionName = L"refs/tags/" + m_ChooseVersioinTags.GetString();
115 break;
116 case IDC_RADIO_VERSION:
117 this->m_VersionName=m_ChooseVersioinVersion.GetString();
118 break;
121 void SetDefaultChoose(int id)
123 m_pWin->CheckRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION,id);
124 OnBnClickedChooseRadio();
127 void OnBnClickedButtonBrowseRef()
129 CString origRef;
130 UpdateRevsionName();
131 CString resultRef = CBrowseRefsDlg::PickRef(false, m_VersionName, gPickRef_All);
132 if(resultRef.IsEmpty())
133 return;
134 SelectRef(resultRef, false);
137 void SelectRef(CString refName, bool bRefNameIsPossiblyNotFullName = true)
139 if(bRefNameIsPossiblyNotFullName)
141 //Make sure refName is a full ref name first
142 CString fullRefName = g_Git.GetFullRefName(refName);
143 if(!fullRefName.IsEmpty())
144 refName = fullRefName;
147 if(wcsncmp(refName,L"refs/",5)==0)
148 refName = refName.Mid(5);
149 if(wcsncmp(refName,L"heads/",6)==0)
151 refName = refName.Mid(6);
152 SetDefaultChoose(IDC_RADIO_BRANCH);
153 m_ChooseVersioinBranch.SetCurSel(
154 m_ChooseVersioinBranch.FindStringExact(-1, refName));
156 else if(wcsncmp(refName,L"remotes/",8)==0)
158 SetDefaultChoose(IDC_RADIO_BRANCH);
159 m_ChooseVersioinBranch.SetCurSel(
160 m_ChooseVersioinBranch.FindStringExact(-1, refName));
162 else if(wcsncmp(refName,L"tags/",5)==0)
164 refName = refName.Mid(5);
165 refName.Replace(_T("^{}"), _T(""));
166 SetDefaultChoose(IDC_RADIO_TAGS);
167 m_ChooseVersioinTags.SetCurSel(
168 m_ChooseVersioinTags.FindStringExact(-1, refName));
170 else
172 SetDefaultChoose(IDC_RADIO_VERSION);
173 m_ChooseVersioinVersion.AddString(refName);
175 OnVersionChanged();
178 UINT LoadingThread()
180 STRING_VECTOR list;
182 int current;
183 g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL_F);
184 m_ChooseVersioinBranch.AddString(list, false);
185 m_ChooseVersioinBranch.SetCurSel(current);
187 m_RadioBranch.EnableWindow(TRUE);
189 list.clear();
190 g_Git.GetTagList(list);
191 m_ChooseVersioinTags.AddString(list, false);
192 m_ChooseVersioinTags.SetCurSel(0);
194 m_RadioTag.EnableWindow(TRUE);
196 if(m_initialRefName.IsEmpty())
197 OnVersionChanged();
198 else
199 SelectRef(m_initialRefName);
201 InterlockedExchange(&m_bLoadingThreadRunning, FALSE);
202 return 0;
204 void Init()
206 m_ChooseVersioinBranch.SetMaxHistoryItems(0x7FFFFFFF);
207 m_ChooseVersioinTags.SetMaxHistoryItems(0x7FFFFFFF);
209 m_bIsBranch = false;
210 m_RadioBranch.EnableWindow(FALSE);
211 m_RadioTag.EnableWindow(FALSE);
213 InterlockedExchange(&m_bLoadingThreadRunning, TRUE);
215 if ( (m_pLoadingThread=AfxBeginThread(LoadingThreadEntry, this)) ==NULL)
217 InterlockedExchange(&m_bLoadingThreadRunning, FALSE);
218 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
221 void WaitForFinishLoading()
223 if(m_bLoadingThreadRunning && m_pLoadingThread)
225 DWORD ret =::WaitForSingleObject(m_pLoadingThread->m_hThread,20000);
226 if(ret == WAIT_TIMEOUT)
227 ::TerminateThread(m_pLoadingThread,0);
230 public:
231 CString m_VersionName;
232 bool m_bIsBranch;
233 CChooseVersion(CWnd *win)
235 m_pWin=win;
241 #define CHOOSE_VERSION_DDX \
242 DDX_Control(pDX, IDC_COMBOBOXEX_BRANCH, m_ChooseVersioinBranch); \
243 DDX_Control(pDX, IDC_COMBOBOXEX_TAGS, m_ChooseVersioinTags); \
244 DDX_Control(pDX, IDC_COMBOBOXEX_VERSION, m_ChooseVersioinVersion); \
245 DDX_Control(pDX, IDC_RADIO_BRANCH, m_RadioBranch);\
246 DDX_Control(pDX, IDC_RADIO_TAGS, m_RadioTag);
248 #define CHOOSE_VERSION_EVENT\
249 ON_BN_CLICKED(IDC_RADIO_HEAD, OnBnClickedChooseRadioHost)\
250 ON_BN_CLICKED(IDC_RADIO_BRANCH, OnBnClickedChooseRadioHost)\
251 ON_BN_CLICKED(IDC_RADIO_TAGS, OnBnClickedChooseRadioHost)\
252 ON_BN_CLICKED(IDC_BUTTON_SHOW, OnBnClickedShow)\
253 ON_BN_CLICKED(IDC_RADIO_VERSION, OnBnClickedChooseRadioHost)\
254 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, OnBnClickedButtonBrowseRefHost)
256 #define CHOOSE_VERSION_ADDANCHOR \
258 AddAnchor(IDC_COMBOBOXEX_BRANCH, TOP_LEFT, TOP_RIGHT); \
259 AddAnchor(IDC_COMBOBOXEX_TAGS, TOP_LEFT, TOP_RIGHT); \
260 AddAnchor(IDC_COMBOBOXEX_VERSION, TOP_LEFT, TOP_RIGHT); \
261 AddAnchor(IDC_GROUP_BASEON, TOP_LEFT, TOP_RIGHT); \
262 AddAnchor(IDC_BUTTON_SHOW,TOP_RIGHT); \
263 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT); \
266 #define CHOOSE_EVENT_RADIO() \
267 afx_msg void OnBnClickedChooseRadioHost(){OnBnClickedChooseRadio();}\
268 afx_msg void OnBnClickedShow(){OnBnClickedChooseVersion();}\
269 afx_msg void OnBnClickedButtonBrowseRefHost(){OnBnClickedButtonBrowseRef();}