OSDN Git Service

77b712df11525f0402e100a458b15b35d6f84d85
[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 \r
21 CCloneDlg::~CCloneDlg()\r
22 {\r
23 }\r
24 \r
25 void CCloneDlg::DoDataExchange(CDataExchange* pDX)\r
26 {\r
27         CResizableStandAloneDialog::DoDataExchange(pDX);\r
28         DDX_Control(pDX, IDC_URLCOMBO, m_URLCombo);\r
29     DDX_Control(pDX, IDC_PUTTYKEYFILE, m_PuttyKeyCombo);\r
30         DDX_Text(pDX, IDC_CLONE_DIR, m_Directory);\r
31     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD, m_bAutoloadPuttyKeyFile);\r
32 \r
33 }\r
34 \r
35 BOOL CCloneDlg::OnInitDialog()\r
36 {\r
37         CResizableStandAloneDialog::OnInitDialog();\r
38         AddAnchor(IDC_URLCOMBO, TOP_LEFT, TOP_RIGHT);\r
39         AddAnchor(IDC_CLONE_BROWSE_URL, TOP_RIGHT);\r
40         AddAnchor(IDC_CLONE_DIR, TOP_LEFT,TOP_RIGHT);\r
41         AddAnchor(IDC_CLONE_DIR_BROWSE, TOP_RIGHT);\r
42         AddAnchor(IDOK,BOTTOM_RIGHT);\r
43         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
44 \r
45     AddAnchor(IDC_GROUP_CLONE,TOP_LEFT,BOTTOM_RIGHT);\r
46     AddAnchor(IDC_PUTTYKEYFILE_BROWSE,BOTTOM_RIGHT);\r
47     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);\r
48     AddAnchor(IDC_PUTTYKEYFILE,BOTTOM_LEFT,BOTTOM_RIGHT);\r
49 \r
50         this->AddOthersToAnchor();\r
51 \r
52         m_URLCombo.SetURLHistory(TRUE);\r
53         m_URLCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));\r
54         if(m_URL.IsEmpty())\r
55         {\r
56                 CString str=CAppUtils::GetClipboardLink();\r
57                 if(str.IsEmpty())\r
58                         m_URLCombo.SetCurSel(0);\r
59                 else\r
60                         m_URLCombo.SetWindowText(str);\r
61         }\r
62         else\r
63                 m_URLCombo.SetWindowText(m_URL);\r
64 \r
65         CWnd *window=this->GetDlgItem(IDC_CLONE_DIR);\r
66         if(window)\r
67                 SHAutoComplete(window->m_hWnd, SHACF_FILESYSTEM);\r
68 \r
69     m_PuttyKeyCombo.SetPathHistory(TRUE);\r
70     m_PuttyKeyCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));\r
71     m_PuttyKeyCombo.SetCurSel(0);\r
72 \r
73     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow( CAppUtils::IsSSHPutty() );\r
74     this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
75     this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
76        \r
77     EnableSaveRestore(_T("CloneDlg"));\r
78         return TRUE;  // return TRUE  unless you set the focus to a control\r
79 }\r
80 \r
81 BEGIN_MESSAGE_MAP(CCloneDlg, CResizableStandAloneDialog)\r
82         ON_BN_CLICKED(IDC_CLONE_BROWSE_URL, &CCloneDlg::OnBnClickedCloneBrowseUrl)\r
83         ON_BN_CLICKED(IDC_CLONE_DIR_BROWSE, &CCloneDlg::OnBnClickedCloneDirBrowse)\r
84     ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE, &CCloneDlg::OnBnClickedPuttykeyfileBrowse)\r
85     ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD, &CCloneDlg::OnBnClickedPuttykeyAutoload)\r
86         ON_CBN_SELCHANGE(IDC_URLCOMBO, &CCloneDlg::OnCbnSelchangeUrlcombo)\r
87         ON_NOTIFY(CBEN_BEGINEDIT, IDC_URLCOMBO, &CCloneDlg::OnCbenBegineditUrlcombo)\r
88         ON_NOTIFY(CBEN_ENDEDIT, IDC_URLCOMBO, &CCloneDlg::OnCbenEndeditUrlcombo)\r
89         ON_CBN_EDITCHANGE(IDC_URLCOMBO, &CCloneDlg::OnCbnEditchangeUrlcombo)\r
90 END_MESSAGE_MAP()\r
91 \r
92 \r
93 \r
94 // CCloneDlg message handlers\r
95 \r
96 void CCloneDlg::OnOK()\r
97 {\r
98         this->m_URLCombo.GetWindowTextW(m_URL);\r
99         m_URL.Trim();\r
100         UpdateData(TRUE);\r
101         if(m_URL.IsEmpty() || m_Directory.IsEmpty())\r
102         {\r
103                 CMessageBox::Show(NULL, _T("URL or Directory can't be empty"), _T("TortoiseGit"), MB_OK);\r
104                 return;\r
105         }\r
106 \r
107         m_URLCombo.SaveHistory();\r
108     m_PuttyKeyCombo.SaveHistory();\r
109 \r
110     this->m_PuttyKeyCombo.GetWindowText(m_strPuttyKeyFile);\r
111         CResizableDialog::OnOK();\r
112 \r
113 }\r
114 \r
115 void CCloneDlg::OnCancel()\r
116 {\r
117         CResizableDialog::OnCancel();\r
118 }\r
119 \r
120 void CCloneDlg::OnBnClickedCloneBrowseUrl()\r
121 {\r
122         // TODO: Add your control notification handler code here\r
123         CBrowseFolder browseFolder;\r
124         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
125         CString strCloneDirectory;\r
126         this->m_URLCombo.GetWindowTextW(strCloneDirectory);\r
127         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
128         {\r
129                 this->m_URLCombo.SetWindowTextW(strCloneDirectory);\r
130         }\r
131 }\r
132 \r
133 void CCloneDlg::OnBnClickedCloneDirBrowse()\r
134 {\r
135         // TODO: Add your control notification handler code here\r
136         CBrowseFolder browseFolder;\r
137         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
138         CString strCloneDirectory = this->m_Directory;\r
139         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
140         {\r
141                 UpdateData(TRUE);\r
142                 m_Directory = strCloneDirectory;\r
143                 UpdateData(FALSE);\r
144         }\r
145 }\r
146 \r
147 void CCloneDlg::OnEnChangeCloneDir()\r
148 {\r
149         // TODO:  If this is a RICHEDIT control, the control will not\r
150         // send this notification unless you override the CDHtmlDialog::OnInitDialog()\r
151         // function and call CRichEditCtrl().SetEventMask()\r
152         // with the ENM_CHANGE flag ORed into the mask.\r
153 \r
154         // TODO:  Add your control notification handler code here\r
155 }\r
156 \r
157 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()\r
158 {\r
159     // TODO: Add your control notification handler code here\r
160     CFileDialog dlg(TRUE,NULL,\r
161                                         NULL,\r
162                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\r
163                                         _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));\r
164         \r
165         this->UpdateData();\r
166         if(dlg.DoModal()==IDOK)\r
167         {\r
168         this->m_PuttyKeyCombo.SetWindowText( dlg.GetPathName() );\r
169         }\r
170 \r
171 }\r
172 \r
173 void CCloneDlg::OnBnClickedPuttykeyAutoload()\r
174 {\r
175     // TODO: Add your control notification handler code here\r
176     this->UpdateData();\r
177     this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
178     this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
179 \r
180 }\r
181 \r
182 void CCloneDlg::OnCbnSelchangeUrlcombo()\r
183 {\r
184         // TODO: Add your control notification handler code here\r
185 }\r
186 \r
187 void CCloneDlg::OnCbenBegineditUrlcombo(NMHDR *pNMHDR, LRESULT *pResult)\r
188 {\r
189         // TODO: Add your control notification handler code here\r
190         *pResult = 0;\r
191 }\r
192 \r
193 void CCloneDlg::OnCbenEndeditUrlcombo(NMHDR *pNMHDR, LRESULT *pResult)\r
194 {\r
195         // TODO: Add your control notification handler code here\r
196         *pResult = 0;\r
197 }\r
198 \r
199 void CCloneDlg::OnCbnEditchangeUrlcombo()\r
200 {\r
201         // TODO: Add your control notification handler code here\r
202         this->UpdateData();\r
203         CString url;\r
204         m_URLCombo.GetWindowText(url);\r
205         //if(url.IsEmpty())\r
206         //      return;\r
207 \r
208         CString old;\r
209         old=m_ModuleName;\r
210 \r
211         url.Replace(_T('\\'),_T('/'));\r
212         int start=url.ReverseFind(_T('/'));\r
213         if(start<0)\r
214                 start = 0;\r
215 \r
216         CString temp;\r
217         temp=url.Mid(start+1);\r
218         \r
219         temp=temp.MakeLower();\r
220 \r
221         int end;\r
222         end=temp.Find(_T(".git"));\r
223         if(end<0)\r
224                 end=temp.GetLength();\r
225 \r
226         //CString modulename;\r
227         m_ModuleName=url.Mid(start+1,end);\r
228         \r
229         start = m_Directory.ReverseFind(_T('\\'));\r
230         if(start <0 )\r
231                 start = m_Directory.ReverseFind(_T('/'));\r
232         if(start <0 )\r
233                 start =0;\r
234 \r
235         int dirstart=m_Directory.Find(old,start);\r
236         if(dirstart>=0 && (dirstart+old.GetLength() == m_Directory.GetLength()) )\r
237         {\r
238                 m_Directory=m_Directory.Left(dirstart);\r
239                 m_Directory+=m_ModuleName;\r
240 \r
241         }else\r
242         {\r
243                 if(m_Directory.GetLength()>0 && \r
244                         (m_Directory[m_Directory.GetLength()-1] != _T('\\') ||\r
245                         m_Directory[m_Directory.GetLength()-1] != _T('/') ) )\r
246                 {\r
247                         m_Directory+=_T('\\');\r
248                 }\r
249                 m_Directory += m_ModuleName;\r
250         }\r
251 \r
252         if(m_Directory.GetLength()>0)\r
253         {\r
254                 if( m_Directory[m_Directory.GetLength()-1] == _T('\\') ||\r
255                         m_Directory[m_Directory.GetLength()-1] == _T('/')\r
256                    )\r
257                 {\r
258                         m_Directory=m_Directory.Left(m_Directory.GetLength()-1);\r
259                 }\r
260 \r
261         }\r
262         this->UpdateData(FALSE);\r
263 }\r