Setting dialog, remote list work.
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingGitRemote.cpp
blob7c51ad89a69d6a32981d42fc7e50b09810db1f57
1 // SettingGitRemote.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "SettingGitRemote.h"
7 #include "Settings.h"
8 #include "GitAdminDir.h"
9 #include "MessageBox.h"
10 #include "git.h"
12 // CSettingGitRemote dialog
14 IMPLEMENT_DYNAMIC(CSettingGitRemote, ISettingsPropPage)
16 CSettingGitRemote::CSettingGitRemote()
17 : ISettingsPropPage(CSettingGitRemote::IDD)
18 , m_strRemote(_T(""))
19 , m_strUrl(_T(""))
20 , m_strPuttyKeyfile(_T(""))
22 m_bChanged=FALSE;
25 CSettingGitRemote::~CSettingGitRemote()
29 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)
31 CPropertyPage::DoDataExchange(pDX);
32 DDX_Control(pDX, IDC_LIST_REMOTE, m_ctrlRemoteList);
33 DDX_Text(pDX, IDC_EDIT_REMOTE, m_strRemote);
34 DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);
35 DDX_Control(pDX, IDC_CHECK_ISAUTOLOADPUTTYKEY, m_bAutoLoad);
36 DDX_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);
40 BEGIN_MESSAGE_MAP(CSettingGitRemote, CPropertyPage)
41 ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CSettingGitRemote::OnBnClickedButtonBrowse)
42 ON_BN_CLICKED(IDC_BUTTON_ADD, &CSettingGitRemote::OnBnClickedButtonAdd)
43 ON_LBN_SELCHANGE(IDC_LIST_REMOTE, &CSettingGitRemote::OnLbnSelchangeListRemote)
44 ON_EN_CHANGE(IDC_EDIT_REMOTE, &CSettingGitRemote::OnEnChangeEditRemote)
45 ON_EN_CHANGE(IDC_EDIT_URL, &CSettingGitRemote::OnEnChangeEditUrl)
46 ON_BN_CLICKED(IDC_CHECK_ISAUTOLOADPUTTYKEY, &CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey)
47 ON_EN_CHANGE(IDC_EDIT_PUTTY_KEY, &CSettingGitRemote::OnEnChangeEditPuttyKey)
48 END_MESSAGE_MAP()
50 BOOL CSettingGitRemote::OnInitDialog()
52 ISettingsPropPage::OnInitDialog();
54 CString str=((CSettings*)GetParent())->m_CmdPath.GetWinPath();
55 CString proj;
56 if( g_GitAdminDir.HasAdminDir(str,&proj) )
58 this->SetWindowText(CString(_T("Config - "))+proj);
61 CString cmd,out;
62 cmd=_T("git.exe remote");
63 if(g_Git.Run(cmd,&out,CP_ACP))
65 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
66 return FALSE;
68 int start =0;
69 m_ctrlRemoteList.ResetContent();
72 CString one;
73 one=out.Tokenize(_T("\n"),start);
74 if(!one.IsEmpty())
75 this->m_ctrlRemoteList.AddString(one);
77 }while(start>=0);
79 this->UpdateData(FALSE);
80 return TRUE;
82 // CSettingGitRemote message handlers
84 void CSettingGitRemote::OnBnClickedButtonBrowse()
86 // TODO: Add your control notification handler code here
89 void CSettingGitRemote::OnBnClickedButtonAdd()
91 // TODO: Add your control notification handler code here
94 void CSettingGitRemote::OnLbnSelchangeListRemote()
96 // TODO: Add your control notification handler code here
97 if(m_bChanged)
99 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),
100 _T("TortoiseGit"),MB_YESNO) == IDYES)
102 OnApply();
105 SetModified(FALSE);
107 CString cmd,output;
108 int index;
109 index = this->m_ctrlRemoteList.GetCurSel();
110 if(index<0)
111 return;
113 CString remote;
114 m_ctrlRemoteList.GetText(index,remote);
115 this->m_strRemote=remote;
117 cmd.Format(_T("git.exe config remote.%s.url"),remote);
118 m_strUrl.Empty();
119 if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )
121 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
122 //return;
125 int start=0;
126 m_strUrl = m_strUrl.Tokenize(_T("\n"),start);
129 cmd.Format(_T("git.exe config remote.%s.puttykey"),remote);
130 this->m_strPuttyKeyfile.Empty();
131 if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )
133 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
134 //return;
136 start=0;
137 m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);
140 cmd.Format(_T("git.exe config remote.%s.puttykeyautoload"),remote);
141 CString autoload;
142 if( g_Git.Run(cmd,&autoload,CP_ACP) )
144 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
145 //return;
148 start=0;
149 autoload = autoload.Tokenize(_T("\n"),start);
150 m_bAutoLoad.SetCheck(false);
151 if( autoload == _T("true"))
153 m_bAutoLoad.SetCheck(true);
156 this->UpdateData(FALSE);
160 void CSettingGitRemote::OnEnChangeEditRemote()
162 // TODO: If this is a RICHEDIT control, the control will not
163 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
164 // function and call CRichEditCtrl().SetEventMask()
165 // with the ENM_CHANGE flag ORed into the mask.
167 // TODO: Add your control notification handler code here
170 void CSettingGitRemote::OnEnChangeEditUrl()
172 // TODO: If this is a RICHEDIT control, the control will not
173 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
174 // function and call CRichEditCtrl().SetEventMask()
175 // with the ENM_CHANGE flag ORed into the mask.
177 // TODO: Add your control notification handler code here
180 void CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey()
182 // TODO: Add your control notification handler code here
185 void CSettingGitRemote::OnEnChangeEditPuttyKey()
187 // TODO: If this is a RICHEDIT control, the control will not
188 // send this notification unless you override the ISettingsPropPage::OnInitDialog()
189 // function and call CRichEditCtrl().SetEventMask()
190 // with the ENM_CHANGE flag ORed into the mask.
192 // TODO: Add your control notification handler code here
195 BOOL CSettingGitRemote::OnApply()
198 SetModified(FALSE);
199 return ISettingsPropPage::OnApply();