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(CString cmdPath)
\r
17 : ISettingsPropPage(CSettingGitRemote::IDD)
\r
18 , m_strRemote(_T(""))
\r
20 , m_strPuttyKeyfile(_T(""))
\r
21 , m_cmdPath(cmdPath)
\r
27 CSettingGitRemote::~CSettingGitRemote()
\r
31 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)
\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
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
50 BOOL CSettingGitRemote::OnInitDialog()
\r
52 ISettingsPropPage::OnInitDialog();
\r
54 //CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
\r
56 if( g_GitAdminDir.HasAdminDir(m_cmdPath,&proj) )
\r
58 this->SetWindowText(CString(_T("Config - "))+proj);
\r
62 cmd=_T("git.exe remote");
\r
63 if(g_Git.Run(cmd,&out,CP_ACP))
\r
65 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
69 m_ctrlRemoteList.ResetContent();
\r
73 one=out.Tokenize(_T("\n"),start);
\r
75 this->m_ctrlRemoteList.AddString(one);
\r
79 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
80 this->UpdateData(FALSE);
\r
83 // CSettingGitRemote message handlers
\r
85 void CSettingGitRemote::OnBnClickedButtonBrowse()
\r
87 // TODO: Add your control notification handler code here
\r
88 CFileDialog dlg(TRUE,NULL,
\r
90 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
\r
91 _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));
\r
94 if(dlg.DoModal()==IDOK)
\r
96 this->m_strPuttyKeyfile = dlg.GetPathName();
\r
97 this->UpdateData(FALSE);
\r
98 OnEnChangeEditPuttyKey();
\r
104 void CSettingGitRemote::OnBnClickedButtonAdd()
\r
106 // TODO: Add your control notification handler code here
\r
107 if( this->m_ctrlRemoteList.GetCount() == 0)
\r
109 this->m_strRemote = _T("origin");
\r
113 this->m_strRemote.Empty();
\r
115 this->m_strUrl.Empty();
\r
116 this->m_strPuttyKeyfile.Empty();
\r
117 this->UpdateData(FALSE);
\r
118 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(TRUE);
\r
119 this->m_ChangedMask |= REMOTE_NAME;
\r
120 this->m_ctrlRemoteList.SetCurSel(-1);
\r
121 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE);
\r
124 void CSettingGitRemote::OnLbnSelchangeListRemote()
\r
126 // TODO: Add your control notification handler code here
\r
131 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),
\r
132 _T("TortoiseGit"),1,NULL,_T("Save"),_T("Discard")) == 1)
\r
137 SetModified(FALSE);
\r
139 CString cmd,output;
\r
141 index = this->m_ctrlRemoteList.GetCurSel();
\r
146 m_ctrlRemoteList.GetText(index,remote);
\r
147 this->m_strRemote=remote;
\r
149 cmd.Format(_T("git.exe config remote.%s.url"),remote);
\r
151 if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )
\r
153 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
158 m_strUrl = m_strUrl.Tokenize(_T("\n"),start);
\r
161 cmd.Format(_T("git.exe config remote.%s.puttykeyfile"),remote);
\r
162 this->m_strPuttyKeyfile.Empty();
\r
163 if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )
\r
165 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
169 m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);
\r
174 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
175 this->UpdateData(FALSE);
\r
179 void CSettingGitRemote::OnEnChangeEditRemote()
\r
181 // TODO: If this is a RICHEDIT control, the control will not
\r
182 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
183 // function and call CRichEditCtrl().SetEventMask()
\r
184 // with the ENM_CHANGE flag ORed into the mask.
\r
186 // TODO: Add your control notification handler code here
\r
188 m_ChangedMask|=REMOTE_NAME;
\r
190 this->SetModified();
\r
193 void CSettingGitRemote::OnEnChangeEditUrl()
\r
195 // TODO: If this is a RICHEDIT control, the control will not
\r
196 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
197 // function and call CRichEditCtrl().SetEventMask()
\r
198 // with the ENM_CHANGE flag ORed into the mask.
\r
200 // TODO: Add your control notification handler code here
\r
201 m_ChangedMask|=REMOTE_URL;
\r
202 this->SetModified();
\r
205 void CSettingGitRemote::OnEnChangeEditPuttyKey()
\r
207 // TODO: If this is a RICHEDIT control, the control will not
\r
208 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
\r
209 // function and call CRichEditCtrl().SetEventMask()
\r
210 // with the ENM_CHANGE flag ORed into the mask.
\r
212 // TODO: Add your control notification handler code here
\r
213 m_ChangedMask|=REMOTE_PUTTYKEY;
\r
214 this->SetModified();
\r
216 void CSettingGitRemote::Save(CString key,CString value)
\r
219 cmd.Format(_T("git.exe config remote.%s.%s \"%s\""),this->m_strRemote,key,value);
\r
220 if(g_Git.Run(cmd,&out,CP_ACP))
\r
222 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
225 BOOL CSettingGitRemote::OnApply()
\r
228 this->UpdateData();
\r
229 if(m_ChangedMask & REMOTE_NAME)
\r
232 if( this->m_strRemote.IsEmpty() || this->m_strUrl.IsEmpty() )
\r
234 CMessageBox::Show(NULL,_T("Remote Name and URL can't be Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
\r
238 cmd.Format(_T("git.exe remote add \"%s\" \"%s\""),m_strRemote,m_strUrl);
\r
239 if(g_Git.Run(cmd,&out,CP_ACP))
\r
241 CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);
\r
244 m_ChangedMask &= ~REMOTE_URL;
\r
246 this->m_ctrlRemoteList.AddString(m_strRemote);
\r
247 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
\r
249 if(m_ChangedMask & REMOTE_URL)
\r
251 Save(_T("url"),this->m_strUrl);
\r
254 if(m_ChangedMask & REMOTE_PUTTYKEY)
\r
256 Save(_T("puttykeyfile"),this->m_strPuttyKeyfile);
\r
259 this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
\r
260 SetModified(FALSE);
\r
263 return ISettingsPropPage::OnApply();
\r