29#ifndef __AUDACITY_PREFS__
30#define __AUDACITY_PREFS__
39#define AUDACITY_PREFS_VERSION_STRING "1.1.1r1"
51PREFERENCES_API
void InitPreferences( std::unique_ptr<FileConfig> uPrefs );
155template<
typename T >
159 using TransactionalSettingBase::TransactionalSettingBase;
165 mutable T mCurrentValue{};
166 mutable bool mValid{
false};
171template<
typename T >
182 , mDefaultValue{ defaultValue }
188 , mFunction{ function }
195 mDefaultValue = mFunction();
196 return mDefaultValue;
202 return ReadWithDefault( pVar, GetDefault() );
209 *pVar = defaultValue;
210 if ( pVar && this->mValid ) {
211 *pVar = this->mCurrentValue;
215 if ( pVar && config ) {
216 if ((this->mValid = config->Read( this->mPath, &this->mCurrentValue )))
217 *pVar = this->mCurrentValue;
220 return (this->mValid =
false);
228 return ReadWithDefault( GetDefault() );
237 return this->mCurrentValue;
240 this->mCurrentValue =
241 config->ReadObject(this->
mPath, defaultValue);
244 this->mValid = (this->mCurrentValue != defaultValue);
245 return this->mCurrentValue;
256 if (config ==
nullptr)
263 this->mCurrentValue = value;
270 this->mCurrentValue = value;
279 return Write( GetDefault() );
284 this->mValid =
false;
290 const T value =
Read();
292 for (
size_t i = mPreviousValues.size(); i < depth; ++i)
293 this->mPreviousValues.emplace_back( value );
299 assert(!this->mPreviousValues.empty());
301 if (this->mPreviousValues.empty())
304 const auto result = this->mPreviousValues.size() > 1 || DoWrite();
305 mPreviousValues.pop_back();
313 assert(!this->mPreviousValues.empty());
315 if (!this->mPreviousValues.empty())
317 this->mCurrentValue = std::move(this->mPreviousValues.back());
318 this->mPreviousValues.pop_back();
328 return this->mValid =
329 config ? config->Write( this->
mPath, this->mCurrentValue ) :
false;
333 mutable T mDefaultValue{};
413 long defaultSymbol = -1)
415 , mSymbols{ move(symbols) }
416 , mpOtherSettings{ &
key }
417 , mDefaultSymbol{ defaultSymbol }
419 assert(defaultSymbol <
static_cast<long>(mSymbols.size()));
424 long defaultSymbol = -1)
426 , mSymbols{ move(symbols) }
427 , mDefaultSymbol{ defaultSymbol }
429 assert(defaultSymbol <
static_cast<long>(mSymbols.size()));
432 const wxString &
Key()
const {
return mKey; }
436 wxString
Read()
const;
441 wxString ReadWithDefault(
const wxString & )
const;
443 bool Write(
const wxString &value );
446 void SetDefault(
long value );
449 size_t Find(
const wxString &value )
const;
450 virtual void Migrate( wxString& );
457 mutable bool mMigrated {
false };
469 template<
typename Key>
475 std::vector<int> intValues,
476 const wxString &oldKey = {}
478 , mIntValues{ move(intValues) }
481 assert (mIntValues.size() == mSymbols.size());
492 int ReadIntWithDefault(
int defaultValue )
const;
496 size_t FindInt(
int code )
const;
497 void Migrate( wxString& )
override;
505template<
typename Enum >
511 template<
typename Key>
517 std::vector< Enum >
values,
518 const wxString &oldKey = {}
521 std::forward<Key>(
key), move(symbols), defaultSymbol,
522 ConvertValues(
values), oldKey
528 {
return static_cast<Enum
>(
ReadInt() ); }
535 auto integer =
static_cast<int>(defaultValue);
536 return static_cast<Enum
>( ReadIntWithDefault( integer ) );
540 {
return WriteInt(
static_cast<int>( value ) ); }
546 std::vector<int> result;
547 result.reserve(
values.size());
549 result.push_back(
static_cast<int>(value));
566 static void Broadcast(
int id = 0);
580 virtual void UpdateSelectedPrefs(
int id );
600 virtual void operator () () = 0;
602 static void ReinitializeAll();
static const AudacityProject::AttachedObjects::RegisteredFactory key
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
PREFERENCES_API void InitPreferences(std::unique_ptr< FileConfig > uPrefs)
PREFERENCES_API BoolSetting DefaultUpdatesCheckingFlag
PREFERENCES_API FileConfig * gPrefs
PREFERENCES_API wxString WarningDialogKey(const wxString &internalDialogName)
PREFERENCES_API void FinishPreferences()
PREFERENCES_API void ResetPreferences()
Call this to reset preferences to an (almost)-"new" default state.
PREFERENCES_API ByColumns_t ByColumns
std::vector< TranslatableString > TranslatableStrings
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Class template adds an in-memory cache of a value to TransactionalSettingBase and support for Setting...
CachingSettingBase(const CachingSettingBase &)=default
CachingSettingBase(const SettingBase &path)
const wxString & Key() const
ChoiceSetting(const SettingBase &key, EnumValueSymbols symbols, long defaultSymbol=-1)
const EnumValueSymbols mSymbols
ChoiceSetting(const SettingPath &, EnumValueSymbols, long=-1)=delete
const EnumValueSymbols & GetSymbols() const
ChoiceSetting(TransactionalSettingBase &key, EnumValueSymbols symbols, long defaultSymbol=-1)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Specialization of Setting for double.
std::vector< int > mIntValues
EnumSettingBase(Key &&key, EnumValueSymbols symbols, long defaultSymbol, std::vector< int > intValues, const wxString &oldKey={})
Adapts EnumSettingBase to a particular enumeration type.
std::vector< int > ConvertValues(const std::vector< Enum > &values)
bool WriteEnum(Enum value)
EnumSetting(Key &&key, EnumValueSymbols symbols, long defaultSymbol, std::vector< Enum > values, const wxString &oldKey={})
Enum ReadEnumWithDefault(Enum defaultValue) const
EnumValueSymbols()=default
wxArrayStringEx mInternals
EnumValueSymbols(std::vector< EnumValueSymbol > symbols)
EnumValueSymbols(std::initializer_list< EnumValueSymbol > symbols)
TranslatableStrings mMsgids
Specialization of Setting for int.
A listener notified of changes in preferences.
std::unique_ptr< Impl > mpImpl
Base class for settings objects. It holds a configuration key path.
SettingBase(const wxChar *path)
SettingBase(const wxString &path)
SettingBase(const char *path)
SettingBase(const SettingBase &)=default
wxConfigBase * GetConfig() const
const SettingPath & GetPath() const
bool Write(const T &value)
Write value to config and return true if successful.
T Read() const
overload of Read, always returning a value
Setting(const SettingBase &path, const T &defaultValue)
Usual overload supplies a default value.
T ReadWithDefault(const T &defaultValue) const
new direct use is discouraged but it may be needed in legacy code
void EnterTransaction(size_t depth) override
void Invalidate() override
bool ReadWithDefault(T *pVar, const T &defaultValue) const
overload of ReadWithDefault returning a boolean that is true if the value was previously defined */
void Rollback() noexcept override
bool Reset()
Reset to the default value.
bool DoWrite()
Write cached value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
std::function< T() > DefaultValueFunction
std::vector< T > mPreviousValues
const T & GetDefault() const
Setting(const SettingBase &path, DefaultValueFunction function)
This overload causes recomputation of the default each time it is needed.
const DefaultValueFunction mFunction
Makes temporary changes to preferences, then rolls them back at destruction.
static AddResult Add(TransactionalSettingBase &setting)
SettingScope(const SettingScope &)=delete
SettingScope & operator=(const SettingScope &)=delete
std::set< TransactionalSettingBase * > mPending
Extend SettingScope with Commit() which flushes updates in a batch.
Specialization of Setting for strings.
friend class SettingScope
virtual void Rollback() noexcept=0
virtual void EnterTransaction(size_t depth)=0
virtual void Invalidate()=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
PROJECT_FILE_IO_API void Add(const FilePath &path)
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
bool GetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, Value &var, const Value &defval)
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
static const auto WriteInt
static const auto ReadInt