1 // SettingGitRemote.cpp : implementation file
\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
12 // CSettingGitRemote dialog
\r
14 IMPLEMENT_DYNAMIC(CSettingGitRemote, ISettingsPropPage)
\r
16 CSettingGitRemote::CSettingGitRemote()
\r
17 : ISettingsPropPage(CSettingGitRemote::IDD)
\r
18 , m_strRemote(_T(""))
\r
20 , m_strPuttyKeyfile(_T(""))
\r
26 CSettingGitRemote::~CSettingGitRemote()
\r
30 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)
\r
32 CPropertyPage::DoDataExchange(pDX);
\r
33 DDX_Control(pDX, IDC_LIST_REMOTE, m_ctrlRemoteList);
\r
34 DDX_Text(pDX, IDC_EDIT_REMOTE, m_strRemote);
\r
35 DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);
\r
36 DDX_Control(pDX, IDC_CHECK_ISAUTOLOADPUTTYKEY, m_bAutoLoad);
\r
37 DDX_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);
\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_BN_CLICKED(IDC_CHECK_ISAUTOLOADPUTTYKEY, &CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey)
\r
48 ON_EN_CHANGE(IDC_EDIT_PUTTY_KEY, &CSettingGitRemote::OnEnChangeEditPuttyKey)
\r
51 BOOL CSettingGitRemote::OnInitDialog()
\r
53 ISettingsPropPage::OnInitDialog();
\r
55 CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
\r
57 if( g_GitAdminDir.HasAdminDir(str,&proj) )
\r
59 this->SetWindowText(CString(_T("Config - "))+proj);
\r
63 cmd=_T("git.exe remote");
\r
64 if(g_Git.Run(cmd,&out,CP_ACP))
\r
66 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
70 m_ctrlRemoteList.ResetContent();
\r
74 one=out.Tokenize(_T("\n"),start);
\r
76 this->m_ctrlRemoteList.AddString(one);
\r
80 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
81 this->UpdateData(FALSE);
\r
84 // CSettingGitRemote message handlers
\r
86 void CSettingGitRemote::OnBnClickedButtonBrowse()
\r
88 // TODO: Add your control notification handler code here
\r
89 CFileDialog dlg(TRUE,NULL,
\r
91 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
\r
92 _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));
\r
95 if(dlg.DoModal()==IDOK)
\r
97 this->m_strPuttyKeyfile = dlg.GetPathName();
\r
98 this->UpdateData(FALSE);
\r
99 OnEnChangeEditPuttyKey();
\r
105 void CSettingGitRemote::OnBnClickedButtonAdd()
\r
107 // TODO: Add your control notification handler code here
\r
108 this->m_strRemote.Empty();
\r
109 this->m_strUrl.Empty();
\r
110 this->m_strPuttyKeyfile.Empty();
\r
111 this->m_bAutoLoad.SetCheck(false);
\r
112 this->UpdateData(FALSE);
\r
113 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(TRUE);
\r
114 this->m_ChangedMask |= REMOTE_NAME;
\r
115 this->m_ctrlRemoteList.SetCurSel(-1);
\r
116 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE);
\r
119 void CSettingGitRemote::OnLbnSelchangeListRemote()
\r
121 // TODO: Add your control notification handler code here
\r
126 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),
\r
127 _T("TortoiseGit"),MB_YESNO) == IDYES)
\r
132 SetModified(FALSE);
\r
134 CString cmd,output;
\r
136 index = this->m_ctrlRemoteList.GetCurSel();
\r
141 m_ctrlRemoteList.GetText(index,remote);
\r
142 this->m_strRemote=remote;
\r
144 cmd.Format(_T("git.exe config remote.%s.url"),remote);
\r
146 if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )
\r
148 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
153 m_strUrl = m_strUrl.Tokenize(_T("\n"),start);
\r
156 cmd.Format(_T("git.exe config remote.%s.puttykey"),remote);
\r
157 this->m_strPuttyKeyfile.Empty();
\r
158 if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )
\r
160 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
164 m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);
\r
167 cmd.Format(_T("git.exe config remote.%s.puttykeyautoload"),remote);
\r
169 if( g_Git.Run(cmd,&autoload,CP_ACP) )
\r
171 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
176 autoload = autoload.Tokenize(_T("\n"),start);
\r
177 m_bAutoLoad.SetCheck(false);
\r
178 if( autoload == _T("true"))
\r
180 m_bAutoLoad.SetCheck(true);
\r
185 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
186 this->UpdateData(FALSE);
\r
190 void CSettingGitRemote::OnEnChangeEditRemote()
\r
192 // TODO: If this is a RICHEDIT control, the control will not
\r
193 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
194 // function and call CRichEditCtrl().SetEventMask()
\r
195 // with the ENM_CHANGE flag ORed into the mask.
\r
197 // TODO: Add your control notification handler code here
\r
199 m_ChangedMask|=REMOTE_NAME;
\r
201 this->SetModified();
\r
204 void CSettingGitRemote::OnEnChangeEditUrl()
\r
206 // TODO: If this is a RICHEDIT control, the control will not
\r
207 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
208 // function and call CRichEditCtrl().SetEventMask()
\r
209 // with the ENM_CHANGE flag ORed into the mask.
\r
211 // TODO: Add your control notification handler code here
\r
212 m_ChangedMask|=REMOTE_URL;
\r
213 this->SetModified();
\r
216 void CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey()
\r
218 // TODO: Add your control notification handler code here
\r
219 m_ChangedMask|=REMOTE_AUTOLOAD;
\r
220 this->SetModified();
\r
223 void CSettingGitRemote::OnEnChangeEditPuttyKey()
\r
225 // TODO: If this is a RICHEDIT control, the control will not
\r
226 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
227 // function and call CRichEditCtrl().SetEventMask()
\r
228 // with the ENM_CHANGE flag ORed into the mask.
\r
230 // TODO: Add your control notification handler code here
\r
231 m_ChangedMask|=REMOTE_PUTTYKEY;
\r
232 this->SetModified();
\r
234 void CSettingGitRemote::Save(CString key,CString value)
\r
237 cmd.Format(_T("git.exe config remote.%s.%s \"%s\""),this->m_strRemote,key,value);
\r
238 if(g_Git.Run(cmd,&out,CP_ACP))
\r
240 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
243 BOOL CSettingGitRemote::OnApply()
\r
246 this->UpdateData();
\r
247 if(m_ChangedMask & REMOTE_NAME)
\r
250 if( this->m_strRemote.IsEmpty() || this->m_strUrl.IsEmpty() )
\r
252 CMessageBox::Show(NULL,_T("Remote Name and URL can't be Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
256 cmd.Format(_T("git.exe remote add \"%s\" \"%s\""),m_strRemote,m_strUrl);
\r
257 if(g_Git.Run(cmd,&out,CP_ACP))
\r
259 CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);
\r
262 m_ChangedMask &= ~REMOTE_URL;
\r
264 this->m_ctrlRemoteList.AddString(m_strRemote);
\r
265 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
267 if(m_ChangedMask & REMOTE_URL)
\r
269 Save(_T("url"),this->m_strUrl);
\r
272 if(m_ChangedMask & REMOTE_PUTTYKEY)
\r
274 Save(_T("puttykey"),this->m_strPuttyKeyfile);
\r
277 if(m_ChangedMask & REMOTE_AUTOLOAD)
\r
279 Save(_T("puttykeyautoload"),this->m_bAutoLoad.GetCheck()?_T("true"):_T("false"));
\r
281 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
282 SetModified(FALSE);
\r
285 return ISettingsPropPage::OnApply();
\r