Fix building libgit with Windows 11 SDK 10.0.26100.0
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingsAdvanced.h
blob86f71b16237139ab46530d5ddbc988649f96ae31
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2009-2010, 2015 - 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 #pragma once
21 #include "SettingsPropPage.h"
24 class CSettingsAdvanced : public ISettingsPropPage
26 DECLARE_DYNAMIC(CSettingsAdvanced)
28 public:
29 CSettingsAdvanced();
30 virtual ~CSettingsAdvanced();
32 UINT GetIconID() override { return IDI_GENERAL; }
34 // Dialog Data
35 enum { IDD = IDD_SETTINGS_CONFIG };
37 class AdvancedSetting
39 public:
40 AdvancedSetting(const wchar_t* sName) noexcept
41 : sName(sName)
44 virtual ~AdvancedSetting() = default;
46 CString GetName() const { return sName; }
47 virtual CString GetValue() const = 0;
48 virtual bool IsValid(LPCWSTR s) const = 0;
49 virtual void StoreValue(const CString& sValue) const = 0;
51 protected:
52 CString GetRegistryPath() const
54 return L"Software\\TortoiseGit\\" + GetName();
57 private:
58 CString sName;
60 class StringSetting : public AdvancedSetting
62 public:
63 StringSetting(const wchar_t* sName, LPCWSTR defaultValue) noexcept
64 : AdvancedSetting(sName)
65 , m_defaultValue(defaultValue)
69 CString GetValue() const override
71 return CRegString(GetRegistryPath(), m_defaultValue);
73 bool IsValid(LPCWSTR /*s*/) const override
75 return true;
77 void StoreValue(const CString& sValue) const override
79 CRegString s(GetRegistryPath(), m_defaultValue);
80 if (sValue.Compare(static_cast<CString>(s)))
81 s = sValue;
84 private:
85 LPCWSTR m_defaultValue;
87 class BooleanSetting : public AdvancedSetting
89 public:
90 BooleanSetting(const wchar_t* sName, bool defaultValue) noexcept
91 : AdvancedSetting(sName)
92 , m_defaultValue(defaultValue)
96 CString GetValue() const override
98 return static_cast<DWORD>(CRegDWORD(GetRegistryPath(), m_defaultValue)) ? L"true" : L"false";
100 bool IsValid(LPCWSTR pszText) const override
102 assert(pszText);
103 return (!*pszText ||
104 (wcscmp(pszText, L"true") == 0) ||
105 (wcscmp(pszText, L"false") == 0));
107 void StoreValue(const CString& sValue) const override
109 CRegDWORD s(GetRegistryPath(), m_defaultValue);
110 if (sValue.IsEmpty())
112 s.removeValue();
113 return;
116 const DWORD newValue = sValue.Compare(L"true") == 0;
117 if (DWORD(s) != newValue)
118 s = newValue;
121 private:
122 bool m_defaultValue = false;
124 class DWORDSetting : public AdvancedSetting
126 public:
127 DWORDSetting(const wchar_t* sName, DWORD defaultValue) noexcept
128 : AdvancedSetting(sName)
129 , m_defaultValue(defaultValue)
133 CString GetValue() const override
135 CString temp;
136 temp.Format(L"%ld", static_cast<DWORD>(CRegDWORD(GetRegistryPath(), m_defaultValue)));
137 return temp;
139 bool IsValid(LPCWSTR pszText) const override
141 assert(pszText);
142 const wchar_t* pChar = pszText;
143 while (*pChar)
145 if (!_istdigit(*pChar))
146 return false;
147 ++pChar;
149 return true;
151 void StoreValue(const CString& sValue) const override
153 CRegDWORD s(GetRegistryPath(), m_defaultValue);
154 if (sValue.IsEmpty())
156 s.removeValue();
157 return;
159 if (DWORD(_wtol(sValue)) != DWORD(s))
160 s = _wtol(sValue);
163 private:
164 DWORD m_defaultValue;
167 protected:
168 void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
169 BOOL OnApply() override;
170 BOOL PreTranslateMessage(MSG* pMsg) override;
171 BOOL OnInitDialog() override;
172 afx_msg void OnLvnBeginlabeledit(NMHDR *pNMHDR, LRESULT *pResult);
173 afx_msg void OnLvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult);
174 afx_msg void OnNMDblclkConfig(NMHDR *pNMHDR, LRESULT *pResult);
176 DECLARE_MESSAGE_MAP()
178 private:
179 template<typename T, typename S>
180 void AddSetting(const wchar_t* sName, S defaultValue)
182 settings.emplace_back(std::make_unique<T>(sName, defaultValue));
185 CListCtrl m_ListCtrl;
186 std::vector<std::unique_ptr<AdvancedSetting>> settings;