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
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
)
36 m_bAutoloadPuttyKeyFile
= CAppUtils::IsSSHPutty();
41 m_bNoCheckout
= FALSE
;
47 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);
60 CCloneDlg::~CCloneDlg()
64 void CCloneDlg::DoDataExchange(CDataExchange
* pDX
)
66 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
67 DDX_Control(pDX
, IDC_URLCOMBO
, m_URLCombo
);
68 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
69 DDX_Control(pDX
, IDC_CLONE_BROWSE_URL
, m_BrowseUrl
);
70 DDX_Text(pDX
, IDC_CLONE_DIR
, m_Directory
);
71 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
73 DDX_Check(pDX
,IDC_CHECK_SVN
, m_bSVN
);
74 DDX_Check(pDX
,IDC_CHECK_SVN_TRUNK
, m_bSVNTrunk
);
75 DDX_Check(pDX
,IDC_CHECK_SVN_TAG
, m_bSVNTags
);
76 DDX_Check(pDX
,IDC_CHECK_SVN_BRANCH
, m_bSVNBranch
);
77 DDX_Check(pDX
,IDC_CHECK_SVN_FROM
, m_bSVNFrom
);
78 DDX_Check(pDX
,IDC_CHECK_USERNAME
, m_bSVNUserName
);
80 DDX_Text(pDX
, IDC_EDIT_SVN_TRUNK
, m_strSVNTrunk
);
81 DDX_Text(pDX
, IDC_EDIT_SVN_TAG
, m_strSVNTags
);
82 DDX_Text(pDX
, IDC_EDIT_SVN_BRANCH
, m_strSVNBranchs
);
83 DDX_Text(pDX
, IDC_EDIT_SVN_FROM
, this->m_nSVNFrom
);
84 DDX_Text(pDX
, IDC_EDIT_USERNAME
,m_strUserName
);
86 DDX_Check(pDX
, IDC_CHECK_DEPTH
, m_bDepth
);
87 DDX_Check(pDX
, IDC_CHECK_BARE
, m_bBare
);
88 DDX_Check(pDX
, IDC_CHECK_RECURSIVE
, m_bRecursive
);
89 DDX_Text(pDX
, IDC_EDIT_DEPTH
,m_nDepth
);
90 DDX_Check(pDX
,IDC_CHECK_BRANCH
, m_bBranch
);
91 DDX_Text(pDX
, IDC_EDIT_BRANCH
, m_strBranch
);
92 DDX_Check(pDX
,IDC_CHECK_NOCHECKOUT
, m_bNoCheckout
);
95 BOOL
CCloneDlg::OnInitDialog()
97 CHorizontalResizableStandAloneDialog::OnInitDialog();
98 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
100 AddAnchor(IDC_URLCOMBO
, TOP_LEFT
, TOP_RIGHT
);
101 AddAnchor(IDC_CLONE_BROWSE_URL
, TOP_RIGHT
);
102 AddAnchor(IDC_CLONE_DIR
, TOP_LEFT
,TOP_RIGHT
);
103 AddAnchor(IDC_CLONE_DIR_BROWSE
, TOP_RIGHT
);
104 AddAnchor(IDOK
,BOTTOM_RIGHT
);
105 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
107 AddAnchor(IDC_GROUP_CLONE
,TOP_LEFT
,TOP_RIGHT
);
108 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,TOP_RIGHT
);
109 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
110 AddAnchor(IDC_PUTTYKEYFILE
,TOP_LEFT
,TOP_RIGHT
);
111 AddAnchor(IDC_CLONE_GROUP_SVN
,TOP_LEFT
,TOP_RIGHT
);
112 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
114 AdjustControlSize(IDC_CHECK_DEPTH
);
115 AdjustControlSize(IDC_CHECK_RECURSIVE
);
116 AdjustControlSize(IDC_CHECK_BARE
);
117 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
118 AdjustControlSize(IDC_CHECK_SVN
);
119 AdjustControlSize(IDC_CHECK_SVN_TRUNK
);
120 AdjustControlSize(IDC_CHECK_SVN_TAG
);
121 AdjustControlSize(IDC_CHECK_SVN_BRANCH
);
122 AdjustControlSize(IDC_CHECK_SVN_FROM
);
123 AdjustControlSize(IDC_CHECK_USERNAME
);
125 m_tooltips
.Create(this);
127 tt
.LoadString(IDS_CLONE_DEPTH_TT
);
128 m_tooltips
.AddTool(IDC_EDIT_DEPTH
,tt
);
129 m_tooltips
.AddTool(IDC_CHECK_DEPTH
,tt
);
131 this->AddOthersToAnchor();
133 m_URLCombo
.SetURLHistory(TRUE
);
134 m_URLCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
137 CString str
=CAppUtils::GetClipboardLink();
140 m_URLCombo
.SetCurSel(0);
142 m_URLCombo
.SetWindowText(str
);
145 m_URLCombo
.SetWindowText(m_URL
);
147 CWnd
*window
=this->GetDlgItem(IDC_CLONE_DIR
);
149 SHAutoComplete(window
->m_hWnd
, SHACF_FILESYSTEM
);
151 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_DIR
)));
152 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_WEB
)));
153 m_BrowseUrl
.SetCurrentEntry(m_regBrowseUrl
);
155 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
156 m_PuttyKeyCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
157 m_PuttyKeyCombo
.SetCurSel(0);
159 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow( CAppUtils::IsSSHPutty() );
160 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
161 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
163 EnableSaveRestore(_T("CloneDlg"));
165 OnBnClickedCheckSvn();
166 OnBnClickedCheckDepth();
167 OnBnClickedCheckBranch();
168 return TRUE
; // return TRUE unless you set the focus to a control
171 BEGIN_MESSAGE_MAP(CCloneDlg
, CHorizontalResizableStandAloneDialog
)
172 ON_BN_CLICKED(IDC_CLONE_BROWSE_URL
, &CCloneDlg::OnBnClickedCloneBrowseUrl
)
173 ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE
, &CCloneDlg::OnBnClickedCloneDirBrowse
)
174 ON_BN_CLICKED(IDC_CHECK_BRANCH
, &CCloneDlg::OnBnClickedCheckBranch
)
175 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, &CCloneDlg::OnBnClickedPuttykeyfileBrowse
)
176 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, &CCloneDlg::OnBnClickedPuttykeyAutoload
)
177 ON_CBN_EDITCHANGE(IDC_URLCOMBO
, &CCloneDlg::OnCbnEditchangeUrlcombo
)
178 ON_BN_CLICKED(IDC_CHECK_SVN
, &CCloneDlg::OnBnClickedCheckSvn
)
179 ON_BN_CLICKED(IDC_CHECK_SVN_TRUNK
, &CCloneDlg::OnBnClickedCheckSvnTrunk
)
180 ON_BN_CLICKED(IDC_CHECK_SVN_TAG
, &CCloneDlg::OnBnClickedCheckSvnTag
)
181 ON_BN_CLICKED(IDC_CHECK_SVN_BRANCH
, &CCloneDlg::OnBnClickedCheckSvnBranch
)
182 ON_BN_CLICKED(IDC_CHECK_SVN_FROM
, &CCloneDlg::OnBnClickedCheckSvnFrom
)
183 ON_BN_CLICKED(IDC_CHECK_DEPTH
, &CCloneDlg::OnBnClickedCheckDepth
)
184 ON_BN_CLICKED(IDC_CHECK_BARE
, &CCloneDlg::OnBnClickedCheckBare
)
185 ON_BN_CLICKED(IDC_CHECK_RECURSIVE
, &CCloneDlg::OnBnClickedCheckRecursive
)
186 ON_BN_CLICKED(IDC_CHECK_USERNAME
, &CCloneDlg::OnBnClickedCheckUsername
)
189 // CCloneDlg message handlers
191 void CCloneDlg::OnOK()
193 this->m_URLCombo
.GetWindowTextW(m_URL
);
196 if(m_URL
.IsEmpty() || m_Directory
.IsEmpty())
198 CMessageBox::Show(NULL
, IDS_PROC_CLONE_URLDIREMPTY
, IDS_APPNAME
, MB_OK
);
202 if (m_bBranch
&& !g_Git
.IsBranchNameValid(m_strBranch
))
204 ShowEditBalloon(IDC_EDIT_BRANCH
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
208 m_URLCombo
.SaveHistory();
209 m_PuttyKeyCombo
.SaveHistory();
211 this->m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
212 CResizableDialog::OnOK();
216 void CCloneDlg::OnCancel()
218 CResizableDialog::OnCancel();
221 void CCloneDlg::OnBnClickedCloneBrowseUrl()
223 CBrowseFolder browseFolder
;
224 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
225 CString strCloneDirectory
;
227 int sel
= (int)this->m_BrowseUrl
.GetCurrentEntry();
228 this->m_regBrowseUrl
= sel
;
233 m_URLCombo
.GetWindowText(str
);
234 ShellExecute(NULL
, _T("open"), str
.Trim(), NULL
,NULL
, SW_SHOW
);
238 this->m_URLCombo
.GetWindowTextW(strCloneDirectory
);
239 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
241 this->m_URLCombo
.SetWindowTextW(strCloneDirectory
);
245 void CCloneDlg::OnBnClickedCloneDirBrowse()
247 CBrowseFolder browseFolder
;
248 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
249 CString strCloneDirectory
= this->m_Directory
;
250 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
253 m_Directory
= strCloneDirectory
;
258 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()
260 CFileDialog
dlg(TRUE
,NULL
,
262 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
263 CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER
)));
266 if(dlg
.DoModal()==IDOK
)
268 this->m_PuttyKeyCombo
.SetWindowText( dlg
.GetPathName() );
273 void CCloneDlg::OnBnClickedPuttykeyAutoload()
276 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
277 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
280 void CCloneDlg::OnCbnEditchangeUrlcombo()
284 m_URLCombo
.GetWindowText(url
);
298 url
.Replace(_T('\\'),_T('/'));
300 // add compatibility for Google Code git urls
301 if (url
.GetLength() > 0 && url
[url
.GetLength()-1] == _T('/')) {
302 url
= url
.Left(url
.GetLength() - 1);
305 int start
=url
.ReverseFind(_T('/'));
308 start
= url
.ReverseFind(_T(':'));
310 start
= url
.ReverseFind(_T('@'));
316 temp
=url
.Mid(start
+1);
318 temp
=temp
.MakeLower();
320 // we've to check whether the URL ends with .git (instead of using the first .git)
321 int end
= temp
.Right(4) == _T(".git") ? (temp
.GetLength() - 4) : temp
.GetLength();
323 //CString modulename;
324 m_ModuleName
=url
.Mid(start
+1,end
);
326 start
= m_Directory
.ReverseFind(_T('\\'));
328 start
= m_Directory
.ReverseFind(_T('/'));
332 int dirstart
=m_Directory
.Find(old
,start
);
333 if(dirstart
>=0 && (dirstart
+old
.GetLength() == m_Directory
.GetLength()) )
335 m_Directory
=m_Directory
.Left(dirstart
);
336 m_Directory
+=m_ModuleName
;
341 if(m_Directory
.GetLength()>0 &&
342 (m_Directory
[m_Directory
.GetLength()-1] != _T('\\') &&
343 m_Directory
[m_Directory
.GetLength()-1] != _T('/') ) )
345 m_Directory
+= _T('\\');
347 m_Directory
+= m_ModuleName
;
350 if(m_Directory
.GetLength()>0)
352 if( m_Directory
[m_Directory
.GetLength()-1] == _T('\\') ||
353 m_Directory
[m_Directory
.GetLength()-1] == _T('/')
356 m_Directory
=m_Directory
.Left(m_Directory
.GetLength()-1);
360 this->UpdateData(FALSE
);
363 void CCloneDlg::OnBnClickedCheckSvn()
370 m_URLCombo
.GetWindowText(str
);
372 while(str
.GetLength()>=1 &&
373 str
[str
.GetLength()-1] == _T('\\') &&
374 str
[str
.GetLength()-1] == _T('/'))
376 str
=str
.Left(str
.GetLength()-1);
378 if(str
.GetLength()>=5 && (str
.Right(5).MakeLower() == _T("trunk") ))
380 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= FALSE
;
384 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= TRUE
;
388 m_bRecursive
= false;
390 this->UpdateData(FALSE
);
391 OnBnClickedCheckDepth();
393 this->GetDlgItem(IDC_CHECK_DEPTH
)->EnableWindow(!m_bSVN
);
394 this->GetDlgItem(IDC_CHECK_BARE
)->EnableWindow(!m_bSVN
);
395 this->GetDlgItem(IDC_CHECK_RECURSIVE
)->EnableWindow(!m_bSVN
);
396 this->GetDlgItem(IDC_CHECK_BRANCH
)->EnableWindow(!m_bSVN
);
397 this->GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(!m_bSVN
);
398 OnBnClickedCheckSvnTrunk();
399 OnBnClickedCheckSvnTag();
400 OnBnClickedCheckSvnBranch();
401 OnBnClickedCheckSvnFrom();
402 OnBnClickedCheckUsername();
405 void CCloneDlg::OnBnClickedCheckSvnTrunk()
408 this->GetDlgItem(IDC_CHECK_SVN_TRUNK
)->EnableWindow(this->m_bSVN
);
409 this->GetDlgItem(IDC_EDIT_SVN_TRUNK
)->EnableWindow(this->m_bSVNTrunk
&&this->m_bSVN
);
412 void CCloneDlg::OnBnClickedCheckSvnTag()
415 this->GetDlgItem(IDC_CHECK_SVN_TAG
)->EnableWindow(this->m_bSVN
);
416 this->GetDlgItem(IDC_EDIT_SVN_TAG
)->EnableWindow(this->m_bSVNTags
&&this->m_bSVN
);
419 void CCloneDlg::OnBnClickedCheckSvnBranch()
422 this->GetDlgItem(IDC_CHECK_SVN_BRANCH
)->EnableWindow(this->m_bSVN
);
423 this->GetDlgItem(IDC_EDIT_SVN_BRANCH
)->EnableWindow(this->m_bSVNBranch
&&this->m_bSVN
);
426 void CCloneDlg::OnBnClickedCheckSvnFrom()
429 this->GetDlgItem(IDC_CHECK_SVN_FROM
)->EnableWindow(this->m_bSVN
);
430 this->GetDlgItem(IDC_EDIT_SVN_FROM
)->EnableWindow(this->m_bSVNFrom
&&this->m_bSVN
);
433 void CCloneDlg::OnBnClickedCheckRecursive()
437 void CCloneDlg::OnBnClickedCheckBare()
441 void CCloneDlg::OnBnClickedCheckDepth()
444 this->GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(this->m_bDepth
);
447 void CCloneDlg::OnBnClickedCheckBranch()
450 this->GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(this->m_bBranch
);
453 BOOL
CCloneDlg::PreTranslateMessage(MSG
* pMsg
)
455 m_tooltips
.RelayEvent(pMsg
);
457 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);
460 void CCloneDlg::OnBnClickedCheckUsername()
463 this->GetDlgItem(IDC_CHECK_USERNAME
)->EnableWindow(this->m_bSVN
);
464 this->GetDlgItem(IDC_EDIT_USERNAME
)->EnableWindow(this->m_bSVNUserName
&& this->m_bSVN
);