OSDN Git Service

Fixed issue #88: Ambiguous dialog message
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / SettingGitRemote.cpp
1 // SettingGitRemote.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "SettingGitRemote.h"\r
7 #include "Settings.h"\r
8 #include "GitAdminDir.h"\r
9 #include "MessageBox.h"\r
10 #include "git.h"\r
11 \r
12 // CSettingGitRemote dialog\r
13 \r
14 IMPLEMENT_DYNAMIC(CSettingGitRemote, ISettingsPropPage)\r
15 \r
16 CSettingGitRemote::CSettingGitRemote(CString cmdPath)\r
17         : ISettingsPropPage(CSettingGitRemote::IDD)\r
18     , m_strRemote(_T(""))\r
19     , m_strUrl(_T(""))\r
20     , m_strPuttyKeyfile(_T(""))\r
21         , m_cmdPath(cmdPath)\r
22 {\r
23 \r
24         m_ChangedMask = 0;\r
25 }\r
26 \r
27 CSettingGitRemote::~CSettingGitRemote()\r
28 {\r
29 }\r
30 \r
31 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)\r
32 {\r
33     CPropertyPage::DoDataExchange(pDX);\r
34     DDX_Control(pDX, IDC_LIST_REMOTE, m_ctrlRemoteList);\r
35     DDX_Text(pDX, IDC_EDIT_REMOTE, m_strRemote);\r
36     DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);\r
37     DDX_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);\r
38 }\r
39 \r
40 \r
41 BEGIN_MESSAGE_MAP(CSettingGitRemote, CPropertyPage)\r
42     ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CSettingGitRemote::OnBnClickedButtonBrowse)\r
43     ON_BN_CLICKED(IDC_BUTTON_ADD, &CSettingGitRemote::OnBnClickedButtonAdd)\r
44     ON_LBN_SELCHANGE(IDC_LIST_REMOTE, &CSettingGitRemote::OnLbnSelchangeListRemote)\r
45     ON_EN_CHANGE(IDC_EDIT_REMOTE, &CSettingGitRemote::OnEnChangeEditRemote)\r
46     ON_EN_CHANGE(IDC_EDIT_URL, &CSettingGitRemote::OnEnChangeEditUrl)\r
47     ON_EN_CHANGE(IDC_EDIT_PUTTY_KEY, &CSettingGitRemote::OnEnChangeEditPuttyKey)\r
48 END_MESSAGE_MAP()\r
49 \r
50 BOOL CSettingGitRemote::OnInitDialog()\r
51 {\r
52         ISettingsPropPage::OnInitDialog();\r
53 \r
54         //CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();\r
55         CString proj;\r
56         if(     g_GitAdminDir.HasAdminDir(m_cmdPath,&proj) )\r
57         {\r
58                 this->SetWindowText(CString(_T("Config - "))+proj);\r
59         }\r
60 \r
61         CString cmd,out;\r
62         cmd=_T("git.exe remote");\r
63         if(g_Git.Run(cmd,&out,CP_ACP))\r
64         {\r
65                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
66                 return FALSE;\r
67         }\r
68         int start =0;\r
69         m_ctrlRemoteList.ResetContent();\r
70         do\r
71         {\r
72                 CString one;\r
73                 one=out.Tokenize(_T("\n"),start);\r
74                 if(!one.IsEmpty())\r
75                         this->m_ctrlRemoteList.AddString(one);\r
76 \r
77         }while(start>=0);\r
78         \r
79         this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);\r
80         this->UpdateData(FALSE);\r
81         return TRUE;\r
82 }\r
83 // CSettingGitRemote message handlers\r
84 \r
85 void CSettingGitRemote::OnBnClickedButtonBrowse()\r
86 {\r
87     // TODO: Add your control notification handler code here\r
88         CFileDialog dlg(TRUE,NULL,\r
89                                         NULL,\r
90                                         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\r
91                                         _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));\r
92         \r
93         this->UpdateData();\r
94         if(dlg.DoModal()==IDOK)\r
95         {\r
96                 this->m_strPuttyKeyfile = dlg.GetPathName();\r
97                 this->UpdateData(FALSE);\r
98                 OnEnChangeEditPuttyKey();\r
99         }\r
100         \r
101 \r
102 }\r
103 \r
104 void CSettingGitRemote::OnBnClickedButtonAdd()\r
105 {\r
106     // TODO: Add your control notification handler code here\r
107         this->m_strRemote.Empty();\r
108         this->m_strUrl.Empty();\r
109         this->m_strPuttyKeyfile.Empty();\r
110         this->UpdateData(FALSE);\r
111         this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(TRUE);\r
112         this->m_ChangedMask |= REMOTE_NAME;\r
113         this->m_ctrlRemoteList.SetCurSel(-1);\r
114         GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE);\r
115 }\r
116 \r
117 void CSettingGitRemote::OnLbnSelchangeListRemote()\r
118 {\r
119     // TODO: Add your control notification handler code here\r
120         CWaitCursor wait;\r
121 \r
122         if(m_ChangedMask)\r
123         {\r
124                 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),\r
125                                                                  _T("TortoiseGit"),1,NULL,_T("Save"),_T("Discard")) == 1)\r
126                 {\r
127                         OnApply();\r
128                 }\r
129         }\r
130         SetModified(FALSE);\r
131         \r
132         CString cmd,output;\r
133         int index;\r
134         index = this->m_ctrlRemoteList.GetCurSel();\r
135         if(index<0)\r
136                 return;\r
137 \r
138         CString remote;\r
139         m_ctrlRemoteList.GetText(index,remote);\r
140         this->m_strRemote=remote;\r
141 \r
142         cmd.Format(_T("git.exe config remote.%s.url"),remote);\r
143         m_strUrl.Empty();\r
144         if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )\r
145         {\r
146                 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
147                 //return;\r
148         }\r
149         \r
150         int start=0;\r
151         m_strUrl = m_strUrl.Tokenize(_T("\n"),start);\r
152 \r
153 \r
154         cmd.Format(_T("git.exe config remote.%s.puttykeyfile"),remote);\r
155         this->m_strPuttyKeyfile.Empty();\r
156         if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )\r
157         {\r
158                 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
159                 //return;\r
160         }\r
161         start=0;\r
162         m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);\r
163         \r
164 \r
165         m_ChangedMask=0;\r
166 \r
167         GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);\r
168         this->UpdateData(FALSE);\r
169 \r
170 }\r
171 \r
172 void CSettingGitRemote::OnEnChangeEditRemote()\r
173 {\r
174     // TODO:  If this is a RICHEDIT control, the control will not\r
175     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
176     // function and call CRichEditCtrl().SetEventMask()\r
177     // with the ENM_CHANGE flag ORed into the mask.\r
178 \r
179     // TODO:  Add your control notification handler code here\r
180 \r
181         m_ChangedMask|=REMOTE_NAME;\r
182 \r
183         this->SetModified();\r
184 }\r
185 \r
186 void CSettingGitRemote::OnEnChangeEditUrl()\r
187 {\r
188     // TODO:  If this is a RICHEDIT control, the control will not\r
189     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
190     // function and call CRichEditCtrl().SetEventMask()\r
191     // with the ENM_CHANGE flag ORed into the mask.\r
192 \r
193     // TODO:  Add your control notification handler code here\r
194         m_ChangedMask|=REMOTE_URL;\r
195         this->SetModified();\r
196 }\r
197 \r
198 void CSettingGitRemote::OnEnChangeEditPuttyKey()\r
199 {\r
200     // TODO:  If this is a RICHEDIT control, the control will not\r
201     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
202     // function and call CRichEditCtrl().SetEventMask()\r
203     // with the ENM_CHANGE flag ORed into the mask.\r
204 \r
205     // TODO:  Add your control notification handler code here\r
206         m_ChangedMask|=REMOTE_PUTTYKEY;\r
207         this->SetModified();\r
208 }\r
209 void CSettingGitRemote::Save(CString key,CString value)\r
210 {\r
211         CString cmd,out;\r
212         cmd.Format(_T("git.exe config remote.%s.%s \"%s\""),this->m_strRemote,key,value);\r
213         if(g_Git.Run(cmd,&out,CP_ACP))\r
214         {\r
215                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
216         }\r
217 }\r
218 BOOL CSettingGitRemote::OnApply()\r
219 {\r
220         CWaitCursor wait;\r
221         this->UpdateData();\r
222         if(m_ChangedMask & REMOTE_NAME)\r
223         {\r
224                 //Add Remote\r
225                 if( this->m_strRemote.IsEmpty() || this->m_strUrl.IsEmpty() )\r
226                 {\r
227                         CMessageBox::Show(NULL,_T("Remote Name and URL can't be Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
228                         return FALSE;\r
229                 }\r
230                 CString cmd,out;\r
231                 cmd.Format(_T("git.exe remote add \"%s\" \"%s\""),m_strRemote,m_strUrl);\r
232                 if(g_Git.Run(cmd,&out,CP_ACP))\r
233                 {\r
234                         CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);\r
235                         return FALSE;\r
236                 }\r
237                 m_ChangedMask &= ~REMOTE_URL;\r
238 \r
239                 this->m_ctrlRemoteList.AddString(m_strRemote);\r
240                 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);\r
241         }\r
242         if(m_ChangedMask & REMOTE_URL)\r
243         {\r
244                 Save(_T("url"),this->m_strUrl);\r
245         }\r
246 \r
247         if(m_ChangedMask & REMOTE_PUTTYKEY)\r
248         {\r
249                 Save(_T("puttykeyfile"),this->m_strPuttyKeyfile);\r
250         }\r
251 \r
252         this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);\r
253     SetModified(FALSE);\r
254 \r
255         m_ChangedMask = 0;\r
256         return ISettingsPropPage::OnApply();\r
257 }