From cfdb7950f1cf455f2655769902b602b29c3e6f44 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Wed, 10 Jan 2018 11:26:29 +0000 Subject: [PATCH] Update fix for #1554 This is an update to commit 516af71. The Dock key is now retained in the config file, so that if a user goes back to a version before the fix, the toolbar layout remains unchanged. Note that when ToolManager::ReadConfig() is called, InitPreferences has already been called which has set the version keys to the current version of Audacity. Therefore the initial values of these keys are stored in AudacityApp. --- src/AudacityApp.h | 12 ++++++++++++ src/Prefs.cpp | 3 +++ src/toolbars/ToolManager.cpp | 25 ++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/AudacityApp.h b/src/AudacityApp.h index dafca471b..a16274819 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -168,6 +168,13 @@ class AudacityApp final : public wxApp { #endif + // Set and Get values of the version major/minor/micro keys in audacity.cfg when Audacity first opens + void SetVersionKeysInit( int major, int minor, int micro) + { mVersionMajorKeyInit = major; mVersionMinorKeyInit = minor; mVersionMicroKeyInit = micro;} + void GetVersionKeysInit( int& major, int& minor, int& micro) const + { major = mVersionMajorKeyInit; minor = mVersionMinorKeyInit; micro = mVersionMicroKeyInit;} + + private: std::unique_ptr mCmdHandler; std::unique_ptr mRecentFiles; @@ -199,6 +206,11 @@ class AudacityApp final : public wxApp { std::unique_ptr mIPCServ; #endif + // values of the version major/minor/micro keys in audacity.cfg when Audacity first opens + int mVersionMajorKeyInit{}; + int mVersionMinorKeyInit{}; + int mVersionMicroKeyInit{}; + public: DECLARE_EVENT_TABLE() }; diff --git a/src/Prefs.cpp b/src/Prefs.cpp index bde9908a7..bf2cdd7f2 100755 --- a/src/Prefs.cpp +++ b/src/Prefs.cpp @@ -237,6 +237,9 @@ void InitPreferences() int vMinor = gPrefs->Read(wxT("/Version/Minor"), (long) 0); int vMicro = gPrefs->Read(wxT("/Version/Micro"), (long) 0); + wxGetApp().SetVersionKeysInit(vMajor, vMinor, vMicro); // make a note of these initial values + // for use by ToolManager::ReadConfig() + // These integer version keys were introduced april 4 2011 for 1.3.13 // The device toolbar needs to be enabled due to removal of source selection features in // the mixer toolbar. diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index b8a1e4262..469a59bec 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -47,6 +47,8 @@ #include #include +#include "../AudacityApp.h" + #include "ToolManager.h" #include "ControlToolBar.h" #include "DeviceToolBar.h" @@ -699,6 +701,18 @@ void ToolManager::ReadConfig() ToolBarConfiguration::Legacy topLegacy, botLegacy; + int vMajor, vMinor, vMicro; + wxGetApp().GetVersionKeysInit(vMajor, vMinor, vMicro); + bool useLegacyDock = false; + // note that vMajor, vMinor, and vMicro will all be zero if either it's a new audacity.cfg file + // or the version is less than 1.3.13 (when there were no version keys according to the comments in + // InitPreferences()). So for new audacity.cfg + // file useLegacyDock will be true, but this doesn't matter as there are no Dock or DockV2 keys in the file yet. + if (vMajor <= 1 || + (vMajor == 2 && (vMinor <= 1 || (vMinor == 2 && vMicro <= 1)))) // version <= 2.2.1 + useLegacyDock = true; + + // Load and apply settings for each bar for( ndx = 0; ndx < ToolBarCount; ndx++ ) { @@ -729,8 +743,10 @@ void ToolManager::ReadConfig() #endif // Read in all the settings - gPrefs->Read( wxT("Dock"), &dock, -1); // legacy version of DockV2 - if (dock == -1) + + if (useLegacyDock) + gPrefs->Read( wxT("Dock"), &dock, -1); // legacy version of DockV2 + else gPrefs->Read( wxT("DockV2"), &dock, -1); const bool found = (dock != -1); @@ -972,10 +988,13 @@ void ToolManager::WriteConfig() bool bo = mBotDock->GetConfiguration().Contains( bar ); // Save + // Note that DockV2 was introduced in 2.2.2 to fix bug #1554. Dock is retained so that + // the toolbar layout is not changed when opening a version before 2.2.2, and in particular + // its value is compatible with versions 2.1.3 to 2.2.1 which have this bug. ToolDock* dock = bar->GetDock(); // dock for both shown and hidden toolbars gPrefs->Write( wxT("DockV2"), static_cast(dock == mTopDock ? TopDockID : dock == mBotDock ? BotDockID : NoDockID )); - gPrefs->DeleteEntry(wxT("Dock")); // Remove any legacy configuration info. + gPrefs->Write( wxT("Dock"), static_cast( to ? TopDockID : bo ? BotDockID : NoDockID)); dock = to ? mTopDock : bo ? mBotDock : nullptr; // dock for shown toolbars ToolBarConfiguration::Write