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.
20 #include "TortoiseProc.h"
22 #include "MessageBox.h"
23 #include "..\..\TGitCache\CacheInterface.h"
24 #include "CommonResource.h"
25 #include "GitAdminDir.h"
28 IMPLEMENT_DYNAMIC(CSettings
, CTreePropSheet
)
29 CSettings::CSettings(UINT nIDCaption
,CTGitPath
*cmdPath
, CWnd
* pParentWnd
, UINT iSelectPage
)
30 :CTreePropSheet(nIDCaption
, pParentWnd
, iSelectPage
)
33 this->m_CmdPath
=*cmdPath
;
35 m_hIcon
= AfxGetApp()->LoadIcon(IDR_MAINFRAME
);
39 CSettings::~CSettings()
44 void CSettings::AddPropPages()
46 m_pMainPage
= new CSetMainPage();
47 m_pOverlayPage
= new CSetOverlayPage();
48 m_pOverlaysPage
= new CSetOverlayIcons();
49 m_pOverlayHandlersPage
= new CSetOverlayHandlers();
50 m_pProxyPage
= new CSetProxyPage();
51 m_pProgsDiffPage
= new CSettingsProgsDiff();
52 m_pProgsMergePage
= new CSettingsProgsMerge();
53 m_pProgsUniDiffPage
= new CSettingsProgsUniDiff();
54 m_pProgsAlternativeEditor
= new CSettingsProgsAlternativeEditor();
55 m_pLookAndFeelPage
= new CSetLookAndFeelPage();
57 m_pExtMenu
= new CSetExtMenu();
59 m_pDialogsPage
= new CSetDialogs();
60 m_pMiscPage
= new CSetMisc();
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_pOverlayHandlersPage
, m_pOverlayHandlersPage
->GetIconID());
79 SetPageIcon(m_pProxyPage
, m_pProxyPage
->GetIconID());
80 SetPageIcon(m_pProgsDiffPage
, m_pProgsDiffPage
->GetIconID());
81 SetPageIcon(m_pProgsMergePage
, m_pProgsMergePage
->GetIconID());
82 SetPageIcon(m_pProgsAlternativeEditor
, m_pProgsAlternativeEditor
->GetIconID());
83 SetPageIcon(m_pProgsUniDiffPage
, m_pProgsUniDiffPage
->GetIconID());
84 SetPageIcon(m_pLookAndFeelPage
, m_pLookAndFeelPage
->GetIconID());
85 SetPageIcon(m_pDialogsPage
, m_pDialogsPage
->GetIconID());
86 SetPageIcon(m_pMiscPage
, m_pMiscPage
->GetIconID());
87 SetPageIcon(m_pColorsPage
, m_pColorsPage
->GetIconID());
88 SetPageIcon(m_pColorsPage2
, m_pColorsPage2
->GetIconID());
89 SetPageIcon(m_pColorsPage3
, m_pColorsPage3
->GetIconID());
91 SetPageIcon(m_pSavedPage
, m_pSavedPage
->GetIconID());
92 SetPageIcon(m_pHooksPage
, m_pHooksPage
->GetIconID());
94 SetPageIcon(m_pGitConfig
, m_pGitConfig
->GetIconID());
95 SetPageIcon(m_pGitRemote
, m_pGitRemote
->GetIconID());
96 SetPageIcon(m_pBugTraqPage
, m_pBugTraqPage
->GetIconID());
97 SetPageIcon(m_pBugtraqConfig
, m_pBugtraqConfig
->GetIconID());
98 SetPageIcon(m_pTBlamePage
, m_pTBlamePage
->GetIconID());
100 AddPage(m_pMainPage
);
101 AddPage(m_pOverlayPage
);
102 AddPage(m_pOverlaysPage
);
103 AddPage(m_pOverlayHandlersPage
);
104 AddPage(m_pProxyPage
);
105 AddPage(m_pProgsDiffPage
);
106 AddPage(m_pProgsMergePage
);
107 AddPage(m_pProgsUniDiffPage
);
108 AddPage(m_pProgsAlternativeEditor
);
109 AddPage(m_pLookAndFeelPage
);
111 AddPage(m_pDialogsPage
);
112 AddPage(m_pMiscPage
);
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_pHooksPage
);
125 AddPage(m_pBugTraqPage
);
126 if( g_GitAdminDir
.HasAdminDir(this->m_CmdPath
.GetWinPath()) )
128 AddPage(m_pBugtraqConfig
);
130 AddPage(m_pTBlamePage
);
133 void CSettings::RemovePropPages()
136 delete m_pOverlayPage
;
137 delete m_pOverlaysPage
;
138 delete m_pOverlayHandlersPage
;
140 delete m_pProgsDiffPage
;
141 delete m_pProgsMergePage
;
142 delete m_pProgsUniDiffPage
;
143 delete m_pProgsAlternativeEditor
;
144 delete m_pLookAndFeelPage
;
145 delete m_pDialogsPage
;
147 delete m_pColorsPage
;
148 delete m_pColorsPage2
;
149 delete m_pColorsPage3
;
152 delete m_pBugTraqPage
;
153 delete m_pTBlamePage
;
157 delete m_pBugtraqConfig
;
162 void CSettings::HandleRestart()
164 int restart
= ISettingsPropPage::Restart_None
;
165 restart
|= m_pMainPage
->GetRestart();
166 restart
|= m_pOverlayPage
->GetRestart();
167 restart
|= m_pOverlaysPage
->GetRestart();
168 restart
|= m_pOverlayHandlersPage
->GetRestart();
169 restart
|= m_pProxyPage
->GetRestart();
170 restart
|= m_pProgsDiffPage
->GetRestart();
171 restart
|= m_pProgsMergePage
->GetRestart();
172 restart
|= m_pProgsUniDiffPage
->GetRestart();
173 restart
|= m_pProgsAlternativeEditor
->GetRestart();
174 restart
|= m_pLookAndFeelPage
->GetRestart();
175 restart
|= m_pDialogsPage
->GetRestart();
176 restart
|= m_pMiscPage
->GetRestart();
177 restart
|= m_pColorsPage
->GetRestart();
178 restart
|= m_pColorsPage2
->GetRestart();
179 restart
|= m_pColorsPage3
->GetRestart();
180 restart
|= m_pSavedPage
->GetRestart();
181 restart
|= m_pHooksPage
->GetRestart();
182 restart
|= m_pBugTraqPage
->GetRestart();
183 restart
|= m_pTBlamePage
->GetRestart();
185 restart
|= m_pGitConfig
->GetRestart();
186 restart
|= m_pGitRemote
->GetRestart();
187 restart
|= m_pBugTraqPage
->GetRestart();
188 restart
|= m_pExtMenu
->GetRestart();
190 if (restart
& ISettingsPropPage::Restart_System
)
193 ::SendMessageTimeout(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, 0, SMTO_ABORTIFHUNG
, 20, &res
);
194 CMessageBox::Show(NULL
, IDS_SETTINGS_RESTARTSYSTEM
, IDS_APPNAME
, MB_ICONINFORMATION
);
196 if (restart
& ISettingsPropPage::Restart_Cache
)
199 ::SendMessageTimeout(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, 0, SMTO_ABORTIFHUNG
, 20, &res
);
200 // tell the cache to refresh everything
201 HANDLE hPipe
= CreateFile(
202 GetCacheCommandPipeName(), // pipe name
203 GENERIC_READ
| // read and write access
206 NULL
, // default security attributes
207 OPEN_EXISTING
, // opens existing pipe
208 FILE_FLAG_OVERLAPPED
, // default attributes
209 NULL
); // no template file
212 if (hPipe
!= INVALID_HANDLE_VALUE
)
214 // The pipe connected; change to message-read mode.
217 dwMode
= PIPE_READMODE_MESSAGE
;
218 if (SetNamedPipeHandleState(
219 hPipe
, // pipe handle
220 &dwMode
, // new pipe mode
221 NULL
, // don't set maximum bytes
222 NULL
)) // don't set maximum time
225 TGITCacheCommand cmd
;
226 SecureZeroMemory(&cmd
, sizeof(TGITCacheCommand
));
227 cmd
.command
= TGITCACHECOMMAND_REFRESHALL
;
228 BOOL fSuccess
= WriteFile(
229 hPipe
, // handle to pipe
230 &cmd
, // buffer to write from
231 sizeof(cmd
), // number of bytes to write
232 &cbWritten
, // number of bytes written
233 NULL
); // not overlapped I/O
235 if (! fSuccess
|| sizeof(cmd
) != cbWritten
)
237 DisconnectNamedPipe(hPipe
);
239 hPipe
= INVALID_HANDLE_VALUE
;
241 if (hPipe
!= INVALID_HANDLE_VALUE
)
243 // now tell the cache we don't need it's command thread anymore
245 TGITCacheCommand cmd
;
246 SecureZeroMemory(&cmd
, sizeof(TGITCacheCommand
));
247 cmd
.command
= TGITCACHECOMMAND_END
;
249 hPipe
, // handle to pipe
250 &cmd
, // buffer to write from
251 sizeof(cmd
), // number of bytes to write
252 &cbWritten
, // number of bytes written
253 NULL
); // not overlapped I/O
254 DisconnectNamedPipe(hPipe
);
256 hPipe
= INVALID_HANDLE_VALUE
;
261 ATLTRACE("SetNamedPipeHandleState failed");
268 BEGIN_MESSAGE_MAP(CSettings
, CTreePropSheet
)
269 ON_WM_QUERYDRAGICON()
273 BOOL
CSettings::OnInitDialog()
275 BOOL bResult
= CTreePropSheet::OnInitDialog();
276 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
278 SetIcon(m_hIcon
, TRUE
); // Set big icon
279 SetIcon(m_hIcon
, FALSE
); // Set small icon
281 CenterWindow(CWnd::FromHandle(hWndExplorer
));
283 if(this->m_DefaultPage
== _T("gitremote"))
285 this->SetActivePage(this->m_pGitRemote
);
287 if(this->m_DefaultPage
== _T("gitconfig"))
289 this->SetActivePage(this->m_pGitConfig
);
291 if(this->m_DefaultPage
== _T("main"))
293 this->SetActivePage(this->m_pMainPage
);
295 if(this->m_DefaultPage
== _T("overlay"))
297 this->SetActivePage(this->m_pOverlayPage
);
299 if(this->m_DefaultPage
== _T("overlays"))
301 this->SetActivePage(this->m_pOverlaysPage
);
303 if(this->m_DefaultPage
== _T("overlayshandlers"))
305 this->SetActivePage(this->m_pOverlayHandlersPage
);
307 if(this->m_DefaultPage
== _T("proxy"))
309 this->SetActivePage(this->m_pProxyPage
);
312 if(this->m_DefaultPage
== _T("diff"))
314 this->SetActivePage(this->m_pProgsDiffPage
);
316 if(this->m_DefaultPage
== _T("merge"))
318 this->SetActivePage(this->m_pProgsMergePage
);
320 if(this->m_DefaultPage
== _T("unidiff"))
322 this->SetActivePage(this->m_pProgsUniDiffPage
);
324 if(this->m_DefaultPage
== _T("alternativeeditor"))
326 this->SetActivePage(this->m_pProgsAlternativeEditor
);
328 if(this->m_DefaultPage
== _T("look"))
330 this->SetActivePage(this->m_pLookAndFeelPage
);
332 if(this->m_DefaultPage
== _T("dialog"))
334 this->SetActivePage(this->m_pDialogsPage
);
336 if(this->m_DefaultPage
== _T("misc"))
338 this->SetActivePage(this->m_pMiscPage
);
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
);
360 void CSettings::OnPaint()
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
);
372 GetClientRect(&rect
);
373 int x
= (rect
.Width() - cxIcon
+ 1) / 2;
374 int y
= (rect
.Height() - cyIcon
+ 1) / 2;
377 dc
.DrawIcon(x
, y
, m_hIcon
);
381 CTreePropSheet::OnPaint();
385 HCURSOR
CSettings::OnQueryDragIcon()
387 return static_cast<HCURSOR
>(m_hIcon
);