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();
44 m_bSVNUserName
= FALSE
;
46 m_strSVNTrunk
= _T("trunk");
47 m_strSVNTags
= _T("tags");
48 m_strSVNBranchs
= _T("branches");
50 m_regBrowseUrl
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\CloneBrowse"),0);
57 CCloneDlg::~CCloneDlg()
61 void CCloneDlg::DoDataExchange(CDataExchange
* pDX
)
63 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
64 DDX_Control(pDX
, IDC_URLCOMBO
, m_URLCombo
);
65 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
66 DDX_Control(pDX
, IDC_CLONE_BROWSE_URL
, m_BrowseUrl
);
67 DDX_Text(pDX
, IDC_CLONE_DIR
, m_Directory
);
68 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
70 DDX_Check(pDX
,IDC_CHECK_SVN
, m_bSVN
);
71 DDX_Check(pDX
,IDC_CHECK_SVN_TRUNK
, m_bSVNTrunk
);
72 DDX_Check(pDX
,IDC_CHECK_SVN_TAG
, m_bSVNTags
);
73 DDX_Check(pDX
,IDC_CHECK_SVN_BRANCH
, m_bSVNBranch
);
74 DDX_Check(pDX
,IDC_CHECK_SVN_FROM
, m_bSVNFrom
);
75 DDX_Check(pDX
,IDC_CHECK_USERNAME
, m_bSVNUserName
);
77 DDX_Text(pDX
, IDC_EDIT_SVN_TRUNK
, m_strSVNTrunk
);
78 DDX_Text(pDX
, IDC_EDIT_SVN_TAG
, m_strSVNTags
);
79 DDX_Text(pDX
, IDC_EDIT_SVN_BRANCH
, m_strSVNBranchs
);
80 DDX_Text(pDX
, IDC_EDIT_SVN_FROM
, this->m_nSVNFrom
);
81 DDX_Text(pDX
, IDC_EDIT_USERNAME
,m_strUserName
);
83 DDX_Check(pDX
, IDC_CHECK_DEPTH
, m_bDepth
);
84 DDX_Check(pDX
, IDC_CHECK_BARE
, m_bBare
);
85 DDX_Check(pDX
, IDC_CHECK_RECURSIVE
, m_bRecursive
);
86 DDX_Text(pDX
, IDC_EDIT_DEPTH
,m_nDepth
);
90 BOOL
CCloneDlg::OnInitDialog()
92 CHorizontalResizableStandAloneDialog::OnInitDialog();
93 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
95 AddAnchor(IDC_URLCOMBO
, TOP_LEFT
, TOP_RIGHT
);
96 AddAnchor(IDC_CLONE_BROWSE_URL
, TOP_RIGHT
);
97 AddAnchor(IDC_CLONE_DIR
, TOP_LEFT
,TOP_RIGHT
);
98 AddAnchor(IDC_CLONE_DIR_BROWSE
, TOP_RIGHT
);
99 AddAnchor(IDOK
,BOTTOM_RIGHT
);
100 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
102 AddAnchor(IDC_GROUP_CLONE
,TOP_LEFT
,TOP_RIGHT
);
103 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,TOP_RIGHT
);
104 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
105 AddAnchor(IDC_PUTTYKEYFILE
,TOP_LEFT
,TOP_RIGHT
);
106 AddAnchor(IDC_CLONE_GROUP_SVN
,TOP_LEFT
,TOP_RIGHT
);
107 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
109 m_tooltips
.Create(this);
111 tt
.LoadString(IDS_CLONE_DEPTH_TT
);
112 m_tooltips
.AddTool(IDC_EDIT_DEPTH
,tt
);
113 m_tooltips
.AddTool(IDC_CHECK_DEPTH
,tt
);
115 this->AddOthersToAnchor();
117 m_URLCombo
.SetURLHistory(TRUE
);
118 m_URLCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
121 CString str
=CAppUtils::GetClipboardLink();
123 m_URLCombo
.SetCurSel(0);
125 m_URLCombo
.SetWindowText(str
);
128 m_URLCombo
.SetWindowText(m_URL
);
130 CWnd
*window
=this->GetDlgItem(IDC_CLONE_DIR
);
132 SHAutoComplete(window
->m_hWnd
, SHACF_FILESYSTEM
);
134 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_DIR
)));
135 this->m_BrowseUrl
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_CLONE_WEB
)));
136 m_BrowseUrl
.SetCurrentEntry(m_regBrowseUrl
);
138 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
139 m_PuttyKeyCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
140 m_PuttyKeyCombo
.SetCurSel(0);
142 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow( CAppUtils::IsSSHPutty() );
143 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
144 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
146 EnableSaveRestore(_T("CloneDlg"));
148 OnBnClickedCheckSvn();
149 OnBnClickedCheckDepth();
150 return TRUE
; // return TRUE unless you set the focus to a control
153 BEGIN_MESSAGE_MAP(CCloneDlg
, CHorizontalResizableStandAloneDialog
)
154 ON_BN_CLICKED(IDC_CLONE_BROWSE_URL
, &CCloneDlg::OnBnClickedCloneBrowseUrl
)
155 ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE
, &CCloneDlg::OnBnClickedCloneDirBrowse
)
156 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, &CCloneDlg::OnBnClickedPuttykeyfileBrowse
)
157 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, &CCloneDlg::OnBnClickedPuttykeyAutoload
)
158 ON_CBN_EDITCHANGE(IDC_URLCOMBO
, &CCloneDlg::OnCbnEditchangeUrlcombo
)
159 ON_BN_CLICKED(IDC_CHECK_SVN
, &CCloneDlg::OnBnClickedCheckSvn
)
160 ON_BN_CLICKED(IDC_CHECK_SVN_TRUNK
, &CCloneDlg::OnBnClickedCheckSvnTrunk
)
161 ON_BN_CLICKED(IDC_CHECK_SVN_TAG
, &CCloneDlg::OnBnClickedCheckSvnTag
)
162 ON_BN_CLICKED(IDC_CHECK_SVN_BRANCH
, &CCloneDlg::OnBnClickedCheckSvnBranch
)
163 ON_BN_CLICKED(IDC_CHECK_SVN_FROM
, &CCloneDlg::OnBnClickedCheckSvnFrom
)
164 ON_BN_CLICKED(IDC_CHECK_DEPTH
, &CCloneDlg::OnBnClickedCheckDepth
)
165 ON_BN_CLICKED(IDC_CHECK_BARE
, &CCloneDlg::OnBnClickedCheckBare
)
166 ON_BN_CLICKED(IDC_CHECK_RECURSIVE
, &CCloneDlg::OnBnClickedCheckRecursive
)
167 ON_BN_CLICKED(IDC_CHECK_USERNAME
, &CCloneDlg::OnBnClickedCheckUsername
)
170 // CCloneDlg message handlers
172 void CCloneDlg::OnOK()
174 this->m_URLCombo
.GetWindowTextW(m_URL
);
177 if(m_URL
.IsEmpty() || m_Directory
.IsEmpty())
179 CMessageBox::Show(NULL
, IDS_PROC_CLONE_URLDIREMPTY
, IDS_APPNAME
, MB_OK
);
183 m_URLCombo
.SaveHistory();
184 m_PuttyKeyCombo
.SaveHistory();
186 this->m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
187 CResizableDialog::OnOK();
191 void CCloneDlg::OnCancel()
193 CResizableDialog::OnCancel();
196 void CCloneDlg::OnBnClickedCloneBrowseUrl()
198 CBrowseFolder browseFolder
;
199 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
200 CString strCloneDirectory
;
202 int sel
= this->m_BrowseUrl
.GetCurrentEntry();
203 this->m_regBrowseUrl
= sel
;
208 m_URLCombo
.GetWindowText(str
);
209 ShellExecute(NULL
, _T("open"), str
, NULL
,NULL
, SW_SHOW
);
213 this->m_URLCombo
.GetWindowTextW(strCloneDirectory
);
214 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
216 this->m_URLCombo
.SetWindowTextW(strCloneDirectory
);
220 void CCloneDlg::OnBnClickedCloneDirBrowse()
222 CBrowseFolder browseFolder
;
223 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
224 CString strCloneDirectory
= this->m_Directory
;
225 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
228 m_Directory
= strCloneDirectory
;
233 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()
235 CFileDialog
dlg(TRUE
,NULL
,
237 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
238 CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER
)));
241 if(dlg
.DoModal()==IDOK
)
243 this->m_PuttyKeyCombo
.SetWindowText( dlg
.GetPathName() );
248 void CCloneDlg::OnBnClickedPuttykeyAutoload()
251 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
252 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
255 void CCloneDlg::OnCbnEditchangeUrlcombo()
259 m_URLCombo
.GetWindowText(url
);
272 url
.Replace(_T('\\'),_T('/'));
274 // add compatibility for Google Code git urls
275 if (url
.GetLength() > 0 && url
[url
.GetLength()-1] == _T('/')) {
276 url
= url
.Left(url
.GetLength() - 1);
279 int start
=url
.ReverseFind(_T('/'));
282 start
= url
.ReverseFind(_T(':'));
284 start
= url
.ReverseFind(_T('@'));
290 temp
=url
.Mid(start
+1);
292 temp
=temp
.MakeLower();
295 end
=temp
.Find(_T(".git"));
297 end
=temp
.GetLength();
299 //CString modulename;
300 m_ModuleName
=url
.Mid(start
+1,end
);
302 start
= m_Directory
.ReverseFind(_T('\\'));
304 start
= m_Directory
.ReverseFind(_T('/'));
308 int dirstart
=m_Directory
.Find(old
,start
);
309 if(dirstart
>=0 && (dirstart
+old
.GetLength() == m_Directory
.GetLength()) )
311 m_Directory
=m_Directory
.Left(dirstart
);
312 m_Directory
+=m_ModuleName
;
317 if(m_Directory
.GetLength()>0 &&
318 (m_Directory
[m_Directory
.GetLength()-1] != _T('\\') &&
319 m_Directory
[m_Directory
.GetLength()-1] != _T('/') ) )
321 m_Directory
+= _T('\\');
323 m_Directory
+= m_ModuleName
;
326 if(m_Directory
.GetLength()>0)
328 if( m_Directory
[m_Directory
.GetLength()-1] == _T('\\') ||
329 m_Directory
[m_Directory
.GetLength()-1] == _T('/')
332 m_Directory
=m_Directory
.Left(m_Directory
.GetLength()-1);
336 this->UpdateData(FALSE
);
339 void CCloneDlg::OnBnClickedCheckSvn()
346 m_URLCombo
.GetWindowText(str
);
348 while(str
.GetLength()>=1 &&
349 str
[str
.GetLength()-1] == _T('\\') &&
350 str
[str
.GetLength()-1] == _T('/'))
352 str
=str
.Left(str
.GetLength()-1);
354 if(str
.GetLength()>=5 && (str
.Right(5).MakeLower() == _T("trunk") ))
356 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= FALSE
;
360 this->m_bSVNBranch
=this->m_bSVNTags
=this->m_bSVNTrunk
= TRUE
;
364 m_bRecursive
= false;
365 this->UpdateData(FALSE
);
366 OnBnClickedCheckDepth();
368 this->GetDlgItem(IDC_CHECK_DEPTH
)->EnableWindow(!m_bSVN
);
369 this->GetDlgItem(IDC_CHECK_BARE
)->EnableWindow(!m_bSVN
);
370 this->GetDlgItem(IDC_CHECK_RECURSIVE
)->EnableWindow(!m_bSVN
);
371 OnBnClickedCheckSvnTrunk();
372 OnBnClickedCheckSvnTag();
373 OnBnClickedCheckSvnBranch();
374 OnBnClickedCheckSvnFrom();
375 OnBnClickedCheckUsername();
378 void CCloneDlg::OnBnClickedCheckSvnTrunk()
381 this->GetDlgItem(IDC_CHECK_SVN_TRUNK
)->EnableWindow(this->m_bSVN
);
382 this->GetDlgItem(IDC_EDIT_SVN_TRUNK
)->EnableWindow(this->m_bSVNTrunk
&&this->m_bSVN
);
385 void CCloneDlg::OnBnClickedCheckSvnTag()
388 this->GetDlgItem(IDC_CHECK_SVN_TAG
)->EnableWindow(this->m_bSVN
);
389 this->GetDlgItem(IDC_EDIT_SVN_TAG
)->EnableWindow(this->m_bSVNTags
&&this->m_bSVN
);
392 void CCloneDlg::OnBnClickedCheckSvnBranch()
395 this->GetDlgItem(IDC_CHECK_SVN_BRANCH
)->EnableWindow(this->m_bSVN
);
396 this->GetDlgItem(IDC_EDIT_SVN_BRANCH
)->EnableWindow(this->m_bSVNBranch
&&this->m_bSVN
);
399 void CCloneDlg::OnBnClickedCheckSvnFrom()
402 this->GetDlgItem(IDC_CHECK_SVN_FROM
)->EnableWindow(this->m_bSVN
);
403 this->GetDlgItem(IDC_EDIT_SVN_FROM
)->EnableWindow(this->m_bSVNFrom
&&this->m_bSVN
);
406 void CCloneDlg::OnBnClickedCheckRecursive()
410 void CCloneDlg::OnBnClickedCheckBare()
414 void CCloneDlg::OnBnClickedCheckDepth()
417 this->GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(this->m_bDepth
);
419 BOOL
CCloneDlg::PreTranslateMessage(MSG
* pMsg
)
421 m_tooltips
.RelayEvent(pMsg
);
423 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);
426 void CCloneDlg::OnBnClickedCheckUsername()
429 this->GetDlgItem(IDC_CHECK_USERNAME
)->EnableWindow(this->m_bSVN
);
430 this->GetDlgItem(IDC_EDIT_USERNAME
)->EnableWindow(this->m_bSVNUserName
&& this->m_bSVN
);