Fixed issue #472: TortoiseGit allows to commit without setting up a username + email
[TortoiseGit.git] / src / TortoiseProc / Settings / Settings.cpp
blob271eebd34f43738b919c578f44e03ad47f9716db
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "Settings.h"
22 #include "MessageBox.h"
23 #include "..\..\TGitCache\CacheInterface.h"
24 #include "CommonResource.h"
25 #include "GitAdminDir.h"
27 IMPLEMENT_DYNAMIC(CSettings, CTreePropSheet)
28 CSettings::CSettings(UINT nIDCaption,CTGitPath *cmdPath, CWnd* pParentWnd, UINT iSelectPage)
29 :CTreePropSheet(nIDCaption, pParentWnd, iSelectPage)
31 if(cmdPath)
32 this->m_CmdPath=*cmdPath;
34 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
35 AddPropPages();
38 CSettings::~CSettings()
40 RemovePropPages();
43 void CSettings::AddPropPages()
45 m_pMainPage = new CSetMainPage();
46 m_pOverlayPage = new CSetOverlayPage();
47 m_pOverlaysPage = new CSetOverlayIcons();
48 m_pProxyPage = new CSetProxyPage();
49 m_pProgsDiffPage = new CSettingsProgsDiff();
50 m_pProgsMergePage = new CSettingsProgsMerge();
51 m_pProgsUniDiffPage = new CSettingsProgsUniDiff();
52 m_pLookAndFeelPage = new CSetLookAndFeelPage();
54 m_pExtMenu = new CSetExtMenu();
56 m_pDialogsPage = new CSetDialogs();
57 m_pMiscPage = new CSetMisc();
58 // m_pRevisionGraphPage = new CSettingsRevisionGraph();
59 // m_pLogCachePage = new CSetLogCache();
60 // m_pLogCacheListPage = new CSettingsLogCaches();
61 m_pColorsPage = new CSettingsColors();
62 m_pColorsPage2 = new CSettingsColors2();
63 m_pColorsPage3 = new CSettingsColors3();
64 m_pSavedPage = new CSetSavedDataPage();
65 m_pHooksPage = new CSetHooks();
66 m_pBugTraqPage = new CSetBugTraq();
67 m_pTBlamePage = new CSettingsTBlame();
68 m_pGitConfig = new CSettingGitConfig();
69 m_pGitRemote = new CSettingGitRemote(m_CmdPath.GetWinPath());
70 m_pBugtraqConfig = new CSettingsBugtraqConfig(m_CmdPath.GetWinPath());
73 SetPageIcon(m_pExtMenu,m_pExtMenu->GetIconID());
75 SetPageIcon(m_pMainPage, m_pMainPage->GetIconID());
76 SetPageIcon(m_pOverlayPage, m_pOverlayPage->GetIconID());
77 SetPageIcon(m_pOverlaysPage, m_pOverlaysPage->GetIconID());
78 SetPageIcon(m_pProxyPage, m_pProxyPage->GetIconID());
79 SetPageIcon(m_pProgsDiffPage, m_pProgsDiffPage->GetIconID());
80 SetPageIcon(m_pProgsMergePage, m_pProgsMergePage->GetIconID());
81 SetPageIcon(m_pProgsUniDiffPage, m_pProgsUniDiffPage->GetIconID());
82 SetPageIcon(m_pLookAndFeelPage, m_pLookAndFeelPage->GetIconID());
83 SetPageIcon(m_pDialogsPage, m_pDialogsPage->GetIconID());
84 // SetPageIcon(m_pRevisionGraphPage, m_pRevisionGraphPage->GetIconID());
85 SetPageIcon(m_pMiscPage, m_pMiscPage->GetIconID());
86 //// SetPageIcon(m_pLogCachePage, m_pLogCachePage->GetIconID());
87 // SetPageIcon(m_pLogCacheListPage, m_pLogCacheListPage->GetIconID());
88 SetPageIcon(m_pColorsPage, m_pColorsPage->GetIconID());
89 SetPageIcon(m_pColorsPage2, m_pColorsPage2->GetIconID());
90 SetPageIcon(m_pColorsPage3, m_pColorsPage3->GetIconID());
92 SetPageIcon(m_pSavedPage, m_pSavedPage->GetIconID());
93 SetPageIcon(m_pHooksPage, m_pHooksPage->GetIconID());
95 SetPageIcon(m_pGitConfig, m_pGitConfig->GetIconID());
96 SetPageIcon(m_pGitRemote, m_pGitRemote->GetIconID());
97 SetPageIcon(m_pBugTraqPage, m_pBugTraqPage->GetIconID());
98 SetPageIcon(m_pBugtraqConfig, m_pBugtraqConfig->GetIconID());
99 SetPageIcon(m_pTBlamePage, m_pTBlamePage->GetIconID());
101 AddPage(m_pMainPage);
102 AddPage(m_pOverlayPage);
103 AddPage(m_pOverlaysPage);
104 AddPage(m_pProxyPage);
105 AddPage(m_pProgsDiffPage);
106 AddPage(m_pProgsMergePage);
107 AddPage(m_pProgsUniDiffPage);
108 AddPage(m_pLookAndFeelPage);
109 AddPage(m_pExtMenu);
110 AddPage(m_pDialogsPage);
111 AddPage(m_pMiscPage);
112 // AddPage(m_pRevisionGraphPage);
113 AddPage(m_pColorsPage);
114 AddPage(m_pColorsPage2);
115 AddPage(m_pColorsPage3);
116 AddPage(m_pSavedPage);
118 AddPage(m_pGitConfig);
120 if( g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )
122 AddPage(m_pGitRemote);
124 // AddPage(m_pGitRemotem_pLogCachePage);
125 // AddPage(m_pLogCacheListPage);
126 AddPage(m_pHooksPage);
127 AddPage(m_pBugTraqPage);
128 if( g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )
130 AddPage(m_pBugtraqConfig);
132 AddPage(m_pTBlamePage);
135 void CSettings::RemovePropPages()
137 delete m_pMainPage;
138 delete m_pOverlayPage;
139 delete m_pOverlaysPage;
140 delete m_pProxyPage;
141 delete m_pProgsDiffPage;
142 delete m_pProgsMergePage;
143 delete m_pProgsUniDiffPage;
144 delete m_pLookAndFeelPage;
145 delete m_pDialogsPage;
146 // delete m_pRevisionGraphPage;
147 delete m_pMiscPage;
148 //// delete m_pLogCachePage;
149 //// delete m_pLogCacheListPage;
150 delete m_pColorsPage;
151 delete m_pColorsPage2;
152 delete m_pColorsPage3;
153 delete m_pSavedPage;
154 delete m_pHooksPage;
155 delete m_pBugTraqPage;
156 delete m_pTBlamePage;
158 delete m_pGitConfig;
159 delete m_pGitRemote;
160 delete m_pBugtraqConfig;
161 delete m_pExtMenu;
165 void CSettings::HandleRestart()
167 int restart = ISettingsPropPage::Restart_None;
168 restart |= m_pMainPage->GetRestart();
169 restart |= m_pOverlayPage->GetRestart();
170 restart |= m_pOverlaysPage->GetRestart();
171 restart |= m_pProxyPage->GetRestart();
172 restart |= m_pProgsDiffPage->GetRestart();
173 restart |= m_pProgsMergePage->GetRestart();
174 restart |= m_pProgsUniDiffPage->GetRestart();
175 restart |= m_pLookAndFeelPage->GetRestart();
176 restart |= m_pDialogsPage->GetRestart();
177 // restart |= m_pRevisionGraphPage->GetRestart();
178 restart |= m_pMiscPage->GetRestart();
179 //// restart |= m_pLogCachePage->GetRestart();
180 // restart |= m_pLogCacheListPage->GetRestart();
181 restart |= m_pColorsPage->GetRestart();
182 restart |= m_pColorsPage2->GetRestart();
183 restart |= m_pColorsPage3->GetRestart();
184 restart |= m_pSavedPage->GetRestart();
185 restart |= m_pHooksPage->GetRestart();
186 restart |= m_pBugTraqPage->GetRestart();
187 restart |= m_pTBlamePage->GetRestart();
189 restart |= m_pGitConfig->GetRestart();
190 restart |= m_pGitRemote->GetRestart();
191 restart |= m_pBugTraqPage->GetRestart();
192 restart |= m_pExtMenu->GetRestart();
194 if (restart & ISettingsPropPage::Restart_System)
196 DWORD_PTR res = 0;
197 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);
198 CMessageBox::Show(NULL, IDS_SETTINGS_RESTARTSYSTEM, IDS_APPNAME, MB_ICONINFORMATION);
200 if (restart & ISettingsPropPage::Restart_Cache)
202 DWORD_PTR res = 0;
203 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);
204 // tell the cache to refresh everything
205 HANDLE hPipe = CreateFile(
206 GetCacheCommandPipeName(), // pipe name
207 GENERIC_READ | // read and write access
208 GENERIC_WRITE,
209 0, // no sharing
210 NULL, // default security attributes
211 OPEN_EXISTING, // opens existing pipe
212 FILE_FLAG_OVERLAPPED, // default attributes
213 NULL); // no template file
216 if (hPipe != INVALID_HANDLE_VALUE)
218 // The pipe connected; change to message-read mode.
219 DWORD dwMode;
221 dwMode = PIPE_READMODE_MESSAGE;
222 if (SetNamedPipeHandleState(
223 hPipe, // pipe handle
224 &dwMode, // new pipe mode
225 NULL, // don't set maximum bytes
226 NULL)) // don't set maximum time
228 DWORD cbWritten;
229 TSVNCacheCommand cmd;
230 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));
231 cmd.command = TSVNCACHECOMMAND_REFRESHALL;
232 BOOL fSuccess = WriteFile(
233 hPipe, // handle to pipe
234 &cmd, // buffer to write from
235 sizeof(cmd), // number of bytes to write
236 &cbWritten, // number of bytes written
237 NULL); // not overlapped I/O
239 if (! fSuccess || sizeof(cmd) != cbWritten)
241 DisconnectNamedPipe(hPipe);
242 CloseHandle(hPipe);
243 hPipe = INVALID_HANDLE_VALUE;
245 if (hPipe != INVALID_HANDLE_VALUE)
247 // now tell the cache we don't need it's command thread anymore
248 DWORD cbWritten;
249 TSVNCacheCommand cmd;
250 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));
251 cmd.command = TSVNCACHECOMMAND_END;
252 WriteFile(
253 hPipe, // handle to pipe
254 &cmd, // buffer to write from
255 sizeof(cmd), // number of bytes to write
256 &cbWritten, // number of bytes written
257 NULL); // not overlapped I/O
258 DisconnectNamedPipe(hPipe);
259 CloseHandle(hPipe);
260 hPipe = INVALID_HANDLE_VALUE;
263 else
265 ATLTRACE("SetNamedPipeHandleState failed");
266 CloseHandle(hPipe);
272 BEGIN_MESSAGE_MAP(CSettings, CTreePropSheet)
273 ON_WM_QUERYDRAGICON()
274 ON_WM_PAINT()
275 END_MESSAGE_MAP()
277 BOOL CSettings::OnInitDialog()
279 BOOL bResult = CTreePropSheet::OnInitDialog();
281 SetIcon(m_hIcon, TRUE); // Set big icon
282 SetIcon(m_hIcon, FALSE); // Set small icon
284 CenterWindow(CWnd::FromHandle(hWndExplorer));
286 if(this->m_DefaultPage == _T("gitremote"))
288 this->SetActivePage(this->m_pGitRemote);
290 if(this->m_DefaultPage == _T("gitconfig"))
292 this->SetActivePage(this->m_pGitConfig);
294 if(this->m_DefaultPage == _T("main"))
296 this->SetActivePage(this->m_pMainPage);
298 if(this->m_DefaultPage == _T("overlay"))
300 this->SetActivePage(this->m_pOverlayPage);
302 if(this->m_DefaultPage == _T("overlays"))
304 this->SetActivePage(this->m_pOverlaysPage);
306 if(this->m_DefaultPage == _T("proxy"))
308 this->SetActivePage(this->m_pProxyPage);
311 if(this->m_DefaultPage == _T("diff"))
313 this->SetActivePage(this->m_pProgsDiffPage);
315 if(this->m_DefaultPage == _T("merge"))
317 this->SetActivePage(this->m_pProgsMergePage);
319 if(this->m_DefaultPage == _T("unidiff"))
321 this->SetActivePage(this->m_pProgsUniDiffPage);
323 if(this->m_DefaultPage == _T("look"))
325 this->SetActivePage(this->m_pLookAndFeelPage);
327 if(this->m_DefaultPage == _T("dialog"))
329 this->SetActivePage(this->m_pDialogsPage);
331 if(this->m_DefaultPage == _T("misc"))
333 this->SetActivePage(this->m_pMiscPage);
335 if(this->m_DefaultPage == _T("graph"))
337 // this->SetActivePage(this->m_pRevisionGraphPage);
340 if(this->m_DefaultPage == _T("color1"))
342 this->SetActivePage(this->m_pColorsPage);
344 if(this->m_DefaultPage == _T("color2"))
346 this->SetActivePage(this->m_pColorsPage2);
348 if(this->m_DefaultPage == _T("color3"))
350 this->SetActivePage(this->m_pColorsPage3);
352 if(this->m_DefaultPage == _T("save"))
354 this->SetActivePage(this->m_pSavedPage);
357 return bResult;
360 void CSettings::OnPaint()
362 if (IsIconic())
364 CPaintDC dc(this); // device context for painting
366 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
368 // Center icon in client rectangle
369 int cxIcon = GetSystemMetrics(SM_CXICON);
370 int cyIcon = GetSystemMetrics(SM_CYICON);
371 CRect rect;
372 GetClientRect(&rect);
373 int x = (rect.Width() - cxIcon + 1) / 2;
374 int y = (rect.Height() - cyIcon + 1) / 2;
376 // Draw the icon
377 dc.DrawIcon(x, y, m_hIcon);
379 else
381 CTreePropSheet::OnPaint();
385 HCURSOR CSettings::OnQueryDragIcon()
387 return static_cast<HCURSOR>(m_hIcon);