1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-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 // CloneDlg.cpp : implementation file
23 #include "TortoiseProc.h"
25 #include "BrowseFolder.h"
26 #include "MessageBox.h"
30 IMPLEMENT_DYNCREATE(CCloneDlg
, CHorizontalResizableStandAloneDialog
)
32 CCloneDlg::CCloneDlg(CWnd
* pParent
/*=NULL*/)
33 : CHorizontalResizableStandAloneDialog(CCloneDlg::IDD
, pParent
)
40 m_bNoCheckout
= FALSE
;
46 m_bSVNUserName
= FALSE
;
49 m_strSVNTrunk
= _T("trunk");
50 m_strSVNTags
= _T("tags");
51 m_strSVNBranchs
= _T("branches");
53 m_regBrowseUrl
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\CloneBrowse"),0);
54 m_regCloneDir
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\CloneDir"));
55 m_regUseSSHKey
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\CloneUseSSHKey"), TRUE
);
58 m_bAutoloadPuttyKeyFile
= m_regUseSSHKey
&& CAppUtils::IsSSHPutty();
65 CCloneDlg::~CCloneDlg()
69 void CCloneDlg::DoDataExchange(CDataExchange
* pDX
)
71 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
72 DDX_Control(pDX
, IDC_URLCOMBO
, m_URLCombo
);
73 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
74 DDX_Control(pDX
, IDC_CLONE_BROWSE_URL
, m_BrowseUrl
);
75 DDX_Text(pDX
, IDC_CLONE_DIR
, m_Directory
);
76 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
78 DDX_Check(pDX
,IDC_CHECK_SVN
, m_bSVN
);
79 DDX_Check(pDX
,IDC_CHECK_SVN_TRUNK
, m_bSVNTrunk
);
80 DDX_Check(pDX
,IDC_CHECK_SVN_TAG
, m_bSVNTags
);
81 DDX_Check(pDX
,IDC_CHECK_SVN_BRANCH
, m_bSVNBranch
);
82 DDX_Check(pDX
,IDC_CHECK_SVN_FROM
, m_bSVNFrom
);
83 DDX_Check(pDX
,IDC_CHECK_USERNAME
, m_bSVNUserName
);
85 DDX_Text(pDX
, IDC_EDIT_SVN_TRUNK
, m_strSVNTrunk
);
86 DDX_Text(pDX
, IDC_EDIT_SVN_TAG
, m_strSVNTags
);
87 DDX_Text(pDX
, IDC_EDIT_SVN_BRANCH
, m_strSVNBranchs
);
88 DDX_Text(pDX
, IDC_EDIT_SVN_FROM
, this->m_nSVNFrom
);
89 DDX_Text(pDX
, IDC_EDIT_USERNAME
,m_strUserName
);
91 DDX_Check(pDX
, IDC_CHECK_DEPTH
, m_bDepth
);
92 DDX_Check(pDX
, IDC_CHECK_BARE
, m_bBare
);
93 DDX_Check(pDX
, IDC_CHECK_RECURSIVE
, m_bRecursive
);
94 DDX_Text(pDX
, IDC_EDIT_DEPTH
,m_nDepth
);
95 DDX_Check(pDX
,IDC_CHECK_BRANCH
, m_bBranch
);
96 DDX_Text(pDX
, IDC_EDIT_BRANCH
, m_strBranch
);
97 DDX_Check(pDX
, IDC_CHECK_ORIGIN
, m_bOrigin
);
98 DDX_Text(pDX
, IDC_EDIT_ORIGIN
, m_strOrigin
);
99 DDX_Check(pDX
,IDC_CHECK_NOCHECKOUT
, m_bNoCheckout
);
102 BOOL
CCloneDlg::OnInitDialog()
104 CHorizontalResizableStandAloneDialog::OnInitDialog();
105 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
107 AddAnchor(IDC_URLCOMBO
, TOP_LEFT
, TOP_RIGHT
);
108 AddAnchor(IDC_CLONE_BROWSE_URL
, TOP_RIGHT
);
109 AddAnchor(IDC_CLONE_DIR
, TOP_LEFT
,TOP_RIGHT
);
110 AddAnchor(IDC_CLONE_DIR_BROWSE
, TOP_RIGHT
);
111 AddAnchor(IDOK
,BOTTOM_RIGHT
);
112 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
114 AddAnchor(IDC_GROUP_CLONE
,TOP_LEFT
,TOP_RIGHT
);
115 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,TOP_RIGHT
);
116 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
117 AddAnchor(IDC_PUTTYKEYFILE
,TOP_LEFT
,TOP_RIGHT
);
118 AddAnchor(IDC_CLONE_GROUP_SVN
,TOP_LEFT
,TOP_RIGHT
);
119 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
121 AdjustControlSize(IDC_CHECK_DEPTH
);
122 AdjustControlSize(IDC_CHECK_RECURSIVE
);
123 AdjustControlSize(IDC_CHECK_BARE
);
124 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
125 AdjustControlSize(IDC_CHECK_SVN
);
126 AdjustControlSize(IDC_CHECK_SVN_TRUNK
);
127 AdjustControlSize(IDC_CHECK_SVN_TAG
);
128 AdjustControlSize(IDC_CHECK_SVN_BRANCH
);
129 AdjustControlSize(IDC_CHECK_SVN_FROM
);
130 AdjustControlSize(IDC_CHECK_USERNAME
);
133 tt
.LoadString(IDS_CLONE_DEPTH_TT
);
134 m_tooltips
.AddTool(IDC_EDIT_DEPTH
,tt
);
135 m_tooltips
.AddTool(IDC_CHECK_DEPTH
,tt
);
137 this->AddOthersToAnchor();
139 if (m_Directory
.IsEmpty())
141 CString dir
= m_regCloneDir
;
142 int index
= dir
.ReverseFind('\\');
144 dir
= dir
.Left(index
);
147 if (m_Directory
.IsEmpty())
149 TCHAR szPath
[MAX_PATH
] = {0};
150 if (SUCCEEDED(SHGetFolderPath(NULL
, CSIDL_PERSONAL
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, szPath
)))
151 m_Directory
= szPath
;
155 m_URLCombo
.SetCaseSensitive(TRUE
);
156 m_URLCombo
.SetURLHistory(TRUE
);
157 m_URLCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
160 CString str
= CAppUtils::GetClipboardLink(_T("git clone "));
163 m_URLCombo
.SetCurSel(0);
165 m_URLCombo
.SetWindowText(str
);
168 m_URLCombo
.SetWindowText(m_URL
);
170 CWnd
*window
=this->GetDlgItem(IDC_CLONE_DIR
);
172 SHAutoComplete(window
->m_hWnd
, SHACF_FILESYSTEM
);
174 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_DIR
)));
175 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_WEB
)));
176 m_BrowseUrl
.SetCurrentEntry(m_regBrowseUrl
);
178 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
179 m_PuttyKeyCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
180 m_PuttyKeyCombo
.SetCurSel(0);
182 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow( CAppUtils::IsSSHPutty() );
183 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
184 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
186 EnableSaveRestore(_T("CloneDlg"));
188 OnBnClickedCheckSvn();
189 OnBnClickedCheckDepth();
190 OnBnClickedCheckBranch();
191 OnBnClickedCheckOrigin();
192 return TRUE
; // return TRUE unless you set the focus to a control
195 BEGIN_MESSAGE_MAP(CCloneDlg
, CHorizontalResizableStandAloneDialog
)
196 ON_BN_CLICKED(IDC_CLONE_BROWSE_URL
, &CCloneDlg::OnBnClickedCloneBrowseUrl
)
197 ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE
, &CCloneDlg::OnBnClickedCloneDirBrowse
)
198 ON_BN_CLICKED(IDC_CHECK_BRANCH
, &CCloneDlg::OnBnClickedCheckBranch
)
199 ON_BN_CLICKED(IDC_CHECK_ORIGIN
, &CCloneDlg::OnBnClickedCheckOrigin
)
200 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, &CCloneDlg::OnBnClickedPuttykeyfileBrowse
)
201 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, &CCloneDlg::OnBnClickedPuttykeyAutoload
)
202 ON_CBN_EDITCHANGE(IDC_URLCOMBO
, &CCloneDlg::OnCbnEditchangeUrlcombo
)
203 ON_BN_CLICKED(IDC_CHECK_SVN
, &CCloneDlg::OnBnClickedCheckSvn
)
204 ON_BN_CLICKED(IDC_CHECK_SVN_TRUNK
, &CCloneDlg::OnBnClickedCheckSvnTrunk
)
205 ON_BN_CLICKED(IDC_CHECK_SVN_TAG
, &CCloneDlg::OnBnClickedCheckSvnTag
)
206 ON_BN_CLICKED(IDC_CHECK_SVN_BRANCH
, &CCloneDlg::OnBnClickedCheckSvnBranch
)
207 ON_BN_CLICKED(IDC_CHECK_SVN_FROM
, &CCloneDlg::OnBnClickedCheckSvnFrom
)
208 ON_BN_CLICKED(IDC_CHECK_DEPTH
, &CCloneDlg::OnBnClickedCheckDepth
)
209 ON_BN_CLICKED(IDC_CHECK_BARE
, &CCloneDlg::OnBnClickedCheckBare
)
210 ON_BN_CLICKED(IDC_CHECK_RECURSIVE
, &CCloneDlg::OnBnClickedCheckRecursive
)
211 ON_BN_CLICKED(IDC_CHECK_NOCHECKOUT
, &CCloneDlg::OnBnClickedCheckRecursive
)
212 ON_BN_CLICKED(IDC_CHECK_USERNAME
, &CCloneDlg::OnBnClickedCheckUsername
)
215 // CCloneDlg message handlers
217 void CCloneDlg::OnOK()
220 this->m_URLCombo
.GetWindowTextW(m_URL
);
223 if(m_URL
.IsEmpty() || m_Directory
.IsEmpty())
225 CMessageBox::Show(NULL
, IDS_PROC_CLONE_URLDIREMPTY
, IDS_APPNAME
, MB_OK
);
230 if (m_bBranch
&& !g_Git
.IsBranchNameValid(m_strBranch
))
232 ShowEditBalloon(IDC_EDIT_BRANCH
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
237 if (m_bOrigin
&& m_strOrigin
.GetLength() == 0 && !m_bSVN
)
239 ShowEditBalloon(IDC_EDIT_ORIGIN
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
244 m_URLCombo
.SaveHistory();
245 m_PuttyKeyCombo
.SaveHistory();
246 m_regCloneDir
= m_Directory
;
247 m_regUseSSHKey
= m_bAutoloadPuttyKeyFile
;
249 this->m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
250 CResizableDialog::OnOK();
255 void CCloneDlg::OnCancel()
257 CResizableDialog::OnCancel();
260 void CCloneDlg::OnBnClickedCloneBrowseUrl()
262 CBrowseFolder browseFolder
;
263 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
264 CString strCloneDirectory
;
266 int sel
= (int)this->m_BrowseUrl
.GetCurrentEntry();
267 this->m_regBrowseUrl
= sel
;
272 m_URLCombo
.GetWindowText(str
);
273 ShellExecute(NULL
, _T("open"), str
.Trim(), NULL
,NULL
, SW_SHOW
);
277 this->m_URLCombo
.GetWindowTextW(strCloneDirectory
);
278 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
280 this->m_URLCombo
.SetWindowTextW(strCloneDirectory
);
284 void CCloneDlg::OnBnClickedCloneDirBrowse()
286 CBrowseFolder browseFolder
;
287 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
288 CString strCloneDirectory
= this->m_Directory
;
289 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
292 m_Directory
= strCloneDirectory
;
297 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()
299 CFileDialog
dlg(TRUE
,NULL
,
301 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
302 CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER
)));
305 if(dlg
.DoModal()==IDOK
)
307 this->m_PuttyKeyCombo
.SetWindowText( dlg
.GetPathName() );
312 void CCloneDlg::OnBnClickedPuttykeyAutoload()
315 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
316 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
319 void CCloneDlg::OnCbnEditchangeUrlcombo()
321 // do not update member variables from UI while saving
322 if (m_bSaving
|| m_bExactPath
)
327 m_URLCombo
.GetWindowText(url
);
341 url
.Replace(_T('\\'),_T('/'));
343 // add compatibility for Google Code git urls
346 int start
=url
.ReverseFind(_T('/'));
349 start
= url
.ReverseFind(_T(':'));
351 start
= url
.ReverseFind(_T('@'));
357 temp
=url
.Mid(start
+1);
359 temp
=temp
.MakeLower();
361 // we've to check whether the URL ends with .git (instead of using the first .git)
362 int end
= temp
.Right(4) == _T(".git") ? (temp
.GetLength() - 4) : temp
.GetLength();
364 //CString modulename;
365 m_ModuleName
=url
.Mid(start
+1,end
);
367 start
= m_Directory
.ReverseFind(_T('\\'));
369 start
= m_Directory
.ReverseFind(_T('/'));
373 int dirstart
=m_Directory
.Find(old
,start
);
374 if(dirstart
>=0 && (dirstart
+old
.GetLength() == m_Directory
.GetLength()) )
375 m_Directory
=m_Directory
.Left(dirstart
);
377 m_Directory
.TrimRight(L
"\\/");
378 m_Directory
+= _T('\\');
379 m_Directory
+= m_ModuleName
;
381 // check if URL starts with http://, https:// or git:// in those cases loading putty keys is only
382 // asking for passwords for keys that are never used
383 if (url
.Find(L
"http://", 0) >= 0 || url
.Find(L
"https://", 0) >= 0 || url
.Find(L
"git://", 0) >= 0)
384 m_bAutoloadPuttyKeyFile
= false;
386 m_bAutoloadPuttyKeyFile
= m_regUseSSHKey
&& CAppUtils::IsSSHPutty();
389 this->UpdateData(FALSE
);
392 void CCloneDlg::OnBnClickedCheckSvn()
399 m_URLCombo
.GetWindowText(str
);
401 str
.TrimRight(L
"\\/");
402 if(str
.GetLength()>=5 && (str
.Right(5).MakeLower() == _T("trunk") ))
404 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= FALSE
;
408 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= TRUE
;
412 m_bRecursive
= false;
414 this->UpdateData(FALSE
);
415 OnBnClickedCheckDepth();
417 this->GetDlgItem(IDC_CHECK_DEPTH
)->EnableWindow(!m_bSVN
);
418 this->GetDlgItem(IDC_CHECK_BARE
)->EnableWindow(!m_bSVN
);
419 this->GetDlgItem(IDC_CHECK_RECURSIVE
)->EnableWindow(!m_bSVN
);
420 this->GetDlgItem(IDC_CHECK_BRANCH
)->EnableWindow(!m_bSVN
);
421 this->GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(!m_bSVN
);
422 OnBnClickedCheckSvnTrunk();
423 OnBnClickedCheckSvnTag();
424 OnBnClickedCheckSvnBranch();
425 OnBnClickedCheckSvnFrom();
426 OnBnClickedCheckUsername();
429 void CCloneDlg::OnBnClickedCheckSvnTrunk()
432 this->GetDlgItem(IDC_CHECK_SVN_TRUNK
)->EnableWindow(this->m_bSVN
);
433 this->GetDlgItem(IDC_EDIT_SVN_TRUNK
)->EnableWindow(this->m_bSVNTrunk
&&this->m_bSVN
);
436 void CCloneDlg::OnBnClickedCheckSvnTag()
439 this->GetDlgItem(IDC_CHECK_SVN_TAG
)->EnableWindow(this->m_bSVN
);
440 this->GetDlgItem(IDC_EDIT_SVN_TAG
)->EnableWindow(this->m_bSVNTags
&&this->m_bSVN
);
443 void CCloneDlg::OnBnClickedCheckSvnBranch()
446 this->GetDlgItem(IDC_CHECK_SVN_BRANCH
)->EnableWindow(this->m_bSVN
);
447 this->GetDlgItem(IDC_EDIT_SVN_BRANCH
)->EnableWindow(this->m_bSVNBranch
&&this->m_bSVN
);
450 void CCloneDlg::OnBnClickedCheckSvnFrom()
453 this->GetDlgItem(IDC_CHECK_SVN_FROM
)->EnableWindow(this->m_bSVN
);
454 this->GetDlgItem(IDC_EDIT_SVN_FROM
)->EnableWindow(this->m_bSVNFrom
&&this->m_bSVN
);
457 void CCloneDlg::OnBnClickedCheckRecursive()
460 if (m_bRecursive
|| m_bNoCheckout
)
463 GetDlgItem(IDC_CHECK_BARE
)->EnableWindow(FALSE
);
467 GetDlgItem(IDC_CHECK_BARE
)->EnableWindow(TRUE
);
470 void CCloneDlg::OnBnClickedCheckBare()
475 m_bRecursive
= FALSE
;
476 m_bNoCheckout
= FALSE
;
477 GetDlgItem(IDC_CHECK_RECURSIVE
)->EnableWindow(FALSE
);
478 GetDlgItem(IDC_CHECK_NOCHECKOUT
)->EnableWindow(FALSE
);
483 GetDlgItem(IDC_CHECK_RECURSIVE
)->EnableWindow(TRUE
);
484 GetDlgItem(IDC_CHECK_NOCHECKOUT
)->EnableWindow(TRUE
);
487 void CCloneDlg::OnBnClickedCheckDepth()
490 this->GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(this->m_bDepth
);
493 void CCloneDlg::OnBnClickedCheckBranch()
496 this->GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(this->m_bBranch
);
499 void CCloneDlg::OnBnClickedCheckOrigin()
502 this->GetDlgItem(IDC_EDIT_ORIGIN
)->EnableWindow(this->m_bOrigin
);
505 void CCloneDlg::OnBnClickedCheckUsername()
508 this->GetDlgItem(IDC_CHECK_USERNAME
)->EnableWindow(this->m_bSVN
);
509 this->GetDlgItem(IDC_EDIT_USERNAME
)->EnableWindow(this->m_bSVNUserName
&& this->m_bSVN
);