1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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
);
56 int radio
=m_pWin
->GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
61 case IDC_RADIO_BRANCH
:
62 this->m_ChooseVersioinBranch
.EnableWindow(TRUE
);
63 m_pWin
->GetDlgItem(IDC_BUTTON_BROWSE_REF
)->EnableWindow(TRUE
);
66 this->m_ChooseVersioinTags
.EnableWindow(TRUE
);
68 case IDC_RADIO_VERSION
:
69 this->m_ChooseVersioinVersion
.EnableWindow(TRUE
);
70 m_pWin
->GetDlgItem(IDC_BUTTON_SHOW
)->EnableWindow(TRUE
);
73 // enable version browse button if Version is selected
74 m_pWin
->GetDlgItem(IDC_BUTTON_SHOW
)->EnableWindow(radio
== IDC_RADIO_VERSION
);
78 void OnBnClickedChooseVersion()
80 // use the git log to allow selection of a version
82 // tell the dialog to use mode for selecting revisions
84 // only one revision must be selected however
85 dlg
.SingleSelection(true);
86 if ( dlg
.DoModal() == IDOK
)
88 // get selected hash if any
89 CString selectedHash
= dlg
.GetSelectedHash();
90 // load into window, do this even if empty so that it is clear that nothing has been selected
91 m_ChooseVersioinVersion
.SetWindowText( selectedHash
);
96 void UpdateRevsionName()
98 int radio
=m_pWin
->GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
102 this->m_VersionName
=_T("HEAD");
104 case IDC_RADIO_BRANCH
:
105 this->m_VersionName
=m_ChooseVersioinBranch
.GetString();
108 this->m_VersionName
=m_ChooseVersioinTags
.GetString();
110 case IDC_RADIO_VERSION
:
111 this->m_VersionName
=m_ChooseVersioinVersion
.GetString();
115 void SetDefaultChoose(int id
)
117 m_pWin
->CheckRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
,id
);
118 OnBnClickedChooseRadio();
121 void OnBnClickedButtonBrowseRef()
125 CString resultRef
= CBrowseRefsDlg::PickRef(false, m_VersionName
, gPickRef_All
);
126 if(resultRef
.IsEmpty())
128 SelectRef(resultRef
, false);
131 void SelectRef(CString refName
, bool bRefNameIsPossiblyNotFullName
= true)
133 if(bRefNameIsPossiblyNotFullName
)
135 //Make sure refName is a full ref name first
136 CString fullRefName
= g_Git
.GetFullRefName(refName
);
137 if(!fullRefName
.IsEmpty())
138 refName
= fullRefName
;
141 if(wcsncmp(refName
,L
"refs/",5)==0)
142 refName
= refName
.Mid(5);
143 if(wcsncmp(refName
,L
"heads/",6)==0)
145 refName
= refName
.Mid(6);
146 SetDefaultChoose(IDC_RADIO_BRANCH
);
147 m_ChooseVersioinBranch
.SetCurSel(
148 m_ChooseVersioinBranch
.FindStringExact(-1, refName
));
150 else if(wcsncmp(refName
,L
"remotes/",8)==0)
152 SetDefaultChoose(IDC_RADIO_BRANCH
);
153 m_ChooseVersioinBranch
.SetCurSel(
154 m_ChooseVersioinBranch
.FindStringExact(-1, refName
));
156 else if(wcsncmp(refName
,L
"tags/",5)==0)
158 refName
= refName
.Mid(5);
159 SetDefaultChoose(IDC_RADIO_TAGS
);
160 m_ChooseVersioinTags
.SetCurSel(
161 m_ChooseVersioinTags
.FindStringExact(-1, refName
));
165 SetDefaultChoose(IDC_RADIO_VERSION
);
166 m_ChooseVersioinVersion
.AddString(refName
);
176 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL_F
);
177 m_ChooseVersioinBranch
.AddString(list
, false);
178 m_ChooseVersioinBranch
.SetCurSel(current
);
180 m_RadioBranch
.EnableWindow(TRUE
);
183 g_Git
.GetTagList(list
);
184 m_ChooseVersioinTags
.AddString(list
, false);
185 m_ChooseVersioinTags
.SetCurSel(0);
187 m_RadioTag
.EnableWindow(TRUE
);
189 if(m_initialRefName
.IsEmpty())
192 SelectRef(m_initialRefName
);
194 InterlockedExchange(&m_bLoadingThreadRunning
, FALSE
);
199 m_ChooseVersioinBranch
.SetMaxHistoryItems(0x7FFFFFFF);
200 m_ChooseVersioinTags
.SetMaxHistoryItems(0x7FFFFFFF);
202 m_RadioBranch
.EnableWindow(FALSE
);
203 m_RadioTag
.EnableWindow(FALSE
);
205 InterlockedExchange(&m_bLoadingThreadRunning
, TRUE
);
207 if ( (m_pLoadingThread
=AfxBeginThread(LoadingThreadEntry
, this)) ==NULL
)
209 InterlockedExchange(&m_bLoadingThreadRunning
, FALSE
);
210 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
213 void WaitForFinishLoading()
215 if(m_bLoadingThreadRunning
&& m_pLoadingThread
)
217 DWORD ret
=::WaitForSingleObject(m_pLoadingThread
->m_hThread
,20000);
218 if(ret
== WAIT_TIMEOUT
)
219 ::TerminateThread(m_pLoadingThread
,0);
223 CString m_VersionName
;
224 CChooseVersion(CWnd
*win
)
232 #define CHOOSE_VERSION_DDX \
233 DDX_Control(pDX, IDC_COMBOBOXEX_BRANCH, m_ChooseVersioinBranch); \
234 DDX_Control(pDX, IDC_COMBOBOXEX_TAGS, m_ChooseVersioinTags); \
235 DDX_Control(pDX, IDC_COMBOBOXEX_VERSION, m_ChooseVersioinVersion); \
236 DDX_Control(pDX, IDC_RADIO_BRANCH, m_RadioBranch);\
237 DDX_Control(pDX, IDC_RADIO_TAGS, m_RadioTag);
239 #define CHOOSE_VERSION_EVENT\
240 ON_BN_CLICKED(IDC_RADIO_HEAD, OnBnClickedChooseRadioHost)\
241 ON_BN_CLICKED(IDC_RADIO_BRANCH, OnBnClickedChooseRadioHost)\
242 ON_BN_CLICKED(IDC_RADIO_TAGS, OnBnClickedChooseRadioHost)\
243 ON_BN_CLICKED(IDC_BUTTON_SHOW, OnBnClickedShow)\
244 ON_BN_CLICKED(IDC_RADIO_VERSION, OnBnClickedChooseRadioHost)\
245 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, OnBnClickedButtonBrowseRefHost)
247 #define CHOOSE_VERSION_ADDANCHOR \
249 AddAnchor(IDC_COMBOBOXEX_BRANCH, TOP_LEFT, TOP_RIGHT); \
250 AddAnchor(IDC_COMBOBOXEX_TAGS, TOP_LEFT, TOP_RIGHT); \
251 AddAnchor(IDC_COMBOBOXEX_VERSION, TOP_LEFT, TOP_RIGHT); \
252 AddAnchor(IDC_GROUP_BASEON, TOP_LEFT, TOP_RIGHT); \
253 AddAnchor(IDC_BUTTON_SHOW,TOP_RIGHT); \
254 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT); \
257 #define CHOOSE_EVENT_RADIO() \
258 afx_msg void OnBnClickedChooseRadioHost(){OnBnClickedChooseRadio();}\
259 afx_msg void OnBnClickedShow(){OnBnClickedChooseVersion();}\
260 afx_msg void OnBnClickedButtonBrowseRefHost(){OnBnClickedButtonBrowseRef();}