Can run cleanup without using recycle bin and add dry run option
[TortoiseGit.git] / src / TortoiseProc / CloneDlg.cpp
blob62e95c7f13a6610aece48741cd515567605f7c66
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 // CloneDlg.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "CloneDlg.h"
25 #include "BrowseFolder.h"
26 #include "MessageBox.h"
27 #include "AppUtils.h"
28 // CCloneDlg dialog
30 IMPLEMENT_DYNCREATE(CCloneDlg, CHorizontalResizableStandAloneDialog)
32 CCloneDlg::CCloneDlg(CWnd* pParent /*=NULL*/)
33 : CHorizontalResizableStandAloneDialog(CCloneDlg::IDD, pParent)
34 , m_Directory(_T(""))
36 m_bAutoloadPuttyKeyFile = CAppUtils::IsSSHPutty();
38 m_bRecursive = FALSE;
39 m_bBare = FALSE;
40 m_bBranch = FALSE;
41 m_bNoCheckout = FALSE;
42 m_bSVN = FALSE;
43 m_bSVNTrunk = FALSE;
44 m_bSVNTags = FALSE;
45 m_bSVNBranch = FALSE;
46 m_bSVNUserName = FALSE;
48 m_strSVNTrunk = _T("trunk");
49 m_strSVNTags = _T("tags");
50 m_strSVNBranchs = _T("branches");
52 m_regBrowseUrl = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\CloneBrowse"),0);
53 m_nSVNFrom = 0;
55 m_nDepth = 0;
56 m_bDepth = false;
59 CCloneDlg::~CCloneDlg()
63 void CCloneDlg::DoDataExchange(CDataExchange* pDX)
65 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
66 DDX_Control(pDX, IDC_URLCOMBO, m_URLCombo);
67 DDX_Control(pDX, IDC_PUTTYKEYFILE, m_PuttyKeyCombo);
68 DDX_Control(pDX, IDC_CLONE_BROWSE_URL, m_BrowseUrl);
69 DDX_Text(pDX, IDC_CLONE_DIR, m_Directory);
70 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD, m_bAutoloadPuttyKeyFile);
72 DDX_Check(pDX,IDC_CHECK_SVN, m_bSVN);
73 DDX_Check(pDX,IDC_CHECK_SVN_TRUNK, m_bSVNTrunk);
74 DDX_Check(pDX,IDC_CHECK_SVN_TAG, m_bSVNTags);
75 DDX_Check(pDX,IDC_CHECK_SVN_BRANCH, m_bSVNBranch);
76 DDX_Check(pDX,IDC_CHECK_SVN_FROM, m_bSVNFrom);
77 DDX_Check(pDX,IDC_CHECK_USERNAME, m_bSVNUserName);
79 DDX_Text(pDX, IDC_EDIT_SVN_TRUNK, m_strSVNTrunk);
80 DDX_Text(pDX, IDC_EDIT_SVN_TAG, m_strSVNTags);
81 DDX_Text(pDX, IDC_EDIT_SVN_BRANCH, m_strSVNBranchs);
82 DDX_Text(pDX, IDC_EDIT_SVN_FROM, this->m_nSVNFrom);
83 DDX_Text(pDX, IDC_EDIT_USERNAME,m_strUserName);
85 DDX_Check(pDX, IDC_CHECK_DEPTH, m_bDepth);
86 DDX_Check(pDX, IDC_CHECK_BARE, m_bBare);
87 DDX_Check(pDX, IDC_CHECK_RECURSIVE, m_bRecursive);
88 DDX_Text(pDX, IDC_EDIT_DEPTH,m_nDepth);
89 DDX_Check(pDX,IDC_CHECK_BRANCH, m_bBranch);
90 DDX_Text(pDX, IDC_EDIT_BRANCH, m_strBranch);
91 DDX_Check(pDX,IDC_CHECK_NOCHECKOUT, m_bNoCheckout);
94 BOOL CCloneDlg::OnInitDialog()
96 CHorizontalResizableStandAloneDialog::OnInitDialog();
97 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
99 AddAnchor(IDC_URLCOMBO, TOP_LEFT, TOP_RIGHT);
100 AddAnchor(IDC_CLONE_BROWSE_URL, TOP_RIGHT);
101 AddAnchor(IDC_CLONE_DIR, TOP_LEFT,TOP_RIGHT);
102 AddAnchor(IDC_CLONE_DIR_BROWSE, TOP_RIGHT);
103 AddAnchor(IDOK,BOTTOM_RIGHT);
104 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
106 AddAnchor(IDC_GROUP_CLONE,TOP_LEFT,TOP_RIGHT);
107 AddAnchor(IDC_PUTTYKEYFILE_BROWSE,TOP_RIGHT);
108 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
109 AddAnchor(IDC_PUTTYKEYFILE,TOP_LEFT,TOP_RIGHT);
110 AddAnchor(IDC_CLONE_GROUP_SVN,TOP_LEFT,TOP_RIGHT);
111 AddAnchor(IDHELP, BOTTOM_RIGHT);
113 AdjustControlSize(IDC_CHECK_DEPTH);
114 AdjustControlSize(IDC_CHECK_RECURSIVE);
115 AdjustControlSize(IDC_CHECK_BARE);
116 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
117 AdjustControlSize(IDC_CHECK_SVN);
118 AdjustControlSize(IDC_CHECK_SVN_TRUNK);
119 AdjustControlSize(IDC_CHECK_SVN_TAG);
120 AdjustControlSize(IDC_CHECK_SVN_BRANCH);
121 AdjustControlSize(IDC_CHECK_SVN_FROM);
122 AdjustControlSize(IDC_CHECK_USERNAME);
124 m_tooltips.Create(this);
125 CString tt;
126 tt.LoadString(IDS_CLONE_DEPTH_TT);
127 m_tooltips.AddTool(IDC_EDIT_DEPTH,tt);
128 m_tooltips.AddTool(IDC_CHECK_DEPTH,tt);
130 this->AddOthersToAnchor();
132 m_URLCombo.SetURLHistory(TRUE);
133 m_URLCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
134 if(m_URL.IsEmpty())
136 CString str=CAppUtils::GetClipboardLink();
137 str.Trim();
138 if(str.IsEmpty())
139 m_URLCombo.SetCurSel(0);
140 else
141 m_URLCombo.SetWindowText(str);
143 else
144 m_URLCombo.SetWindowText(m_URL);
146 CWnd *window=this->GetDlgItem(IDC_CLONE_DIR);
147 if(window)
148 SHAutoComplete(window->m_hWnd, SHACF_FILESYSTEM);
150 this->m_BrowseUrl.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_DIR)));
151 this->m_BrowseUrl.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_WEB)));
152 m_BrowseUrl.SetCurrentEntry(m_regBrowseUrl);
154 m_PuttyKeyCombo.SetPathHistory(TRUE);
155 m_PuttyKeyCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
156 m_PuttyKeyCombo.SetCurSel(0);
158 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow( CAppUtils::IsSSHPutty() );
159 this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);
160 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);
162 EnableSaveRestore(_T("CloneDlg"));
164 OnBnClickedCheckSvn();
165 OnBnClickedCheckDepth();
166 OnBnClickedCheckBranch();
167 return TRUE; // return TRUE unless you set the focus to a control
170 BEGIN_MESSAGE_MAP(CCloneDlg, CHorizontalResizableStandAloneDialog)
171 ON_BN_CLICKED(IDC_CLONE_BROWSE_URL, &CCloneDlg::OnBnClickedCloneBrowseUrl)
172 ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE, &CCloneDlg::OnBnClickedCloneDirBrowse)
173 ON_BN_CLICKED(IDC_CHECK_BRANCH, &CCloneDlg::OnBnClickedCheckBranch)
174 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE, &CCloneDlg::OnBnClickedPuttykeyfileBrowse)
175 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD, &CCloneDlg::OnBnClickedPuttykeyAutoload)
176 ON_CBN_EDITCHANGE(IDC_URLCOMBO, &CCloneDlg::OnCbnEditchangeUrlcombo)
177 ON_BN_CLICKED(IDC_CHECK_SVN, &CCloneDlg::OnBnClickedCheckSvn)
178 ON_BN_CLICKED(IDC_CHECK_SVN_TRUNK, &CCloneDlg::OnBnClickedCheckSvnTrunk)
179 ON_BN_CLICKED(IDC_CHECK_SVN_TAG, &CCloneDlg::OnBnClickedCheckSvnTag)
180 ON_BN_CLICKED(IDC_CHECK_SVN_BRANCH, &CCloneDlg::OnBnClickedCheckSvnBranch)
181 ON_BN_CLICKED(IDC_CHECK_SVN_FROM, &CCloneDlg::OnBnClickedCheckSvnFrom)
182 ON_BN_CLICKED(IDC_CHECK_DEPTH, &CCloneDlg::OnBnClickedCheckDepth)
183 ON_BN_CLICKED(IDC_CHECK_BARE, &CCloneDlg::OnBnClickedCheckBare)
184 ON_BN_CLICKED(IDC_CHECK_RECURSIVE, &CCloneDlg::OnBnClickedCheckRecursive)
185 ON_BN_CLICKED(IDC_CHECK_USERNAME, &CCloneDlg::OnBnClickedCheckUsername)
186 END_MESSAGE_MAP()
188 // CCloneDlg message handlers
190 void CCloneDlg::OnOK()
192 this->m_URLCombo.GetWindowTextW(m_URL);
193 m_URL.Trim();
194 UpdateData(TRUE);
195 if(m_URL.IsEmpty() || m_Directory.IsEmpty())
197 CMessageBox::Show(NULL, IDS_PROC_CLONE_URLDIREMPTY, IDS_APPNAME, MB_OK);
198 return;
201 if (m_bBranch && !g_Git.IsBranchNameValid(m_strBranch))
203 ShowEditBalloon(IDC_EDIT_BRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
204 return;
207 m_URLCombo.SaveHistory();
208 m_PuttyKeyCombo.SaveHistory();
210 this->m_PuttyKeyCombo.GetWindowText(m_strPuttyKeyFile);
211 CResizableDialog::OnOK();
215 void CCloneDlg::OnCancel()
217 CResizableDialog::OnCancel();
220 void CCloneDlg::OnBnClickedCloneBrowseUrl()
222 CBrowseFolder browseFolder;
223 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
224 CString strCloneDirectory;
226 int sel = (int)this->m_BrowseUrl.GetCurrentEntry();
227 this->m_regBrowseUrl = sel;
229 if( sel == 1 )
231 CString str;
232 m_URLCombo.GetWindowText(str);
233 ShellExecute(NULL, _T("open"), str.Trim(), NULL,NULL, SW_SHOW);
234 return ;
237 this->m_URLCombo.GetWindowTextW(strCloneDirectory);
238 if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK)
240 this->m_URLCombo.SetWindowTextW(strCloneDirectory);
244 void CCloneDlg::OnBnClickedCloneDirBrowse()
246 CBrowseFolder browseFolder;
247 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
248 CString strCloneDirectory = this->m_Directory;
249 if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK)
251 UpdateData(TRUE);
252 m_Directory = strCloneDirectory;
253 UpdateData(FALSE);
257 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()
259 CFileDialog dlg(TRUE,NULL,
260 NULL,
261 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
262 CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER)));
264 this->UpdateData();
265 if(dlg.DoModal()==IDOK)
267 this->m_PuttyKeyCombo.SetWindowText( dlg.GetPathName() );
272 void CCloneDlg::OnBnClickedPuttykeyAutoload()
274 this->UpdateData();
275 this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);
276 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);
279 void CCloneDlg::OnCbnEditchangeUrlcombo()
281 this->UpdateData();
282 CString url;
283 m_URLCombo.GetWindowText(url);
284 url.Trim();
286 if(m_OldURL == url )
287 return;
289 m_OldURL=url;
291 //if(url.IsEmpty())
292 // return;
294 CString old;
295 old=m_ModuleName;
297 url.Replace(_T('\\'),_T('/'));
299 // add compatibility for Google Code git urls
300 if (url.GetLength() > 0 && url[url.GetLength()-1] == _T('/')) {
301 url = url.Left(url.GetLength() - 1);
304 int start=url.ReverseFind(_T('/'));
305 if(start<0)
307 start = url.ReverseFind(_T(':'));
308 if(start <0)
309 start = url.ReverseFind(_T('@'));
311 if(start<0)
312 start = 0;
314 CString temp;
315 temp=url.Mid(start+1);
317 temp=temp.MakeLower();
319 // we've to check whether the URL ends with .git (instead of using the first .git)
320 int end = temp.Right(4) == _T(".git") ? (temp.GetLength() - 4) : temp.GetLength();
322 //CString modulename;
323 m_ModuleName=url.Mid(start+1,end);
325 start = m_Directory.ReverseFind(_T('\\'));
326 if(start <0 )
327 start = m_Directory.ReverseFind(_T('/'));
328 if(start <0 )
329 start =0;
331 int dirstart=m_Directory.Find(old,start);
332 if(dirstart>=0 && (dirstart+old.GetLength() == m_Directory.GetLength()) )
334 m_Directory=m_Directory.Left(dirstart);
335 m_Directory+=m_ModuleName;
338 else
340 if(m_Directory.GetLength()>0 &&
341 (m_Directory[m_Directory.GetLength()-1] != _T('\\') &&
342 m_Directory[m_Directory.GetLength()-1] != _T('/') ) )
344 m_Directory += _T('\\');
346 m_Directory += m_ModuleName;
349 if(m_Directory.GetLength()>0)
351 if( m_Directory[m_Directory.GetLength()-1] == _T('\\') ||
352 m_Directory[m_Directory.GetLength()-1] == _T('/')
355 m_Directory=m_Directory.Left(m_Directory.GetLength()-1);
359 this->UpdateData(FALSE);
362 void CCloneDlg::OnBnClickedCheckSvn()
364 this->UpdateData();
366 if(this->m_bSVN)
368 CString str;
369 m_URLCombo.GetWindowText(str);
371 while(str.GetLength()>=1 &&
372 str[str.GetLength()-1] == _T('\\') &&
373 str[str.GetLength()-1] == _T('/'))
375 str=str.Left(str.GetLength()-1);
377 if(str.GetLength()>=5 && (str.Right(5).MakeLower() == _T("trunk") ))
379 this->m_bSVNBranch=this->m_bSVNTags=this->m_bSVNTrunk = FALSE;
381 else
383 this->m_bSVNBranch=this->m_bSVNTags=this->m_bSVNTrunk = TRUE;
385 m_bDepth = false;
386 m_bBare = false;
387 m_bRecursive = false;
388 m_bBranch = FALSE;
389 this->UpdateData(FALSE);
390 OnBnClickedCheckDepth();
392 this->GetDlgItem(IDC_CHECK_DEPTH)->EnableWindow(!m_bSVN);
393 this->GetDlgItem(IDC_CHECK_BARE)->EnableWindow(!m_bSVN);
394 this->GetDlgItem(IDC_CHECK_RECURSIVE)->EnableWindow(!m_bSVN);
395 this->GetDlgItem(IDC_CHECK_BRANCH)->EnableWindow(!m_bSVN);
396 this->GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(!m_bSVN);
397 OnBnClickedCheckSvnTrunk();
398 OnBnClickedCheckSvnTag();
399 OnBnClickedCheckSvnBranch();
400 OnBnClickedCheckSvnFrom();
401 OnBnClickedCheckUsername();
404 void CCloneDlg::OnBnClickedCheckSvnTrunk()
406 UpdateData(TRUE);
407 this->GetDlgItem(IDC_CHECK_SVN_TRUNK)->EnableWindow(this->m_bSVN);
408 this->GetDlgItem(IDC_EDIT_SVN_TRUNK)->EnableWindow(this->m_bSVNTrunk&&this->m_bSVN);
411 void CCloneDlg::OnBnClickedCheckSvnTag()
413 UpdateData(TRUE);
414 this->GetDlgItem(IDC_CHECK_SVN_TAG)->EnableWindow(this->m_bSVN);
415 this->GetDlgItem(IDC_EDIT_SVN_TAG)->EnableWindow(this->m_bSVNTags&&this->m_bSVN);
418 void CCloneDlg::OnBnClickedCheckSvnBranch()
420 UpdateData(TRUE);
421 this->GetDlgItem(IDC_CHECK_SVN_BRANCH)->EnableWindow(this->m_bSVN);
422 this->GetDlgItem(IDC_EDIT_SVN_BRANCH)->EnableWindow(this->m_bSVNBranch&&this->m_bSVN);
425 void CCloneDlg::OnBnClickedCheckSvnFrom()
427 UpdateData(TRUE);
428 this->GetDlgItem(IDC_CHECK_SVN_FROM)->EnableWindow(this->m_bSVN);
429 this->GetDlgItem(IDC_EDIT_SVN_FROM)->EnableWindow(this->m_bSVNFrom&&this->m_bSVN);
432 void CCloneDlg::OnBnClickedCheckRecursive()
434 UpdateData(TRUE);
436 void CCloneDlg::OnBnClickedCheckBare()
438 UpdateData(TRUE);
440 void CCloneDlg::OnBnClickedCheckDepth()
442 UpdateData(TRUE);
443 this->GetDlgItem(IDC_EDIT_DEPTH)->EnableWindow(this->m_bDepth);
446 void CCloneDlg::OnBnClickedCheckBranch()
448 UpdateData(TRUE);
449 this->GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(this->m_bBranch);
452 BOOL CCloneDlg::PreTranslateMessage(MSG* pMsg)
454 m_tooltips.RelayEvent(pMsg);
456 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
459 void CCloneDlg::OnBnClickedCheckUsername()
461 UpdateData(TRUE);
462 this->GetDlgItem(IDC_CHECK_USERNAME)->EnableWindow(this->m_bSVN);
463 this->GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(this->m_bSVNUserName && this->m_bSVN);