OSDN Git Service

Support Git svn-clone at clone dialog.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / CloneDlg.cpp
1 // CloneDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "CloneDlg.h"\r
7 #include "BrowseFolder.h"\r
8 #include "MessageBox.h"\r
9 #include "AppUtils.h"\r
10 // CCloneDlg dialog\r
11 \r
12 IMPLEMENT_DYNCREATE(CCloneDlg, CResizableStandAloneDialog)\r
13 \r
14 CCloneDlg::CCloneDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CCloneDlg::IDD, pParent)\r
16         , m_Directory(_T(""))\r
17 {\r
18     m_bAutoloadPuttyKeyFile = CAppUtils::IsSSHPutty();\r
19 \r
20         m_bSVN = FALSE;\r
21         m_bSVNTrunk = FALSE;\r
22         m_bSVNTags = FALSE;\r
23         m_bSVNBranch = FALSE;;\r
24         m_strSVNTrunk = _T("trunk");\r
25         m_strSVNTags = _T("tags");\r
26         m_strSVNBranchs = _T("branches");\r
27 }\r
28 \r
29 CCloneDlg::~CCloneDlg()\r
30 {\r
31 }\r
32 \r
33 void CCloneDlg::DoDataExchange(CDataExchange* pDX)\r
34 {\r
35         CResizableStandAloneDialog::DoDataExchange(pDX);\r
36         DDX_Control(pDX, IDC_URLCOMBO, m_URLCombo);\r
37     DDX_Control(pDX, IDC_PUTTYKEYFILE, m_PuttyKeyCombo);\r
38         DDX_Text(pDX, IDC_CLONE_DIR, m_Directory);\r
39     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD, m_bAutoloadPuttyKeyFile);\r
40 \r
41         DDX_Check(pDX,IDC_CHECK_SVN, m_bSVN);\r
42         DDX_Check(pDX,IDC_CHECK_SVN_TRUNK, m_bSVNTrunk);\r
43         DDX_Check(pDX,IDC_CHECK_SVN_TAG, m_bSVNTags);\r
44         DDX_Check(pDX,IDC_CHECK_SVN_BRANCH, m_bSVNBranch);\r
45 \r
46         DDX_Text(pDX, IDC_EDIT_SVN_TRUNK, m_strSVNTrunk);\r
47         DDX_Text(pDX, IDC_EDIT_SVN_TAG, m_strSVNTags);\r
48         DDX_Text(pDX, IDC_EDIT_SVN_BRANCH, m_strSVNBranchs);\r
49 \r
50 }\r
51 \r
52 BOOL CCloneDlg::OnInitDialog()\r
53 {\r
54         CResizableStandAloneDialog::OnInitDialog();\r
55         AddAnchor(IDC_URLCOMBO, TOP_LEFT, TOP_RIGHT);\r
56         AddAnchor(IDC_CLONE_BROWSE_URL, TOP_RIGHT);\r
57         AddAnchor(IDC_CLONE_DIR, TOP_LEFT,TOP_RIGHT);\r
58         AddAnchor(IDC_CLONE_DIR_BROWSE, TOP_RIGHT);\r
59         AddAnchor(IDOK,BOTTOM_RIGHT);\r
60         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
61 \r
62     AddAnchor(IDC_GROUP_CLONE,TOP_LEFT,TOP_RIGHT);\r
63     AddAnchor(IDC_PUTTYKEYFILE_BROWSE,TOP_RIGHT);\r
64     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);\r
65     AddAnchor(IDC_PUTTYKEYFILE,TOP_LEFT,TOP_RIGHT);\r
66         AddAnchor(IDC_CLONE_GROUP_SVN,TOP_LEFT,TOP_RIGHT);\r
67         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
68 \r
69         this->AddOthersToAnchor();\r
70 \r
71         m_URLCombo.SetURLHistory(TRUE);\r
72         m_URLCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));\r
73         if(m_URL.IsEmpty())\r
74         {\r
75                 CString str=CAppUtils::GetClipboardLink();\r
76                 if(str.IsEmpty())\r
77                         m_URLCombo.SetCurSel(0);\r
78                 else\r
79                         m_URLCombo.SetWindowText(str);\r
80         }\r
81         else\r
82                 m_URLCombo.SetWindowText(m_URL);\r
83 \r
84         CWnd *window=this->GetDlgItem(IDC_CLONE_DIR);\r
85         if(window)\r
86                 SHAutoComplete(window->m_hWnd, SHACF_FILESYSTEM);\r
87 \r
88     m_PuttyKeyCombo.SetPathHistory(TRUE);\r
89     m_PuttyKeyCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));\r
90     m_PuttyKeyCombo.SetCurSel(0);\r
91 \r
92     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow( CAppUtils::IsSSHPutty() );\r
93     this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
94     this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
95        \r
96     EnableSaveRestore(_T("CloneDlg"));\r
97         \r
98         OnBnClickedCheckSvn();\r
99 \r
100         return TRUE;  // return TRUE  unless you set the focus to a control\r
101 }\r
102 \r
103 BEGIN_MESSAGE_MAP(CCloneDlg, CResizableStandAloneDialog)\r
104         ON_BN_CLICKED(IDC_CLONE_BROWSE_URL, &CCloneDlg::OnBnClickedCloneBrowseUrl)\r
105         ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE, &CCloneDlg::OnBnClickedCloneDirBrowse)\r
106     ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE, &CCloneDlg::OnBnClickedPuttykeyfileBrowse)\r
107     ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD, &CCloneDlg::OnBnClickedPuttykeyAutoload)\r
108         ON_CBN_SELCHANGE(IDC_URLCOMBO, &CCloneDlg::OnCbnSelchangeUrlcombo)\r
109         ON_NOTIFY(CBEN_BEGINEDIT, IDC_URLCOMBO, &CCloneDlg::OnCbenBegineditUrlcombo)\r
110         ON_NOTIFY(CBEN_ENDEDIT, IDC_URLCOMBO, &CCloneDlg::OnCbenEndeditUrlcombo)\r
111         ON_CBN_EDITCHANGE(IDC_URLCOMBO, &CCloneDlg::OnCbnEditchangeUrlcombo)\r
112         ON_BN_CLICKED(IDC_CHECK_SVN, &CCloneDlg::OnBnClickedCheckSvn)\r
113         ON_BN_CLICKED(IDC_CHECK_SVN_TRUNK, &CCloneDlg::OnBnClickedCheckSvnTrunk)\r
114         ON_BN_CLICKED(IDC_CHECK_SVN_TAG, &CCloneDlg::OnBnClickedCheckSvnTag)\r
115         ON_BN_CLICKED(IDC_CHECK_SVN_BRANCH, &CCloneDlg::OnBnClickedCheckSvnBranch)\r
116 END_MESSAGE_MAP()\r
117 \r
118 \r
119 \r
120 // CCloneDlg message handlers\r
121 \r
122 void CCloneDlg::OnOK()\r
123 {\r
124         this->m_URLCombo.GetWindowTextW(m_URL);\r
125         m_URL.Trim();\r
126         UpdateData(TRUE);\r
127         if(m_URL.IsEmpty() || m_Directory.IsEmpty())\r
128         {\r
129                 CMessageBox::Show(NULL, _T("URL or Directory can't be empty"), _T("TortoiseGit"), MB_OK);\r
130                 return;\r
131         }\r
132 \r
133         m_URLCombo.SaveHistory();\r
134     m_PuttyKeyCombo.SaveHistory();\r
135 \r
136     this->m_PuttyKeyCombo.GetWindowText(m_strPuttyKeyFile);\r
137         CResizableDialog::OnOK();\r
138 \r
139 }\r
140 \r
141 void CCloneDlg::OnCancel()\r
142 {\r
143         CResizableDialog::OnCancel();\r
144 }\r
145 \r
146 void CCloneDlg::OnBnClickedCloneBrowseUrl()\r
147 {\r
148         // TODO: Add your control notification handler code here\r
149         CBrowseFolder browseFolder;\r
150         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
151         CString strCloneDirectory;\r
152         this->m_URLCombo.GetWindowTextW(strCloneDirectory);\r
153         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
154         {\r
155                 this->m_URLCombo.SetWindowTextW(strCloneDirectory);\r
156         }\r
157 }\r
158 \r
159 void CCloneDlg::OnBnClickedCloneDirBrowse()\r
160 {\r
161         // TODO: Add your control notification handler code here\r
162         CBrowseFolder browseFolder;\r
163         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
164         CString strCloneDirectory = this->m_Directory;\r
165         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
166         {\r
167                 UpdateData(TRUE);\r
168                 m_Directory = strCloneDirectory;\r
169                 UpdateData(FALSE);\r
170         }\r
171 }\r
172 \r
173 void CCloneDlg::OnEnChangeCloneDir()\r
174 {\r
175         // TODO:  If this is a RICHEDIT control, the control will not\r
176         // send this notification unless you override the CDHtmlDialog::OnInitDialog()\r
177         // function and call CRichEditCtrl().SetEventMask()\r
178         // with the ENM_CHANGE flag ORed into the mask.\r
179 \r
180         // TODO:  Add your control notification handler code here\r
181 }\r
182 \r
183 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()\r
184 {\r
185     // TODO: Add your control notification handler code here\r
186     CFileDialog dlg(TRUE,NULL,\r
187                                         NULL,\r
188                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\r
189                                         _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));\r
190         \r
191         this->UpdateData();\r
192         if(dlg.DoModal()==IDOK)\r
193         {\r
194         this->m_PuttyKeyCombo.SetWindowText( dlg.GetPathName() );\r
195         }\r
196 \r
197 }\r
198 \r
199 void CCloneDlg::OnBnClickedPuttykeyAutoload()\r
200 {\r
201     // TODO: Add your control notification handler code here\r
202     this->UpdateData();\r
203     this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
204     this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
205 \r
206 }\r
207 \r
208 void CCloneDlg::OnCbnSelchangeUrlcombo()\r
209 {\r
210         // TODO: Add your control notification handler code here\r
211 }\r
212 \r
213 void CCloneDlg::OnCbenBegineditUrlcombo(NMHDR *pNMHDR, LRESULT *pResult)\r
214 {\r
215         // TODO: Add your control notification handler code here\r
216         *pResult = 0;\r
217 }\r
218 \r
219 void CCloneDlg::OnCbenEndeditUrlcombo(NMHDR *pNMHDR, LRESULT *pResult)\r
220 {\r
221         // TODO: Add your control notification handler code here\r
222         *pResult = 0;\r
223 }\r
224 \r
225 void CCloneDlg::OnCbnEditchangeUrlcombo()\r
226 {\r
227         // TODO: Add your control notification handler code here\r
228         this->UpdateData();\r
229         CString url;\r
230         m_URLCombo.GetWindowText(url);\r
231         if(m_OldURL == url )\r
232                 return;\r
233 \r
234         m_OldURL=url;\r
235 \r
236         //if(url.IsEmpty())\r
237         //      return;\r
238 \r
239         CString old;\r
240         old=m_ModuleName;\r
241 \r
242         url.Replace(_T('\\'),_T('/'));\r
243         int start=url.ReverseFind(_T('/'));\r
244         if(start<0)\r
245         {\r
246                 start = url.ReverseFind(_T(':'));\r
247                 if(start <0)\r
248                         start = url.ReverseFind(_T('@'));\r
249 \r
250                 if(start<0)\r
251                         start = 0;\r
252         }\r
253         CString temp;\r
254         temp=url.Mid(start+1);\r
255         \r
256         temp=temp.MakeLower();\r
257 \r
258         int end;\r
259         end=temp.Find(_T(".git"));\r
260         if(end<0)\r
261                 end=temp.GetLength();\r
262 \r
263         //CString modulename;\r
264         m_ModuleName=url.Mid(start+1,end);\r
265         \r
266         start = m_Directory.ReverseFind(_T('\\'));\r
267         if(start <0 )\r
268                 start = m_Directory.ReverseFind(_T('/'));\r
269         if(start <0 )\r
270                 start =0;\r
271 \r
272         int dirstart=m_Directory.Find(old,start);\r
273         if(dirstart>=0 && (dirstart+old.GetLength() == m_Directory.GetLength()) )\r
274         {\r
275                 m_Directory=m_Directory.Left(dirstart);\r
276                 m_Directory+=m_ModuleName;\r
277 \r
278         }else\r
279         {\r
280                 if(m_Directory.GetLength()>0 && \r
281                         (m_Directory[m_Directory.GetLength()-1] != _T('\\') ||\r
282                         m_Directory[m_Directory.GetLength()-1] != _T('/') ) )\r
283                 {\r
284                         m_Directory+=_T('\\');\r
285                 }\r
286                 m_Directory += m_ModuleName;\r
287         }\r
288 \r
289         if(m_Directory.GetLength()>0)\r
290         {\r
291                 if( m_Directory[m_Directory.GetLength()-1] == _T('\\') ||\r
292                         m_Directory[m_Directory.GetLength()-1] == _T('/')\r
293                    )\r
294                 {\r
295                         m_Directory=m_Directory.Left(m_Directory.GetLength()-1);\r
296                 }\r
297 \r
298         }\r
299         this->UpdateData(FALSE);\r
300 }\r
301 \r
302 void CCloneDlg::OnBnClickedCheckSvn()\r
303 {\r
304         // TODO: Add your control notification handler code here\r
305         OnBnClickedCheckSvnTrunk();\r
306         OnBnClickedCheckSvnTag();\r
307         OnBnClickedCheckSvnBranch();\r
308 }\r
309 \r
310 void CCloneDlg::OnBnClickedCheckSvnTrunk()\r
311 {\r
312         // TODO: Add your control notification handler code here\r
313         UpdateData(TRUE);\r
314         this->GetDlgItem(IDC_CHECK_SVN_TRUNK)->EnableWindow(this->m_bSVN);\r
315         this->GetDlgItem(IDC_EDIT_SVN_TRUNK)->EnableWindow(this->m_bSVNTrunk&&this->m_bSVN);\r
316 }\r
317 \r
318 void CCloneDlg::OnBnClickedCheckSvnTag()\r
319 {\r
320         // TODO: Add your control notification handler code here\r
321         UpdateData(TRUE);\r
322         this->GetDlgItem(IDC_CHECK_SVN_TAG)->EnableWindow(this->m_bSVN);\r
323         this->GetDlgItem(IDC_EDIT_SVN_TAG)->EnableWindow(this->m_bSVNTags&&this->m_bSVN);\r
324 }\r
325 \r
326 void CCloneDlg::OnBnClickedCheckSvnBranch()\r
327 {\r
328         // TODO: Add your control notification handler code here\r
329         UpdateData(TRUE);\r
330         this->GetDlgItem(IDC_CHECK_SVN_BRANCH)->EnableWindow(this->m_bSVN);\r
331         this->GetDlgItem(IDC_EDIT_SVN_BRANCH)->EnableWindow(this->m_bSVNBranch&&this->m_bSVN);\r
332 }\r