OSDN Git Service

Setting dialog, remote list work.
[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()\r
17         : ISettingsPropPage(CSettingGitRemote::IDD)\r
18     , m_strRemote(_T(""))\r
19     , m_strUrl(_T(""))\r
20     , m_strPuttyKeyfile(_T(""))\r
21 {\r
22         m_bChanged=FALSE;\r
23 }\r
24 \r
25 CSettingGitRemote::~CSettingGitRemote()\r
26 {\r
27 }\r
28 \r
29 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)\r
30 {\r
31     CPropertyPage::DoDataExchange(pDX);\r
32     DDX_Control(pDX, IDC_LIST_REMOTE, m_ctrlRemoteList);\r
33     DDX_Text(pDX, IDC_EDIT_REMOTE, m_strRemote);\r
34     DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);\r
35     DDX_Control(pDX, IDC_CHECK_ISAUTOLOADPUTTYKEY, m_bAutoLoad);\r
36     DDX_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);\r
37 }\r
38 \r
39 \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_BN_CLICKED(IDC_CHECK_ISAUTOLOADPUTTYKEY, &CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey)\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(str,&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->UpdateData(FALSE);\r
80         return TRUE;\r
81 }\r
82 // CSettingGitRemote message handlers\r
83 \r
84 void CSettingGitRemote::OnBnClickedButtonBrowse()\r
85 {\r
86     // TODO: Add your control notification handler code here\r
87 }\r
88 \r
89 void CSettingGitRemote::OnBnClickedButtonAdd()\r
90 {\r
91     // TODO: Add your control notification handler code here\r
92 }\r
93 \r
94 void CSettingGitRemote::OnLbnSelchangeListRemote()\r
95 {\r
96     // TODO: Add your control notification handler code here\r
97         if(m_bChanged)\r
98         {\r
99                 if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),\r
100                                                                  _T("TortoiseGit"),MB_YESNO) == IDYES)\r
101                 {\r
102                         OnApply();\r
103                 }\r
104         }\r
105         SetModified(FALSE);\r
106         \r
107         CString cmd,output;\r
108         int index;\r
109         index = this->m_ctrlRemoteList.GetCurSel();\r
110         if(index<0)\r
111                 return;\r
112 \r
113         CString remote;\r
114         m_ctrlRemoteList.GetText(index,remote);\r
115         this->m_strRemote=remote;\r
116 \r
117         cmd.Format(_T("git.exe config remote.%s.url"),remote);\r
118         m_strUrl.Empty();\r
119         if( g_Git.Run(cmd,&m_strUrl,CP_ACP) )\r
120         {\r
121                 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
122                 //return;\r
123         }\r
124         \r
125         int start=0;\r
126         m_strUrl = m_strUrl.Tokenize(_T("\n"),start);\r
127 \r
128 \r
129         cmd.Format(_T("git.exe config remote.%s.puttykey"),remote);\r
130         this->m_strPuttyKeyfile.Empty();\r
131         if( g_Git.Run(cmd,&m_strPuttyKeyfile,CP_ACP) )\r
132         {\r
133                 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
134                 //return;\r
135         }\r
136         start=0;\r
137         m_strPuttyKeyfile = m_strPuttyKeyfile.Tokenize(_T("\n"),start);\r
138         \r
139 \r
140         cmd.Format(_T("git.exe config remote.%s.puttykeyautoload"),remote);\r
141         CString autoload;\r
142         if( g_Git.Run(cmd,&autoload,CP_ACP) )\r
143         {\r
144                 //CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
145                 //return;\r
146         }\r
147 \r
148         start=0;\r
149         autoload = autoload.Tokenize(_T("\n"),start);\r
150         m_bAutoLoad.SetCheck(false);\r
151         if( autoload == _T("true"))\r
152         {\r
153                 m_bAutoLoad.SetCheck(true);\r
154         }\r
155         \r
156         this->UpdateData(FALSE);\r
157 \r
158 }\r
159 \r
160 void CSettingGitRemote::OnEnChangeEditRemote()\r
161 {\r
162     // TODO:  If this is a RICHEDIT control, the control will not\r
163     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
164     // function and call CRichEditCtrl().SetEventMask()\r
165     // with the ENM_CHANGE flag ORed into the mask.\r
166 \r
167     // TODO:  Add your control notification handler code here\r
168 }\r
169 \r
170 void CSettingGitRemote::OnEnChangeEditUrl()\r
171 {\r
172     // TODO:  If this is a RICHEDIT control, the control will not\r
173     // send this notification unless you override the ISettingsPropPage::OnInitDialog()\r
174     // function and call CRichEditCtrl().SetEventMask()\r
175     // with the ENM_CHANGE flag ORed into the mask.\r
176 \r
177     // TODO:  Add your control notification handler code here\r
178 }\r
179 \r
180 void CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey()\r
181 {\r
182     // TODO: Add your control notification handler code here\r
183 }\r
184 \r
185 void CSettingGitRemote::OnEnChangeEditPuttyKey()\r
186 {\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
191 \r
192     // TODO:  Add your control notification handler code here\r
193 }\r
194 \r
195 BOOL CSettingGitRemote::OnApply()\r
196 {\r
197   \r
198     SetModified(FALSE);\r
199         return ISettingsPropPage::OnApply();\r
200 }