OSDN Git Service

25b582669cf8f5d7b3056034cf81c944b696a902
[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 END_MESSAGE_MAP()\r
87 \r
88 \r
89 \r
90 // CCloneDlg message handlers\r
91 \r
92 void CCloneDlg::OnOK()\r
93 {\r
94         this->m_URLCombo.GetWindowTextW(m_URL);\r
95         m_URL.Trim();\r
96         UpdateData(TRUE);\r
97         if(m_URL.IsEmpty()||m_Directory.IsEmpty())\r
98         {\r
99                 CMessageBox::Show(NULL,_T("URL or Dir can't empty"),_T("TortiseGit"),MB_OK);\r
100                 return;\r
101         }\r
102 \r
103         m_URLCombo.SaveHistory();\r
104     m_PuttyKeyCombo.SaveHistory();\r
105 \r
106     this->m_PuttyKeyCombo.GetWindowText(m_strPuttyKeyFile );\r
107         CResizableDialog::OnOK();\r
108 \r
109 }\r
110 \r
111 void CCloneDlg::OnCancel()\r
112 {\r
113         CResizableDialog::OnCancel();\r
114 }\r
115 \r
116 void CCloneDlg::OnBnClickedCloneBrowseUrl()\r
117 {\r
118         // TODO: Add your control notification handler code here\r
119         CBrowseFolder browseFolder;\r
120         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
121         CString strCloneDirectory;\r
122         this->m_URLCombo.GetWindowTextW(strCloneDirectory);\r
123         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
124         {\r
125                 this->m_URLCombo.SetWindowTextW(strCloneDirectory);\r
126         }\r
127 }\r
128 \r
129 void CCloneDlg::OnBnClickedCloneDirBrowse()\r
130 {\r
131         // TODO: Add your control notification handler code here\r
132         CBrowseFolder browseFolder;\r
133         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
134         CString strCloneDirectory = this->m_Directory;\r
135         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
136         {\r
137                 UpdateData(TRUE);\r
138                 m_Directory = strCloneDirectory;\r
139                 UpdateData(FALSE);\r
140         }\r
141 }\r
142 \r
143 void CCloneDlg::OnEnChangeCloneDir()\r
144 {\r
145         // TODO:  If this is a RICHEDIT control, the control will not\r
146         // send this notification unless you override the CDHtmlDialog::OnInitDialog()\r
147         // function and call CRichEditCtrl().SetEventMask()\r
148         // with the ENM_CHANGE flag ORed into the mask.\r
149 \r
150         // TODO:  Add your control notification handler code here\r
151 }\r
152 \r
153 void CCloneDlg::OnBnClickedPuttykeyfileBrowse()\r
154 {\r
155     // TODO: Add your control notification handler code here\r
156     CFileDialog dlg(TRUE,NULL,\r
157                                         NULL,\r
158                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\r
159                                         _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));\r
160         \r
161         this->UpdateData();\r
162         if(dlg.DoModal()==IDOK)\r
163         {\r
164         this->m_PuttyKeyCombo.SetWindowText( dlg.GetPathName() );\r
165         }\r
166 \r
167 }\r
168 \r
169 void CCloneDlg::OnBnClickedPuttykeyAutoload()\r
170 {\r
171     // TODO: Add your control notification handler code here\r
172     this->UpdateData();\r
173     this->GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
174     this->GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);\r
175 \r
176 }\r