No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / Settings / SetOverlayPage.cpp
blob83c788dbcaaf619f17453eb3cf08244cdd2ba16b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2011,2013-2015 - TortoiseGit
4 // Copyright (C) 2003-2008,2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "SetOverlayPage.h"
23 #include "SetOverlayIcons.h"
24 #include "Globals.h"
25 #include "..\TGitCache\CacheInterface.h"
26 #include "MessageBox.h"
29 IMPLEMENT_DYNAMIC(CSetOverlayPage, ISettingsPropPage)
30 CSetOverlayPage::CSetOverlayPage()
31 : ISettingsPropPage(CSetOverlayPage::IDD)
32 , m_bRemovable(FALSE)
33 , m_bNetwork(FALSE)
34 , m_bFixed(FALSE)
35 , m_bCDROM(FALSE)
36 , m_bRAM(FALSE)
37 , m_bUnknown(FALSE)
38 , m_bOnlyExplorer(FALSE)
39 , m_bUnversionedAsModified(FALSE)
40 , m_bRecurseSubmodules(FALSE)
41 , m_bFloppy(FALSE)
42 , m_bShowExcludedAsNormal(TRUE)
44 m_regOnlyExplorer = CRegDWORD(_T("Software\\TortoiseGit\\LoadDllOnlyInExplorer"), FALSE);
45 m_regDriveMaskRemovable = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskRemovable"));
46 m_regDriveMaskFloppy = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskFloppy"));
47 m_regDriveMaskRemote = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskRemote"));
48 m_regDriveMaskFixed = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskFixed"), TRUE);
49 m_regDriveMaskCDROM = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskCDROM"));
50 m_regDriveMaskRAM = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskRAM"));
51 m_regDriveMaskUnknown = CRegDWORD(_T("Software\\TortoiseGit\\DriveMaskUnknown"));
52 m_regExcludePaths = CRegString(_T("Software\\TortoiseGit\\OverlayExcludeList"));
53 m_regIncludePaths = CRegString(_T("Software\\TortoiseGit\\OverlayIncludeList"));
54 m_regCacheType = CRegDWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? 2 : 1);
55 m_regUnversionedAsModified = CRegDWORD(_T("Software\\TortoiseGit\\UnversionedAsModified"), FALSE);
56 m_regRecurseSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\TGitCacheRecurseSubmodules"), FALSE);
57 m_regShowExcludedAsNormal = CRegDWORD(_T("Software\\TortoiseGit\\ShowExcludedAsNormal"), TRUE);
59 m_bOnlyExplorer = m_regOnlyExplorer;
60 m_bRemovable = m_regDriveMaskRemovable;
61 m_bFloppy = m_regDriveMaskFloppy;
62 m_bNetwork = m_regDriveMaskRemote;
63 m_bFixed = m_regDriveMaskFixed;
64 m_bCDROM = m_regDriveMaskCDROM;
65 m_bRAM = m_regDriveMaskRAM;
66 m_bUnknown = m_regDriveMaskUnknown;
67 m_bUnversionedAsModified = m_regUnversionedAsModified;
68 m_bRecurseSubmodules = m_regRecurseSubmodules;
69 m_bShowExcludedAsNormal = m_regShowExcludedAsNormal;
70 m_sExcludePaths = m_regExcludePaths;
71 m_sExcludePaths.Replace(_T("\n"), _T("\r\n"));
72 m_sIncludePaths = m_regIncludePaths;
73 m_sIncludePaths.Replace(_T("\n"), _T("\r\n"));
74 m_dwCacheType = m_regCacheType;
77 CSetOverlayPage::~CSetOverlayPage()
81 void CSetOverlayPage::DoDataExchange(CDataExchange* pDX)
83 ISettingsPropPage::DoDataExchange(pDX);
84 DDX_Check(pDX, IDC_REMOVABLE, m_bRemovable);
85 DDX_Check(pDX, IDC_NETWORK, m_bNetwork);
86 DDX_Check(pDX, IDC_FIXED, m_bFixed);
87 DDX_Check(pDX, IDC_CDROM, m_bCDROM);
88 DDX_Check(pDX, IDC_RAM, m_bRAM);
89 DDX_Check(pDX, IDC_UNKNOWN, m_bUnknown);
90 DDX_Check(pDX, IDC_ONLYEXPLORER, m_bOnlyExplorer);
91 DDX_Text(pDX, IDC_EXCLUDEPATHS, m_sExcludePaths);
92 DDX_Text(pDX, IDC_INCLUDEPATHS, m_sIncludePaths);
93 DDX_Check(pDX, IDC_UNVERSIONEDASMODIFIED, m_bUnversionedAsModified);
94 DDX_Check(pDX, IDC_RECURSIVESUBMODULES, m_bRecurseSubmodules);
95 DDX_Check(pDX, IDC_FLOPPY, m_bFloppy);
96 DDX_Check(pDX, IDC_SHOWEXCLUDEDASNORMAL, m_bShowExcludedAsNormal);
99 BEGIN_MESSAGE_MAP(CSetOverlayPage, ISettingsPropPage)
100 ON_BN_CLICKED(IDC_REMOVABLE, OnChange)
101 ON_BN_CLICKED(IDC_FLOPPY, &CSetOverlayPage::OnChange)
102 ON_BN_CLICKED(IDC_NETWORK, OnChange)
103 ON_BN_CLICKED(IDC_FIXED, OnChange)
104 ON_BN_CLICKED(IDC_CDROM, OnChange)
105 ON_BN_CLICKED(IDC_UNKNOWN, OnChange)
106 ON_BN_CLICKED(IDC_RAM, OnChange)
107 ON_BN_CLICKED(IDC_ONLYEXPLORER, OnChange)
108 ON_EN_CHANGE(IDC_EXCLUDEPATHS, OnChange)
109 ON_EN_CHANGE(IDC_INCLUDEPATHS, OnChange)
110 ON_BN_CLICKED(IDC_CACHEDEFAULT, &CSetOverlayPage::OnChange)
111 ON_BN_CLICKED(IDC_CACHESHELL, &CSetOverlayPage::OnChange)
112 ON_BN_CLICKED(IDC_CACHESHELL2, &CSetOverlayPage::OnChange)
113 ON_BN_CLICKED(IDC_CACHENONE, &CSetOverlayPage::OnChange)
114 ON_BN_CLICKED(IDC_UNVERSIONEDASMODIFIED, &CSetOverlayPage::OnChange)
115 ON_BN_CLICKED(IDC_RECURSIVESUBMODULES, &CSetOverlayPage::OnChange)
116 ON_BN_CLICKED(IDC_SHOWEXCLUDEDASNORMAL, &CSetOverlayPage::OnChange)
117 END_MESSAGE_MAP()
119 BOOL CSetOverlayPage::OnInitDialog()
121 ISettingsPropPage::OnInitDialog();
123 AdjustControlSize(IDC_REMOVABLE);
124 AdjustControlSize(IDC_NETWORK);
125 AdjustControlSize(IDC_FIXED);
126 AdjustControlSize(IDC_CDROM);
127 AdjustControlSize(IDC_RAM);
128 AdjustControlSize(IDC_UNKNOWN);
129 AdjustControlSize(IDC_ONLYEXPLORER);
130 AdjustControlSize(IDC_UNVERSIONEDASMODIFIED);
131 AdjustControlSize(IDC_RECURSIVESUBMODULES);
132 AdjustControlSize(IDC_FLOPPY);
133 AdjustControlSize(IDC_CACHEDEFAULT);
134 AdjustControlSize(IDC_CACHENONE);
135 AdjustControlSize(IDC_CACHESHELL);
136 AdjustControlSize(IDC_CACHESHELL2);
138 switch (m_dwCacheType)
140 case 0:
141 CheckRadioButton(IDC_CACHEDEFAULT, IDC_CACHENONE, IDC_CACHENONE);
142 break;
143 default:
144 case 1:
145 CheckRadioButton(IDC_CACHEDEFAULT, IDC_CACHENONE, IDC_CACHEDEFAULT);
146 break;
147 case 2:
148 CheckRadioButton(IDC_CACHEDEFAULT, IDC_CACHENONE, IDC_CACHESHELL);
149 break;
150 case 3:
151 CheckRadioButton(IDC_CACHEDEFAULT, IDC_CACHENONE, IDC_CACHESHELL2);
152 break;
154 GetDlgItem(IDC_UNVERSIONEDASMODIFIED)->EnableWindow(m_dwCacheType == 1);
155 GetDlgItem(IDC_RECURSIVESUBMODULES)->EnableWindow(m_dwCacheType == 1);
156 GetDlgItem(IDC_FLOPPY)->EnableWindow(m_bRemovable);
158 m_tooltips.AddTool(IDC_ONLYEXPLORER, IDS_SETTINGS_ONLYEXPLORER_TT);
159 m_tooltips.AddTool(IDC_EXCLUDEPATHS, IDS_SETTINGS_EXCLUDELIST_TT);
160 m_tooltips.AddTool(IDC_INCLUDEPATHS, IDS_SETTINGS_INCLUDELIST_TT);
161 m_tooltips.AddTool(IDC_CACHEDEFAULT, IDS_SETTINGS_CACHEDEFAULT_TT);
162 m_tooltips.AddTool(IDC_CACHESHELL, IDS_SETTINGS_CACHESHELL_TT);
163 m_tooltips.AddTool(IDC_CACHESHELL2, IDS_SETTINGS_CACHESHELLEXT_TT);
164 m_tooltips.AddTool(IDC_CACHENONE, IDS_SETTINGS_CACHENONE_TT);
165 m_tooltips.AddTool(IDC_UNVERSIONEDASMODIFIED, IDS_SETTINGS_UNVERSIONEDASMODIFIED_TT);
166 m_tooltips.AddTool(IDC_SHOWEXCLUDEDASNORMAL, IDS_SETTINGS_SHOWEXCLUDEDASNORMAL_TT);
168 UpdateData(FALSE);
170 return TRUE;
173 void CSetOverlayPage::OnChange()
175 UpdateData();
176 int id = GetCheckedRadioButton(IDC_CACHEDEFAULT, IDC_CACHENONE);
177 switch (id)
179 default:
180 case IDC_CACHEDEFAULT:
181 m_dwCacheType = 1;
182 break;
183 case IDC_CACHESHELL:
184 m_dwCacheType = 2;
185 break;
186 case IDC_CACHESHELL2:
187 m_dwCacheType = 3;
188 break;
189 case IDC_CACHENONE:
190 m_dwCacheType = 0;
191 break;
193 GetDlgItem(IDC_UNVERSIONEDASMODIFIED)->EnableWindow(m_dwCacheType == 1);
194 GetDlgItem(IDC_RECURSIVESUBMODULES)->EnableWindow(m_dwCacheType == 1);
195 GetDlgItem(IDC_FLOPPY)->EnableWindow(m_bRemovable);
196 SetModified();
199 BOOL CSetOverlayPage::OnApply()
201 UpdateData();
202 Store(m_bOnlyExplorer, m_regOnlyExplorer);
203 if (DWORD(m_regDriveMaskRemovable) != DWORD(m_bRemovable))
204 m_restart = Restart_Cache;
205 Store(m_bRemovable, m_regDriveMaskRemovable);
207 if (DWORD(m_regDriveMaskFloppy) != DWORD(m_bFloppy))
208 m_restart = Restart_Cache;
209 Store(m_bFloppy, m_regDriveMaskFloppy);
211 if (DWORD(m_regDriveMaskRemote) != DWORD(m_bNetwork))
212 m_restart = Restart_Cache;
213 Store(m_bNetwork, m_regDriveMaskRemote);
215 if (DWORD(m_regDriveMaskFixed) != DWORD(m_bFixed))
216 m_restart = Restart_Cache;
217 Store(m_bFixed, m_regDriveMaskFixed);
219 if (DWORD(m_regDriveMaskCDROM) != DWORD(m_bCDROM))
220 m_restart = Restart_Cache;
221 Store(m_bCDROM, m_regDriveMaskCDROM);
223 if (DWORD(m_regDriveMaskRAM) != DWORD(m_bRAM))
224 m_restart = Restart_Cache;
225 Store(m_bRAM, m_regDriveMaskRAM);
227 if (DWORD(m_regDriveMaskUnknown) != DWORD(m_bUnknown))
228 m_restart = Restart_Cache;
229 Store(m_bUnknown, m_regDriveMaskUnknown);
231 if (m_sExcludePaths.Compare(CString(m_regExcludePaths)))
232 m_restart = Restart_Cache;
233 m_sExcludePaths.Remove('\r');
234 if (m_sExcludePaths.Right(1).Compare(_T("\n"))!=0)
235 m_sExcludePaths += _T("\n");
236 Store(m_sExcludePaths, m_regExcludePaths);
237 m_sExcludePaths.Replace(_T("\n"), _T("\r\n"));
238 m_sIncludePaths.Remove('\r');
239 if (m_sIncludePaths.Right(1).Compare(_T("\n"))!=0)
240 m_sIncludePaths += _T("\n");
241 if (m_sIncludePaths.Compare(CString(m_regIncludePaths)))
242 m_restart = Restart_Cache;
243 Store(m_sIncludePaths, m_regIncludePaths);
244 m_sIncludePaths.Replace(_T("\n"), _T("\r\n"));
246 if (DWORD(m_regUnversionedAsModified) != DWORD(m_bUnversionedAsModified))
247 m_restart = Restart_Cache;
248 Store(m_bUnversionedAsModified, m_regUnversionedAsModified);
249 if (DWORD(m_regRecurseSubmodules) != DWORD(m_bRecurseSubmodules))
250 m_restart = Restart_Cache;
251 Store(m_bRecurseSubmodules, m_regRecurseSubmodules);
252 if (DWORD(m_regShowExcludedAsNormal) != DWORD(m_bShowExcludedAsNormal))
253 m_restart = Restart_Cache;
254 Store(m_bShowExcludedAsNormal, m_regShowExcludedAsNormal);
256 Store(m_dwCacheType, m_regCacheType);
257 if (m_dwCacheType != 1)
259 // close the possible running cache process
260 HWND hWnd = ::FindWindow(TGIT_CACHE_WINDOW_NAME, TGIT_CACHE_WINDOW_NAME);
261 if (hWnd)
263 ::PostMessage(hWnd, WM_CLOSE, NULL, NULL);
265 m_restart = Restart_None;
267 SetModified(FALSE);
268 return ISettingsPropPage::OnApply();