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.
22 #include "BrowseRefsDlg.h"
23 #include "MessageBox.h"
28 CString m_initialRefName
;
32 CWinThread
* m_pLoadingThread
;
33 static UINT
LoadingThreadEntry(LPVOID pVoid
)
35 return ((CChooseVersion
*)pVoid
)->LoadingThread();
37 volatile LONG m_bLoadingThreadRunning
;
40 CHistoryCombo m_ChooseVersioinBranch
;
41 CHistoryCombo m_ChooseVersioinTags
;
42 CHistoryCombo m_ChooseVersioinVersion
;
43 CButton m_RadioBranch
;
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
);
57 int radio
=m_pWin
->GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
62 case IDC_RADIO_BRANCH
:
63 this->m_ChooseVersioinBranch
.EnableWindow(TRUE
);
64 m_pWin
->GetDlgItem(IDC_BUTTON_BROWSE_REF
)->EnableWindow(TRUE
);
68 this->m_ChooseVersioinTags
.EnableWindow(TRUE
);
70 case IDC_RADIO_VERSION
:
71 this->m_ChooseVersioinVersion
.EnableWindow(TRUE
);
72 m_pWin
->GetDlgItem(IDC_BUTTON_SHOW
)->EnableWindow(TRUE
);
75 // enable version browse button if Version is selected
76 m_pWin
->GetDlgItem(IDC_BUTTON_SHOW
)->EnableWindow(radio
== IDC_RADIO_VERSION
);
80 void OnBnClickedChooseVersion()
82 // use the git log to allow selection of a version
84 // tell the dialog to use mode for selecting revisions
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
);
98 void UpdateRevsionName()
100 int radio
=m_pWin
->GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
104 this->m_VersionName
=_T("HEAD");
106 case IDC_RADIO_BRANCH
:
107 this->m_VersionName
=m_ChooseVersioinBranch
.GetString();
110 this->m_VersionName
=m_ChooseVersioinTags
.GetString();
112 case IDC_RADIO_VERSION
:
113 this->m_VersionName
=m_ChooseVersioinVersion
.GetString();
117 void SetDefaultChoose(int id
)
119 m_pWin
->CheckRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
,id
);
120 OnBnClickedChooseRadio();
123 void OnBnClickedButtonBrowseRef()
127 CString resultRef
= CBrowseRefsDlg::PickRef(false, m_VersionName
, gPickRef_All
);
128 if(resultRef
.IsEmpty())
130 SelectRef(resultRef
, false);
133 void SelectRef(CString refName
, bool bRefNameIsPossiblyNotFullName
= true)
135 if(bRefNameIsPossiblyNotFullName
)
137 //Make sure refName is a full ref name first
138 CString fullRefName
= g_Git
.GetFullRefName(refName
);
139 if(!fullRefName
.IsEmpty())
140 refName
= fullRefName
;
143 if(wcsncmp(refName
,L
"refs/",5)==0)
144 refName
= refName
.Mid(5);
145 if(wcsncmp(refName
,L
"heads/",6)==0)
147 refName
= refName
.Mid(6);
148 SetDefaultChoose(IDC_RADIO_BRANCH
);
149 m_ChooseVersioinBranch
.SetCurSel(
150 m_ChooseVersioinBranch
.FindStringExact(-1, refName
));
152 else if(wcsncmp(refName
,L
"remotes/",8)==0)
154 SetDefaultChoose(IDC_RADIO_BRANCH
);
155 m_ChooseVersioinBranch
.SetCurSel(
156 m_ChooseVersioinBranch
.FindStringExact(-1, refName
));
158 else if(wcsncmp(refName
,L
"tags/",5)==0)
160 refName
= refName
.Mid(5);
161 SetDefaultChoose(IDC_RADIO_TAGS
);
162 m_ChooseVersioinTags
.SetCurSel(
163 m_ChooseVersioinTags
.FindStringExact(-1, refName
));
167 SetDefaultChoose(IDC_RADIO_VERSION
);
168 m_ChooseVersioinVersion
.AddString(refName
);
178 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL_F
);
179 m_ChooseVersioinBranch
.AddString(list
, false);
180 m_ChooseVersioinBranch
.SetCurSel(current
);
182 m_RadioBranch
.EnableWindow(TRUE
);
185 g_Git
.GetTagList(list
);
186 m_ChooseVersioinTags
.AddString(list
, false);
187 m_ChooseVersioinTags
.SetCurSel(0);
189 m_RadioTag
.EnableWindow(TRUE
);
191 if(m_initialRefName
.IsEmpty())
194 SelectRef(m_initialRefName
);
196 InterlockedExchange(&m_bLoadingThreadRunning
, FALSE
);
201 m_ChooseVersioinBranch
.SetMaxHistoryItems(0x7FFFFFFF);
202 m_ChooseVersioinTags
.SetMaxHistoryItems(0x7FFFFFFF);
205 m_RadioBranch
.EnableWindow(FALSE
);
206 m_RadioTag
.EnableWindow(FALSE
);
208 InterlockedExchange(&m_bLoadingThreadRunning
, TRUE
);
210 if ( (m_pLoadingThread
=AfxBeginThread(LoadingThreadEntry
, this)) ==NULL
)
212 InterlockedExchange(&m_bLoadingThreadRunning
, FALSE
);
213 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
216 void WaitForFinishLoading()
218 if(m_bLoadingThreadRunning
&& m_pLoadingThread
)
220 DWORD ret
=::WaitForSingleObject(m_pLoadingThread
->m_hThread
,20000);
221 if(ret
== WAIT_TIMEOUT
)
222 ::TerminateThread(m_pLoadingThread
,0);
226 CString m_VersionName
;
228 CChooseVersion(CWnd
*win
)
236 #define CHOOSE_VERSION_DDX \
237 DDX_Control(pDX, IDC_COMBOBOXEX_BRANCH, m_ChooseVersioinBranch); \
238 DDX_Control(pDX, IDC_COMBOBOXEX_TAGS, m_ChooseVersioinTags); \
239 DDX_Control(pDX, IDC_COMBOBOXEX_VERSION, m_ChooseVersioinVersion); \
240 DDX_Control(pDX, IDC_RADIO_BRANCH, m_RadioBranch);\
241 DDX_Control(pDX, IDC_RADIO_TAGS, m_RadioTag);
243 #define CHOOSE_VERSION_EVENT\
244 ON_BN_CLICKED(IDC_RADIO_HEAD, OnBnClickedChooseRadioHost)\
245 ON_BN_CLICKED(IDC_RADIO_BRANCH, OnBnClickedChooseRadioHost)\
246 ON_BN_CLICKED(IDC_RADIO_TAGS, OnBnClickedChooseRadioHost)\
247 ON_BN_CLICKED(IDC_BUTTON_SHOW, OnBnClickedShow)\
248 ON_BN_CLICKED(IDC_RADIO_VERSION, OnBnClickedChooseRadioHost)\
249 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, OnBnClickedButtonBrowseRefHost)
251 #define CHOOSE_VERSION_ADDANCHOR \
253 AddAnchor(IDC_COMBOBOXEX_BRANCH, TOP_LEFT, TOP_RIGHT); \
254 AddAnchor(IDC_COMBOBOXEX_TAGS, TOP_LEFT, TOP_RIGHT); \
255 AddAnchor(IDC_COMBOBOXEX_VERSION, TOP_LEFT, TOP_RIGHT); \
256 AddAnchor(IDC_GROUP_BASEON, TOP_LEFT, TOP_RIGHT); \
257 AddAnchor(IDC_BUTTON_SHOW,TOP_RIGHT); \
258 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT); \
261 #define CHOOSE_EVENT_RADIO() \
262 afx_msg void OnBnClickedChooseRadioHost(){OnBnClickedChooseRadio();}\
263 afx_msg void OnBnClickedShow(){OnBnClickedChooseVersion();}\
264 afx_msg void OnBnClickedButtonBrowseRefHost(){OnBnClickedButtonBrowseRef();}