diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 2a6a89ba2..0a368b37d 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -241,7 +241,7 @@ void PopulatePreferences() wxYES_NO, NULL); if (action == wxYES) // reset { - gPrefs->DeleteAll(); + ResetPreferences(); writeLang = true; } } diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp index e24fa6954..c4818df6f 100644 --- a/src/PluginManager.cpp +++ b/src/PluginManager.cpp @@ -1943,6 +1943,9 @@ void PluginManager::Load() if (!registry.HasGroup(REGROOT)) { // Must start over + // This DeleteAll affects pluginregistry.cfg only, not audacity.cfg + // That is, the memory of on/off states of effect (and generator, + // analyzer, and tool) plug-ins registry.DeleteAll(); registry.Flush(); return; @@ -2286,7 +2289,7 @@ void PluginManager::Save() {}, {}, FileNames::PluginRegistry()); auto ®istry = *pRegistry; - // Clear it out + // Clear pluginregistry.cfg (not audacity.cfg) registry.DeleteAll(); // Write the version string diff --git a/src/Prefs.cpp b/src/Prefs.cpp index 6dab73e7e..071698622 100755 --- a/src/Prefs.cpp +++ b/src/Prefs.cpp @@ -63,6 +63,9 @@ #include "MemoryX.h" #include +BoolSetting DefaultUpdatesCheckingFlag{ + L"/Update/DefaultUpdatesChecking", true }; + std::unique_ptr ugPrefs {}; FileConfig *gPrefs = nullptr; @@ -179,6 +182,25 @@ void InitPreferences( std::unique_ptr uPrefs ) wxConfigBase::Set(gPrefs); } +void ResetPreferences() +{ + // Future: make this a static registry table, so the settings objects + // don't need to be defined in this source code file to avoid dependency + // cycles + std::pair stickyBoolSettings[] { + {DefaultUpdatesCheckingFlag, 0}, + // ... others? + }; + for (auto &pair : stickyBoolSettings) + pair.second = pair.first.Read(); + + bool savedValue = DefaultUpdatesCheckingFlag.Read(); + gPrefs->DeleteAll(); + + for (auto &pair : stickyBoolSettings) + pair.first.Write(pair.second); +} + void FinishPreferences() { if (gPrefs) { diff --git a/src/Prefs.h b/src/Prefs.h index d1a46e63c..95da48bb0 100644 --- a/src/Prefs.h +++ b/src/Prefs.h @@ -48,6 +48,12 @@ class wxFileName; void InitPreferences( std::unique_ptr uPrefs ); +//! Call this to reset preferences to an (almost)-"new" default state +/*! + There is at least one exception to that: user preferences we want to make + more "sticky." Notably, whether automatic update checking is preferred. + */ +void ResetPreferences(); void FinishPreferences(); extern AUDACITY_DLL_API FileConfig *gPrefs; @@ -423,4 +429,7 @@ struct AUDACITY_DLL_API PreferenceInitializer { static void ReinitializeAll(); }; +// Special extra-sticky settings +extern AUDACITY_DLL_API BoolSetting DefaultUpdatesCheckingFlag; + #endif diff --git a/src/effects/EffectManager.cpp b/src/effects/EffectManager.cpp index e983cb6e4..66f986f29 100644 --- a/src/effects/EffectManager.cpp +++ b/src/effects/EffectManager.cpp @@ -647,6 +647,7 @@ wxString EffectManager::GetPreset(const PluginID & ID, const wxString & params, return preset; } + // This cleans a config "file" backed by a string in memory. eap.DeleteAll(); eap.Write(wxT("Use Preset"), preset); diff --git a/src/menus/PluginMenus.cpp b/src/menus/PluginMenus.cpp index 8eaeba3da..2f0f17ae1 100644 --- a/src/menus/PluginMenus.cpp +++ b/src/menus/PluginMenus.cpp @@ -384,7 +384,7 @@ void OnResetConfig(const CommandContext &context) menuManager.mLastAnalyzer = ""; menuManager.mLastTool = ""; - gPrefs->DeleteAll(); + ResetPreferences(); // Directory will be reset on next restart. FileNames::UpdateDefaultPath(FileNames::Operation::Temp, TempDirectory::DefaultTempDir()); diff --git a/src/prefs/ApplicationPrefs.cpp b/src/prefs/ApplicationPrefs.cpp index a894c6963..6143fa920 100644 --- a/src/prefs/ApplicationPrefs.cpp +++ b/src/prefs/ApplicationPrefs.cpp @@ -72,7 +72,7 @@ void ApplicationPrefs::PopulateOrExchange(ShuttleGui & S) { S.TieCheckBox( XO("&Check for Updates...").Stripped(TranslatableString::Ellipses | TranslatableString::MenuCodes), - UpdatesCheckingSettings::DefaultUpdatesCheckingFlag); + DefaultUpdatesCheckingFlag); } S.EndStatic(); S.EndScroller(); diff --git a/src/update/UpdateManager.cpp b/src/update/UpdateManager.cpp index 02be92215..96f520d23 100644 --- a/src/update/UpdateManager.cpp +++ b/src/update/UpdateManager.cpp @@ -24,9 +24,6 @@ #include #include -BoolSetting UpdatesCheckingSettings::DefaultUpdatesCheckingFlag{ - L"/Update/DefaultUpdatesChecking", true }; - static const char* prefsUpdateScheduledTime = "/Update/UpdateScheduledTime"; @@ -127,7 +124,7 @@ void UpdateManager::GetUpdates(bool ignoreNetworkErrors) void UpdateManager::OnTimer(wxTimerEvent& WXUNUSED(event)) { - bool updatesCheckingEnabled = UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Read(); + bool updatesCheckingEnabled = DefaultUpdatesCheckingFlag.Read(); if (updatesCheckingEnabled && IsTimeForUpdatesChecking()) GetUpdates(true); diff --git a/src/update/UpdateManager.h b/src/update/UpdateManager.h index 944099566..1ff43906f 100644 --- a/src/update/UpdateManager.h +++ b/src/update/UpdateManager.h @@ -18,10 +18,6 @@ #include #include -namespace UpdatesCheckingSettings { - extern AUDACITY_DLL_API BoolSetting DefaultUpdatesCheckingFlag; -} - /// A class that managing of updates. /** Opt-in request and show update dialog by the scheduled time. diff --git a/src/update/UpdatePopupDialog.cpp b/src/update/UpdatePopupDialog.cpp index 718144689..e7f58e4b5 100644 --- a/src/update/UpdatePopupDialog.cpp +++ b/src/update/UpdatePopupDialog.cpp @@ -45,7 +45,7 @@ UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, const VersionPatch& vers S.Id (DontShowID).AddCheckBox ( XO ("Don't show this again at start up"), - !UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Read()); + !DefaultUpdatesCheckingFlag.Read()); S.Prop(1).AddSpace(1, 0, 1); @@ -80,7 +80,7 @@ void UpdatePopupDialog::OnSkip (wxCommandEvent&) void UpdatePopupDialog::OnDontShow (wxCommandEvent& event) { - UpdatesCheckingSettings::DefaultUpdatesCheckingFlag.Write(!event.IsChecked()); + DefaultUpdatesCheckingFlag.Write(!event.IsChecked()); } HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)