some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / Settings / Settings.cpp
blobc5eb6e6b88cb9b11fbba936cf0a9820e90a5284b
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"
26 #include "AppUtils.h"
28 IMPLEMENT_DYNAMIC(CSettings, CTreePropSheet)
29 CSettings::CSettings(UINT nIDCaption,CTGitPath *cmdPath, CWnd* pParentWnd, UINT iSelectPage)
30 :CTreePropSheet(nIDCaption, pParentWnd, iSelectPage)
32 if(cmdPath)
33 this->m_CmdPath=*cmdPath;
35 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
36 AddPropPages();
39 CSettings::~CSettings()
41 RemovePropPages();
44 void CSettings::AddPropPages()
46 m_pMainPage = new CSetMainPage();
47 m_pOverlayPage = new CSetOverlayPage();
48 m_pOverlaysPage = new CSetOverlayIcons();
49 m_pProxyPage = new CSetProxyPage();
50 m_pProgsDiffPage = new CSettingsProgsDiff();
51 m_pProgsMergePage = new CSettingsProgsMerge();
52 m_pProgsUniDiffPage = new CSettingsProgsUniDiff();
53 m_pProgsAlternativeEditor = new CSettingsProgsAlternativeEditor();
54 m_pLookAndFeelPage = new CSetLookAndFeelPage();
56 m_pExtMenu = new CSetExtMenu();
58 m_pDialogsPage = new CSetDialogs();
59 m_pMiscPage = new CSetMisc();
60 // m_pRevisionGraphPage = new CSettingsRevisionGraph();
61 // m_pLogCachePage = new CSetLogCache();
62 // m_pLogCacheListPage = new CSettingsLogCaches();
63 m_pColorsPage = new CSettingsColors();
64 m_pColorsPage2 = new CSettingsColors2();
65 m_pColorsPage3 = new CSettingsColors3();
66 m_pSavedPage = new CSetSavedDataPage();
67 m_pHooksPage = new CSetHooks();
68 m_pBugTraqPage = new CSetBugTraq();
69 m_pTBlamePage = new CSettingsTBlame();
70 m_pGitConfig = new CSettingGitConfig();
71 m_pGitRemote = new CSettingGitRemote(m_CmdPath.GetWinPath());
72 m_pBugtraqConfig = new CSettingsBugtraqConfig(m_CmdPath.GetWinPath());
75 SetPageIcon(m_pExtMenu,m_pExtMenu->GetIconID());
77 SetPageIcon(m_pMainPage, m_pMainPage->GetIconID());
78 SetPageIcon(m_pOverlayPage, m_pOverlayPage->GetIconID());
79 SetPageIcon(m_pOverlaysPage, m_pOverlaysPage->GetIconID());
80 SetPageIcon(m_pProxyPage, m_pProxyPage->GetIconID());
81 SetPageIcon(m_pProgsDiffPage, m_pProgsDiffPage->GetIconID());
82 SetPageIcon(m_pProgsMergePage, m_pProgsMergePage->GetIconID());
83 SetPageIcon(m_pProgsAlternativeEditor, m_pProgsAlternativeEditor->GetIconID());
84 SetPageIcon(m_pProgsUniDiffPage, m_pProgsUniDiffPage->GetIconID());
85 SetPageIcon(m_pLookAndFeelPage, m_pLookAndFeelPage->GetIconID());
86 SetPageIcon(m_pDialogsPage, m_pDialogsPage->GetIconID());
87 // SetPageIcon(m_pRevisionGraphPage, m_pRevisionGraphPage->GetIconID());
88 SetPageIcon(m_pMiscPage, m_pMiscPage->GetIconID());
89 //// SetPageIcon(m_pLogCachePage, m_pLogCachePage->GetIconID());
90 // SetPageIcon(m_pLogCacheListPage, m_pLogCacheListPage->GetIconID());
91 SetPageIcon(m_pColorsPage, m_pColorsPage->GetIconID());
92 SetPageIcon(m_pColorsPage2, m_pColorsPage2->GetIconID());
93 SetPageIcon(m_pColorsPage3, m_pColorsPage3->GetIconID());
95 SetPageIcon(m_pSavedPage, m_pSavedPage->GetIconID());
96 SetPageIcon(m_pHooksPage, m_pHooksPage->GetIconID());
98 SetPageIcon(m_pGitConfig, m_pGitConfig->GetIconID());
99 SetPageIcon(m_pGitRemote, m_pGitRemote->GetIconID());
100 SetPageIcon(m_pBugTraqPage, m_pBugTraqPage->GetIconID());
101 SetPageIcon(m_pBugtraqConfig, m_pBugtraqConfig->GetIconID());
102 SetPageIcon(m_pTBlamePage, m_pTBlamePage->GetIconID());
104 AddPage(m_pMainPage);
105 AddPage(m_pOverlayPage);
106 AddPage(m_pOverlaysPage);
107 AddPage(m_pProxyPage);
108 AddPage(m_pProgsDiffPage);
109 AddPage(m_pProgsMergePage);
110 AddPage(m_pProgsUniDiffPage);
111 AddPage(m_pProgsAlternativeEditor);
112 AddPage(m_pLookAndFeelPage);
113 AddPage(m_pExtMenu);
114 AddPage(m_pDialogsPage);
115 AddPage(m_pMiscPage);
116 // AddPage(m_pRevisionGraphPage);
117 AddPage(m_pColorsPage);
118 AddPage(m_pColorsPage2);
119 AddPage(m_pColorsPage3);
120 AddPage(m_pSavedPage);
122 AddPage(m_pGitConfig);
124 if( g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )
126 AddPage(m_pGitRemote);
128 // AddPage(m_pGitRemotem_pLogCachePage);
129 // AddPage(m_pLogCacheListPage);
130 AddPage(m_pHooksPage);
131 AddPage(m_pBugTraqPage);
132 if( g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )
134 AddPage(m_pBugtraqConfig);
136 AddPage(m_pTBlamePage);
139 void CSettings::RemovePropPages()
141 delete m_pMainPage;
142 delete m_pOverlayPage;
143 delete m_pOverlaysPage;
144 delete m_pProxyPage;
145 delete m_pProgsDiffPage;
146 delete m_pProgsMergePage;
147 delete m_pProgsUniDiffPage;
148 delete m_pProgsAlternativeEditor;
149 delete m_pLookAndFeelPage;
150 delete m_pDialogsPage;
151 // delete m_pRevisionGraphPage;
152 delete m_pMiscPage;
153 //// delete m_pLogCachePage;
154 //// delete m_pLogCacheListPage;
155 delete m_pColorsPage;
156 delete m_pColorsPage2;
157 delete m_pColorsPage3;
158 delete m_pSavedPage;
159 delete m_pHooksPage;
160 delete m_pBugTraqPage;
161 delete m_pTBlamePage;
163 delete m_pGitConfig;
164 delete m_pGitRemote;
165 delete m_pBugtraqConfig;
166 delete m_pExtMenu;
170 void CSettings::HandleRestart()
172 int restart = ISettingsPropPage::Restart_None;
173 restart |= m_pMainPage->GetRestart();
174 restart |= m_pOverlayPage->GetRestart();
175 restart |= m_pOverlaysPage->GetRestart();
176 restart |= m_pProxyPage->GetRestart();
177 restart |= m_pProgsDiffPage->GetRestart();
178 restart |= m_pProgsMergePage->GetRestart();
179 restart |= m_pProgsUniDiffPage->GetRestart();
180 restart |= m_pProgsAlternativeEditor->GetRestart();
181 restart |= m_pLookAndFeelPage->GetRestart();
182 restart |= m_pDialogsPage->GetRestart();
183 // restart |= m_pRevisionGraphPage->GetRestart();
184 restart |= m_pMiscPage->GetRestart();
185 //// restart |= m_pLogCachePage->GetRestart();
186 // restart |= m_pLogCacheListPage->GetRestart();
187 restart |= m_pColorsPage->GetRestart();
188 restart |= m_pColorsPage2->GetRestart();
189 restart |= m_pColorsPage3->GetRestart();
190 restart |= m_pSavedPage->GetRestart();
191 restart |= m_pHooksPage->GetRestart();
192 restart |= m_pBugTraqPage->GetRestart();
193 restart |= m_pTBlamePage->GetRestart();
195 restart |= m_pGitConfig->GetRestart();
196 restart |= m_pGitRemote->GetRestart();
197 restart |= m_pBugTraqPage->GetRestart();
198 restart |= m_pExtMenu->GetRestart();
200 if (restart & ISettingsPropPage::Restart_System)
202 DWORD_PTR res = 0;
203 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);
204 CMessageBox::Show(NULL, IDS_SETTINGS_RESTARTSYSTEM, IDS_APPNAME, MB_ICONINFORMATION);
206 if (restart & ISettingsPropPage::Restart_Cache)
208 DWORD_PTR res = 0;
209 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);
210 // tell the cache to refresh everything
211 HANDLE hPipe = CreateFile(
212 GetCacheCommandPipeName(), // pipe name
213 GENERIC_READ | // read and write access
214 GENERIC_WRITE,
215 0, // no sharing
216 NULL, // default security attributes
217 OPEN_EXISTING, // opens existing pipe
218 FILE_FLAG_OVERLAPPED, // default attributes
219 NULL); // no template file
222 if (hPipe != INVALID_HANDLE_VALUE)
224 // The pipe connected; change to message-read mode.
225 DWORD dwMode;
227 dwMode = PIPE_READMODE_MESSAGE;
228 if (SetNamedPipeHandleState(
229 hPipe, // pipe handle
230 &dwMode, // new pipe mode
231 NULL, // don't set maximum bytes
232 NULL)) // don't set maximum time
234 DWORD cbWritten;
235 TSVNCacheCommand cmd;
236 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));
237 cmd.command = TSVNCACHECOMMAND_REFRESHALL;
238 BOOL fSuccess = WriteFile(
239 hPipe, // handle to pipe
240 &cmd, // buffer to write from
241 sizeof(cmd), // number of bytes to write
242 &cbWritten, // number of bytes written
243 NULL); // not overlapped I/O
245 if (! fSuccess || sizeof(cmd) != cbWritten)
247 DisconnectNamedPipe(hPipe);
248 CloseHandle(hPipe);
249 hPipe = INVALID_HANDLE_VALUE;
251 if (hPipe != INVALID_HANDLE_VALUE)
253 // now tell the cache we don't need it's command thread anymore
254 DWORD cbWritten;
255 TSVNCacheCommand cmd;
256 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));
257 cmd.command = TSVNCACHECOMMAND_END;
258 WriteFile(
259 hPipe, // handle to pipe
260 &cmd, // buffer to write from
261 sizeof(cmd), // number of bytes to write
262 &cbWritten, // number of bytes written
263 NULL); // not overlapped I/O
264 DisconnectNamedPipe(hPipe);
265 CloseHandle(hPipe);
266 hPipe = INVALID_HANDLE_VALUE;
269 else
271 ATLTRACE("SetNamedPipeHandleState failed");
272 CloseHandle(hPipe);
278 BEGIN_MESSAGE_MAP(CSettings, CTreePropSheet)
279 ON_WM_QUERYDRAGICON()
280 ON_WM_PAINT()
281 END_MESSAGE_MAP()
283 BOOL CSettings::OnInitDialog()
285 BOOL bResult = CTreePropSheet::OnInitDialog();
286 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
288 SetIcon(m_hIcon, TRUE); // Set big icon
289 SetIcon(m_hIcon, FALSE); // Set small icon
291 CenterWindow(CWnd::FromHandle(hWndExplorer));
293 if(this->m_DefaultPage == _T("gitremote"))
295 this->SetActivePage(this->m_pGitRemote);
297 if(this->m_DefaultPage == _T("gitconfig"))
299 this->SetActivePage(this->m_pGitConfig);
301 if(this->m_DefaultPage == _T("main"))
303 this->SetActivePage(this->m_pMainPage);
305 if(this->m_DefaultPage == _T("overlay"))
307 this->SetActivePage(this->m_pOverlayPage);
309 if(this->m_DefaultPage == _T("overlays"))
311 this->SetActivePage(this->m_pOverlaysPage);
313 if(this->m_DefaultPage == _T("proxy"))
315 this->SetActivePage(this->m_pProxyPage);
318 if(this->m_DefaultPage == _T("diff"))
320 this->SetActivePage(this->m_pProgsDiffPage);
322 if(this->m_DefaultPage == _T("merge"))
324 this->SetActivePage(this->m_pProgsMergePage);
326 if(this->m_DefaultPage == _T("unidiff"))
328 this->SetActivePage(this->m_pProgsUniDiffPage);
330 if(this->m_DefaultPage == _T("alternativeeditor"))
332 this->SetActivePage(this->m_pProgsAlternativeEditor);
334 if(this->m_DefaultPage == _T("look"))
336 this->SetActivePage(this->m_pLookAndFeelPage);
338 if(this->m_DefaultPage == _T("dialog"))
340 this->SetActivePage(this->m_pDialogsPage);
342 if(this->m_DefaultPage == _T("misc"))
344 this->SetActivePage(this->m_pMiscPage);
346 if(this->m_DefaultPage == _T("graph"))
348 // this->SetActivePage(this->m_pRevisionGraphPage);
351 if(this->m_DefaultPage == _T("color1"))
353 this->SetActivePage(this->m_pColorsPage);
355 if(this->m_DefaultPage == _T("color2"))
357 this->SetActivePage(this->m_pColorsPage2);
359 if(this->m_DefaultPage == _T("color3"))
361 this->SetActivePage(this->m_pColorsPage3);
363 if(this->m_DefaultPage == _T("save"))
365 this->SetActivePage(this->m_pSavedPage);
368 return bResult;
371 void CSettings::OnPaint()
373 if (IsIconic())
375 CPaintDC dc(this); // device context for painting
377 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
379 // Center icon in client rectangle
380 int cxIcon = GetSystemMetrics(SM_CXICON);
381 int cyIcon = GetSystemMetrics(SM_CYICON);
382 CRect rect;
383 GetClientRect(&rect);
384 int x = (rect.Width() - cxIcon + 1) / 2;
385 int y = (rect.Height() - cyIcon + 1) / 2;
387 // Draw the icon
388 dc.DrawIcon(x, y, m_hIcon);
390 else
392 CTreePropSheet::OnPaint();
396 HCURSOR CSettings::OnQueryDragIcon()
398 return static_cast<HCURSOR>(m_hIcon);