57#include <wx/filename.h>
58#include <wx/stdpaths.h>
66 L
"/Update/DefaultUpdatesChecking",
true };
86 using Publisher::Publish;
141static void CopyEntry(wxString path, wxConfigBase *src, wxConfigBase *dst, wxString
entry)
143 switch(src->GetEntryType(
entry)) {
144 case wxConfigBase::Type_Unknown:
145 case wxConfigBase::Type_String: {
146 wxString value = src->Read(
entry,
wxT(
""));
147 dst->Write(path +
entry, value);
150 case wxConfigBase::Type_Boolean: {
152 src->Read(
entry, &value, value);
153 dst->Write(path +
entry, value);
156 case wxConfigBase::Type_Integer: {
158 src->Read(
entry, &value, value);
159 dst->Write(path +
entry, value);
162 case wxConfigBase::Type_Float: {
163 double value =
false;
164 src->Read(
entry, &value, value);
165 dst->Write(path +
entry, value);
173static void CopyEntriesRecursive(wxString path, wxConfigBase *src, wxConfigBase *dst)
179 entryKeepGoing = src->GetFirstEntry(entryName, entryIndex);
180 while (entryKeepGoing) {
181 CopyEntry(path, src, dst, entryName);
182 entryKeepGoing = src->GetNextEntry(entryName, entryIndex);
189 groupKeepGoing = src->GetFirstGroup(groupName, groupIndex);
190 while (groupKeepGoing) {
191 wxString subPath = path+groupName+
wxT(
"/");
192 src->SetPath(subPath);
193 CopyEntriesRecursive(subPath, src, dst);
195 groupKeepGoing = src->GetNextGroup(groupName, groupIndex);
204 wxConfigBase::Set(
gPrefs);
212 std::pair<BoolSetting &, bool> stickyBoolSettings[] {
216 for (
auto &pair : stickyBoolSettings)
217 pair.second = pair.first.
Read();
222 for (
auto &pair : stickyBoolSettings)
223 pair.first.Write(pair.second);
229 wxConfigBase::Set(NULL);
255 for (
auto pSetting : mPending)
256 pSetting->Rollback();
267 const bool inserted =
sScopes.back()->mPending.insert(&setting).second;
271 setting.EnterTransaction(
sScopes.size());
277 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
280 (*it)->mPending.insert(&setting);
284 return inserted ? Added : PreviouslyAdded;
293 for (
auto pSetting : mPending )
294 if ( !pSetting->Commit() )
314 : mInternals(
std::move( internals ) )
317 if (
size != size2 ) {
323 auto iter2 = msgids.begin();
325 emplace_back( *iter1++, *iter2++ );
331 mMsgids = transform_container<TranslatableStrings>( *
this,
339 mInternals = transform_container<wxArrayStringEx>( *
this,
362 if ( !
gPrefs->Read(
mKey, &value, defaultValue) )
370 auto index =
Find( value );
372 value = defaultValue;
391 auto index =
Find( value );
419 wxString defaultString;
420 auto index0 =
FindInt( defaultValue );
422 defaultString =
mSymbols[ index0 ].Internal();
428 wxASSERT( index <
mSymbols.size() );
449 auto index = (long)
FindInt( intValue );
450 if ( index >= (
long)
mSymbols.size() )
452 if ( index >= 0 && index < (
long)
mSymbols.size() ) {
470 return wxT(
"/Warnings/") + internalDialogName;
510 return config && config->DeleteEntry(
GetPath() );
516 if (
Write( !value ) )
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
std::unique_ptr< FileConfig > ugPrefs
BoolSetting DefaultUpdatesCheckingFlag
wxString WarningDialogKey(const wxString &internalDialogName)
void InitPreferences(std::unique_ptr< FileConfig > uPrefs)
void ResetPreferences()
Call this to reset preferences to an (almost)-"new" default state.
static ProjectFileIORegistry::AttributeWriterEntry entry
std::vector< TranslatableString > TranslatableStrings
This specialization of Setting for bool adds a Toggle method to negate the saved value.
bool Toggle()
Write the negation of the previous value, and then return the current value.
bool Write(const wxString &value)
const EnumValueSymbols mSymbols
const EnumValueSymbols & GetSymbols() const
void SetDefault(long value)
size_t Find(const wxString &value) const
TransactionalSettingBase *const mpOtherSettings
wxString ReadWithDefault(const wxString &) const
virtual void Migrate(wxString &)
const EnumValueSymbol & Default() const
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
const TranslatableString & Msgid() const
std::vector< int > mIntValues
void Migrate(wxString &) override
size_t FindInt(int code) const
int ReadIntWithDefault(int defaultValue) const
const wxArrayStringEx & GetInternals() const
EnumValueSymbols()=default
wxArrayStringEx mInternals
TranslatableStrings mMsgids
const TranslatableStrings & GetMsgids() const
virtual bool DeleteAll() wxOVERRIDE
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
An object that sends messages to an open-ended list of subscribed callbacks.
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
CallbackReturn Publish(const Message &message)
Send a message to connected callbacks.
A move-only handle representing a connection to a Publisher.
A listener notified of changes in preferences.
static void Broadcast(int id=0)
Call this static function to notify all PrefsListener objects.
std::unique_ptr< Impl > mpImpl
virtual void UpdateSelectedPrefs(int id)
virtual void UpdatePrefs()=0
bool Delete()
Delete the key if present, and return true iff it was.
wxConfigBase * GetConfig() const
const SettingPath & GetPath() const
bool Write(const bool &value)
Write value to config and return true if successful.
bool Read() const
overload of Read, always returning a value
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
static AddResult Add(TransactionalSettingBase &setting)
virtual void Invalidate()=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
std::vector< SettingScope * > sScopes
std::set< PreferenceInitializer * > PreferenceInitializers
PreferenceInitializers & allInitializers()
virtual ~PreferenceInitializer()
static void ReinitializeAll()
Impl(PrefsListener &owner)
Observer::Subscription mSubscription