BrowseRefs: Context menu enhancements
[TortoiseGit.git] / src / TortoiseProc / CloneDlg.cpp
blob77b712df11525f0402e100a458b15b35d6f84d85
1 // CloneDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "CloneDlg.h"
7 #include "BrowseFolder.h"
8 #include "MessageBox.h"
9 #include "AppUtils.h"
10 // CCloneDlg dialog
12 IMPLEMENT_DYNCREATE(CCloneDlg, CResizableStandAloneDialog)
14 CCloneDlg::CCloneDlg(CWnd* pParent /*=NULL*/)
15 : CResizableStandAloneDialog(CCloneDlg::IDD, pParent)
16 , m_Directory(_T(""))
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"));
54 if(m_URL.IsEmpty())
56 CString str=CAppUtils::GetClipboardLink();
57 if(str.IsEmpty())
58 m_URLCombo.SetCurSel(0);
59 else
60 m_URLCombo.SetWindowText(str);
62 else
63 m_URLCombo.SetWindowText(m_URL);
65 CWnd *window=this->GetDlgItem(IDC_CLONE_DIR);
66 if(window)
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)
90 END_MESSAGE_MAP()
94 // CCloneDlg message handlers
96 void CCloneDlg::OnOK()
98 this->m_URLCombo.GetWindowTextW(m_URL);
99 m_URL.Trim();
100 UpdateData(TRUE);
101 if(m_URL.IsEmpty() || m_Directory.IsEmpty())
103 CMessageBox::Show(NULL, _T("URL or Directory can't be empty"), _T("TortoiseGit"), MB_OK);
104 return;
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)
141 UpdateData(TRUE);
142 m_Directory = strCloneDirectory;
143 UpdateData(FALSE);
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,
161 NULL,
162 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
163 _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));
165 this->UpdateData();
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
176 this->UpdateData();
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
190 *pResult = 0;
193 void CCloneDlg::OnCbenEndeditUrlcombo(NMHDR *pNMHDR, LRESULT *pResult)
195 // TODO: Add your control notification handler code here
196 *pResult = 0;
199 void CCloneDlg::OnCbnEditchangeUrlcombo()
201 // TODO: Add your control notification handler code here
202 this->UpdateData();
203 CString url;
204 m_URLCombo.GetWindowText(url);
205 //if(url.IsEmpty())
206 // return;
208 CString old;
209 old=m_ModuleName;
211 url.Replace(_T('\\'),_T('/'));
212 int start=url.ReverseFind(_T('/'));
213 if(start<0)
214 start = 0;
216 CString temp;
217 temp=url.Mid(start+1);
219 temp=temp.MakeLower();
221 int end;
222 end=temp.Find(_T(".git"));
223 if(end<0)
224 end=temp.GetLength();
226 //CString modulename;
227 m_ModuleName=url.Mid(start+1,end);
229 start = m_Directory.ReverseFind(_T('\\'));
230 if(start <0 )
231 start = m_Directory.ReverseFind(_T('/'));
232 if(start <0 )
233 start =0;
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;
241 }else
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);