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.
21 #include "SettingsPropPage.h"
24 class CSettingsAdvanced
: public ISettingsPropPage
26 DECLARE_DYNAMIC(CSettingsAdvanced
)
30 virtual ~CSettingsAdvanced();
32 UINT
GetIconID() override
{ return IDI_GENERAL
; }
35 enum { IDD
= IDD_SETTINGS_CONFIG
};
40 AdvancedSetting(const wchar_t* sName
) noexcept
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;
52 CString
GetRegistryPath() const
54 return L
"Software\\TortoiseGit\\" + GetName();
60 class StringSetting
: public AdvancedSetting
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
77 void StoreValue(const CString
& sValue
) const override
79 CRegString
s(GetRegistryPath(), m_defaultValue
);
80 if (sValue
.Compare(static_cast<CString
>(s
)))
85 LPCWSTR m_defaultValue
;
87 class BooleanSetting
: public AdvancedSetting
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
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())
116 const DWORD newValue
= sValue
.Compare(L
"true") == 0;
117 if (DWORD(s
) != newValue
)
122 bool m_defaultValue
= false;
124 class DWORDSetting
: public AdvancedSetting
127 DWORDSetting(const wchar_t* sName
, DWORD defaultValue
) noexcept
128 : AdvancedSetting(sName
)
129 , m_defaultValue(defaultValue
)
133 CString
GetValue() const override
136 temp
.Format(L
"%ld", static_cast<DWORD
>(CRegDWORD(GetRegistryPath(), m_defaultValue
)));
139 bool IsValid(LPCWSTR pszText
) const override
142 const wchar_t* pChar
= pszText
;
145 if (!_istdigit(*pChar
))
151 void StoreValue(const CString
& sValue
) const override
153 CRegDWORD
s(GetRegistryPath(), m_defaultValue
);
154 if (sValue
.IsEmpty())
159 if (DWORD(_wtol(sValue
)) != DWORD(s
))
164 DWORD m_defaultValue
;
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()
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
;