58#include <wx/filename.h>
59#include <wx/stdpaths.h>
67 L
"/Update/DefaultUpdatesChecking",
true };
87 using Publisher::Publish;
138static void CopyEntry(wxString path, wxConfigBase *src, wxConfigBase *dst, wxString
entry)
140 switch(src->GetEntryType(
entry)) {
141 case wxConfigBase::Type_Unknown:
142 case wxConfigBase::Type_String: {
143 wxString value = src->Read(
entry, wxT(
""));
144 dst->Write(path +
entry, value);
147 case wxConfigBase::Type_Boolean: {
149 src->Read(
entry, &value, value);
150 dst->Write(path +
entry, value);
153 case wxConfigBase::Type_Integer: {
155 src->Read(
entry, &value, value);
156 dst->Write(path +
entry, value);
159 case wxConfigBase::Type_Float: {
160 double value =
false;
161 src->Read(
entry, &value, value);
162 dst->Write(path +
entry, value);
170static void CopyEntriesRecursive(wxString path, wxConfigBase *src, wxConfigBase *dst)
176 entryKeepGoing = src->GetFirstEntry(entryName, entryIndex);
177 while (entryKeepGoing) {
178 CopyEntry(path, src, dst, entryName);
179 entryKeepGoing = src->GetNextEntry(entryName, entryIndex);
186 groupKeepGoing = src->GetFirstGroup(groupName, groupIndex);
187 while (groupKeepGoing) {
188 wxString subPath = path+groupName+wxT(
"/");
189 src->SetPath(subPath);
190 CopyEntriesRecursive(subPath, src, dst);
192 groupKeepGoing = src->GetNextGroup(groupName, groupIndex);
201 wxConfigBase::Set(
gPrefs);
209 std::pair<BoolSetting &, bool> stickyBoolSettings[] {
213 for (
auto &pair : stickyBoolSettings)
214 pair.second = pair.first.
Read();
219 for (
auto &pair : stickyBoolSettings)
220 pair.first.Write(pair.second);
226 wxConfigBase::Set(NULL);
245 if ( sCurrent ==
this ) {
247 for (
auto pSetting : mPending )
248 pSetting->Rollback();
256 if ( !sCurrent || sCurrent->mCommitted )
258 return sCurrent->mPending.insert( &setting ).second
265 if ( sCurrent ==
this && !mCommitted ) {
266 for (
auto pSetting : mPending )
267 if ( !pSetting->Commit() )
284 : mInternals(
std::move( internals ) )
287 if (
size != size2 ) {
293 auto iter2 = msgids.begin();
295 emplace_back( *iter1++, *iter2++ );
301 mMsgids = transform_container<TranslatableStrings>( *
this,
309 mInternals = transform_container<wxArrayStringEx>( *
this,
332 if ( !
gPrefs->Read(
mKey, &value, defaultValue) )
340 auto index =
Find( value );
342 value = defaultValue;
361 auto index =
Find( value );
375 std::vector<int> intValues,
376 const wxString &oldKey
379 , mIntValues{
std::move( intValues ) }
391 if ( value < (
long)
mSymbols.size() )
407 wxString defaultString;
408 auto index0 =
FindInt( defaultValue );
410 defaultString =
mSymbols[ index0 ].Internal();
416 wxASSERT( index <
mSymbols.size() );
437 auto index = (long)
FindInt( intValue );
438 if ( index >= (
long)
mSymbols.size() )
440 if ( index >= 0 && index < (
long)
mSymbols.size() ) {
458 return wxT(
"/Warnings/") + internalDialogName;
498 return config && config->DeleteEntry(
GetPath() );
504 if (
Write( !value ) )
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
static const AudacityProject::AttachedObjects::RegisteredFactory key
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
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
EnumSettingBase(const SettingBase &key, EnumValueSymbols symbols, long defaultSymbol, std::vector< int > intValues, const wxString &oldKey={})
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
Base class for settings objects. It holds a configuration key path.
bool Delete()
Delete the key if present, and return true iff it was.
const wxString & GetPath() const
wxConfigBase * GetConfig() 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 */
Makes temporary changes to preferences, then rolls them back at destruction.
static SettingScope * sCurrent
static AddResult Add(TransactionalSettingBase &setting)
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, if Traits<Type>::iterated_type is defined.
std::set< PreferenceInitializer * > PreferenceInitializers
PreferenceInitializers & allInitializers()
virtual ~PreferenceInitializer()
static void ReinitializeAll()
Impl(PrefsListener &owner)
Observer::Subscription mSubscription