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_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);
\r
40 BEGIN_MESSAGE_MAP(CSettingGitRemote, CPropertyPage)
\r
41 ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CSettingGitRemote::OnBnClickedButtonBrowse)
\r
42 ON_BN_CLICKED(IDC_BUTTON_ADD, &CSettingGitRemote::OnBnClickedButtonAdd)
\r
43 ON_LBN_SELCHANGE(IDC_LIST_REMOTE, &CSettingGitRemote::OnLbnSelchangeListRemote)
\r
44 ON_EN_CHANGE(IDC_EDIT_REMOTE, &CSettingGitRemote::OnEnChangeEditRemote)
\r
45 ON_EN_CHANGE(IDC_EDIT_URL, &CSettingGitRemote::OnEnChangeEditUrl)
\r
46 ON_EN_CHANGE(IDC_EDIT_PUTTY_KEY, &CSettingGitRemote::OnEnChangeEditPuttyKey)
\r
49 BOOL CSettingGitRemote::OnInitDialog()
\r
51 ISettingsPropPage::OnInitDialog();
\r
53 CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
\r
55 if( g_GitAdminDir.HasAdminDir(str,&proj) )
\r
57 this->SetWindowText(CString(_T("Config - "))+proj);
\r
61 cmd=_T("git.exe remote");
\r
62 if(g_Git.Run(cmd,&out,CP_ACP))
\r
64 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
68 m_ctrlRemoteList.ResetContent();
\r
72 one=out.Tokenize(_T("\n"),start);
\r
74 this->m_ctrlRemoteList.AddString(one);
\r
78 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
79 this->UpdateData(FALSE);
\r
82 // CSettingGitRemote message handlers
\r
84 void CSettingGitRemote::OnBnClickedButtonBrowse()
\r
86 // TODO: Add your control notification handler code here
\r
87 CFileDialog dlg(TRUE,NULL,
\r
89 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
\r
90 _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));
\r
93 if(dlg.DoModal()==IDOK)
\r
95 this->m_strPuttyKeyfile = dlg.GetPathName();
\r
96 this->UpdateData(FALSE);
\r
97 OnEnChangeEditPuttyKey();
\r
103 void CSettingGitRemote::OnBnClickedButtonAdd()
\r
105 // TODO: Add your control notification handler code here
\r
106 this->m_strRemote.Empty();
\r
107 this->m_strUrl.Empty();
\r
108 this->m_strPuttyKeyfile.Empty();
\r
109 this->UpdateData(FALSE);
\r
110 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(TRUE);
\r
111 this->m_ChangedMask |= REMOTE_NAME;
\r
112 this->m_ctrlRemoteList.SetCurSel(-1);
\r
113 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE);
\r
116 void CSettingGitRemote::OnLbnSelchangeListRemote()
\r
118 // TODO: Add your control notification handler code here
\r
123 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),
\r
124 _T("TortoiseGit"),MB_YESNO) == IDYES)
\r
129 SetModified(FALSE);
\r
131 CString cmd,output;
\r
133 index = this->m_ctrlRemoteList.GetCurSel();
\r
138 m_ctrlRemoteList.GetText(index,remote);
\r
139 this->m_strRemote=remote;
\r
141 cmd.Format(_T("git.exe config remote.%s.url"),remote);
\r
143 if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )
\r
145 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
150 m_strUrl = m_strUrl.Tokenize(_T("\n"),start);
\r
153 cmd.Format(_T("git.exe config remote.%s.puttykey"),remote);
\r
154 this->m_strPuttyKeyfile.Empty();
\r
155 if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )
\r
157 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
161 m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);
\r
166 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
167 this->UpdateData(FALSE);
\r
171 void CSettingGitRemote::OnEnChangeEditRemote()
\r
173 // TODO: If this is a RICHEDIT control, the control will not
\r
174 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
175 // function and call CRichEditCtrl().SetEventMask()
\r
176 // with the ENM_CHANGE flag ORed into the mask.
\r
178 // TODO: Add your control notification handler code here
\r
180 m_ChangedMask|=REMOTE_NAME;
\r
182 this->SetModified();
\r
185 void CSettingGitRemote::OnEnChangeEditUrl()
\r
187 // TODO: If this is a RICHEDIT control, the control will not
\r
188 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
189 // function and call CRichEditCtrl().SetEventMask()
\r
190 // with the ENM_CHANGE flag ORed into the mask.
\r
192 // TODO: Add your control notification handler code here
\r
193 m_ChangedMask|=REMOTE_URL;
\r
194 this->SetModified();
\r
197 void CSettingGitRemote::OnEnChangeEditPuttyKey()
\r
199 // TODO: If this is a RICHEDIT control, the control will not
\r
200 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
201 // function and call CRichEditCtrl().SetEventMask()
\r
202 // with the ENM_CHANGE flag ORed into the mask.
\r
204 // TODO: Add your control notification handler code here
\r
205 m_ChangedMask|=REMOTE_PUTTYKEY;
\r
206 this->SetModified();
\r
208 void CSettingGitRemote::Save(CString key,CString value)
\r
211 cmd.Format(_T("git.exe config remote.%s.%s \"%s\""),this->m_strRemote,key,value);
\r
212 if(g_Git.Run(cmd,&out,CP_ACP))
\r
214 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
217 BOOL CSettingGitRemote::OnApply()
\r
220 this->UpdateData();
\r
221 if(m_ChangedMask & REMOTE_NAME)
\r
224 if( this->m_strRemote.IsEmpty() || this->m_strUrl.IsEmpty() )
\r
226 CMessageBox::Show(NULL,_T("Remote Name and URL can't be Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
230 cmd.Format(_T("git.exe remote add \"%s\" \"%s\""),m_strRemote,m_strUrl);
\r
231 if(g_Git.Run(cmd,&out,CP_ACP))
\r
233 CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);
\r
236 m_ChangedMask &= ~REMOTE_URL;
\r
238 this->m_ctrlRemoteList.AddString(m_strRemote);
\r
239 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
241 if(m_ChangedMask & REMOTE_URL)
\r
243 Save(_T("url"),this->m_strUrl);
\r
246 if(m_ChangedMask & REMOTE_PUTTYKEY)
\r
248 Save(_T("puttykey"),this->m_strPuttyKeyfile);
\r
251 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
252 SetModified(FALSE);
\r
255 return ISettingsPropPage::OnApply();
\r