1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-04-02 20:37:38 +02:00

Define Setting classes, bundling config path with settings value...

... the intention being, that no string literal for a path, or its default
value, shall ever occur twice in the code, relying on long-distance coincidence
of literal values.  Instead, a named Setting object is constructed once, then
read and written.

For now, the Tie... functions in ShuttleGuiBase will take references to
implicitly constructed temporary Setting objects.  But all should later be
made static objects, and the constructors made explicit.
This commit is contained in:
Paul Licameli
2019-04-03 11:27:15 -04:00
parent b6c7b744f8
commit 5fef82dccf
9 changed files with 240 additions and 52 deletions

View File

@@ -280,7 +280,7 @@ bool ChoiceSetting::Write( const wxString &value )
}
EnumSettingBase::EnumSettingBase(
const wxString &key,
const SettingBase &key,
EnumValueSymbols symbols,
long defaultSymbol,
@@ -398,3 +398,23 @@ void PreferenceInitializer::ReinitializeAll()
for ( auto pInitializer : allInitializers() )
(*pInitializer)();
}
wxConfigBase *SettingBase::GetConfig() const
{
return gPrefs;
}
bool SettingBase::Delete()
{
auto config = GetConfig();
return config && config->DeleteEntry( GetPath() );
}
bool BoolSetting::Toggle()
{
bool value = Read();
if ( Write( !value ) )
return !value;
else
return value;
}