1 // CloneDlg.cpp : implementation file
5 #include "TortoiseProc.h"
7 #include "BrowseFolder.h"
8 #include "MessageBox.h"
12 IMPLEMENT_DYNCREATE(CCloneDlg
, CResizableStandAloneDialog
)
14 CCloneDlg::CCloneDlg(CWnd
* pParent
/*=NULL*/)
15 : CResizableStandAloneDialog(CCloneDlg::IDD
, pParent
)
18 m_bAutoloadPuttyKeyFile
= CAppUtils::IsSSHPutty();
21 CCloneDlg::~CCloneDlg()
25 void CCloneDlg::DoDataExchange(CDataExchange
* pDX
)
27 CResizableStandAloneDialog::DoDataExchange(pDX
);
28 DDX_Control(pDX
, IDC_URLCOMBO
, m_URLCombo
);
29 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
30 DDX_Text(pDX
, IDC_CLONE_DIR
, m_Directory
);
31 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
35 BOOL
CCloneDlg::OnInitDialog()
37 CResizableStandAloneDialog::OnInitDialog();
38 AddAnchor(IDC_URLCOMBO
, TOP_LEFT
, TOP_RIGHT
);
39 AddAnchor(IDC_CLONE_BROWSE_URL
, TOP_RIGHT
);
40 AddAnchor(IDC_CLONE_DIR
, TOP_LEFT
,TOP_RIGHT
);
41 AddAnchor(IDC_CLONE_DIR_BROWSE
, TOP_RIGHT
);
42 AddAnchor(IDOK
,BOTTOM_RIGHT
);
43 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
45 AddAnchor(IDC_GROUP_CLONE
,TOP_LEFT
,BOTTOM_RIGHT
);
46 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,BOTTOM_RIGHT
);
47 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,BOTTOM_LEFT
);
48 AddAnchor(IDC_PUTTYKEYFILE
,BOTTOM_LEFT
,BOTTOM_RIGHT
);
50 this->AddOthersToAnchor();
52 m_URLCombo
.SetURLHistory(TRUE
);
53 m_URLCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
56 CString str
=CAppUtils::GetClipboardLink();
58 m_URLCombo
.SetCurSel(0);
60 m_URLCombo
.SetWindowText(str
);
63 m_URLCombo
.SetWindowText(m_URL
);
65 CWnd
*window
=this->GetDlgItem(IDC_CLONE_DIR
);
67 SHAutoComplete(window
->m_hWnd
, SHACF_FILESYSTEM
);
69 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
70 m_PuttyKeyCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
71 m_PuttyKeyCombo
.SetCurSel(0);
73 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow( CAppUtils::IsSSHPutty() );
74 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
75 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
77 EnableSaveRestore(_T("CloneDlg"));
78 return TRUE
; // return TRUE unless you set the focus to a control
81 BEGIN_MESSAGE_MAP(CCloneDlg
, CResizableStandAloneDialog
)
82 ON_BN_CLICKED(IDC_CLONE_BROWSE_URL
, &CCloneDlg::OnBnClickedCloneBrowseUrl
)
83 ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE
, &CCloneDlg::OnBnClickedCloneDirBrowse
)
84 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, &CCloneDlg::OnBnClickedPuttykeyfileBrowse
)
85 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, &CCloneDlg::OnBnClickedPuttykeyAutoload
)
86 ON_CBN_SELCHANGE(IDC_URLCOMBO
, &CCloneDlg::OnCbnSelchangeUrlcombo
)
87 ON_NOTIFY(CBEN_BEGINEDIT
, IDC_URLCOMBO
, &CCloneDlg::OnCbenBegineditUrlcombo
)
88 ON_NOTIFY(CBEN_ENDEDIT
, IDC_URLCOMBO
, &CCloneDlg::OnCbenEndeditUrlcombo
)
89 ON_CBN_EDITCHANGE(IDC_URLCOMBO
, &CCloneDlg::OnCbnEditchangeUrlcombo
)
94 // CCloneDlg message handlers
96 void CCloneDlg::OnOK()
98 this->m_URLCombo
.GetWindowTextW(m_URL
);
101 if(m_URL
.IsEmpty() || m_Directory
.IsEmpty())
103 CMessageBox::Show(NULL
, _T("URL or Directory can't be empty"), _T("TortoiseGit"), MB_OK
);
107 m_URLCombo
.SaveHistory();
108 m_PuttyKeyCombo
.SaveHistory();
110 this->m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
111 CResizableDialog::OnOK();
115 void CCloneDlg::OnCancel()
117 CResizableDialog::OnCancel();
120 void CCloneDlg::OnBnClickedCloneBrowseUrl()
122 // TODO: Add your control notification handler code here
123 CBrowseFolder browseFolder
;
124 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
125 CString strCloneDirectory
;
126 this->m_URLCombo
.GetWindowTextW(strCloneDirectory
);
127 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
129 this->m_URLCombo
.SetWindowTextW(strCloneDirectory
);
133 void CCloneDlg::OnBnClickedCloneDirBrowse()
135 // TODO: Add your control notification handler code here
136 CBrowseFolder browseFolder
;
137 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
138 CString strCloneDirectory
= this->m_Directory
;
139 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
142 m_Directory
= strCloneDirectory
;
147 void CCloneDlg::OnEnChangeCloneDir()
149 // TODO: If this is a RICHEDIT control, the control will not
150 // send this notification unless you override the CDHtmlDialog::OnInitDialog()
151 // function and call CRichEditCtrl().SetEventMask()
152 // with the ENM_CHANGE flag ORed into the mask.
154 // TODO: Add your control notification handler code here
157 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()
159 // TODO: Add your control notification handler code here
160 CFileDialog
dlg(TRUE
,NULL
,
162 OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
,
163 _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));
166 if(dlg
.DoModal()==IDOK
)
168 this->m_PuttyKeyCombo
.SetWindowText( dlg
.GetPathName() );
173 void CCloneDlg::OnBnClickedPuttykeyAutoload()
175 // TODO: Add your control notification handler code here
177 this->GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
178 this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
182 void CCloneDlg::OnCbnSelchangeUrlcombo()
184 // TODO: Add your control notification handler code here
187 void CCloneDlg::OnCbenBegineditUrlcombo(NMHDR
*pNMHDR
, LRESULT
*pResult
)
189 // TODO: Add your control notification handler code here
193 void CCloneDlg::OnCbenEndeditUrlcombo(NMHDR
*pNMHDR
, LRESULT
*pResult
)
195 // TODO: Add your control notification handler code here
199 void CCloneDlg::OnCbnEditchangeUrlcombo()
201 // TODO: Add your control notification handler code here
204 m_URLCombo
.GetWindowText(url
);
211 url
.Replace(_T('\\'),_T('/'));
212 int start
=url
.ReverseFind(_T('/'));
217 temp
=url
.Mid(start
+1);
219 temp
=temp
.MakeLower();
222 end
=temp
.Find(_T(".git"));
224 end
=temp
.GetLength();
226 //CString modulename;
227 m_ModuleName
=url
.Mid(start
+1,end
);
229 start
= m_Directory
.ReverseFind(_T('\\'));
231 start
= m_Directory
.ReverseFind(_T('/'));
235 int dirstart
=m_Directory
.Find(old
,start
);
236 if(dirstart
>=0 && (dirstart
+old
.GetLength() == m_Directory
.GetLength()) )
238 m_Directory
=m_Directory
.Left(dirstart
);
239 m_Directory
+=m_ModuleName
;
243 if(m_Directory
.GetLength()>0 &&
244 (m_Directory
[m_Directory
.GetLength()-1] != _T('\\') ||
245 m_Directory
[m_Directory
.GetLength()-1] != _T('/') ) )
247 m_Directory
+=_T('\\');
249 m_Directory
+= m_ModuleName
;
252 if(m_Directory
.GetLength()>0)
254 if( m_Directory
[m_Directory
.GetLength()-1] == _T('\\') ||
255 m_Directory
[m_Directory
.GetLength()-1] == _T('/')
258 m_Directory
=m_Directory
.Left(m_Directory
.GetLength()-1);
262 this->UpdateData(FALSE
);