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.
This commit is contained in:
David Bailes 2018-01-10 11:26:29 +00:00
parent bfbc218a5b
commit cfdb7950f1
3 changed files with 37 additions and 3 deletions

View File

@ -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<CommandHandler> mCmdHandler;
std::unique_ptr<FileHistory> mRecentFiles;
@ -199,6 +206,11 @@ class AudacityApp final : public wxApp {
std::unique_ptr<wxSocketServer> 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()
};

View File

@ -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.

View File

@ -47,6 +47,8 @@
#include <wx/minifram.h>
#include <wx/popupwin.h>
#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<int>(dock == mTopDock ? TopDockID : dock == mBotDock ? BotDockID : NoDockID ));
gPrefs->DeleteEntry(wxT("Dock")); // Remove any legacy configuration info.
gPrefs->Write( wxT("Dock"), static_cast<int>( to ? TopDockID : bo ? BotDockID : NoDockID));
dock = to ? mTopDock : bo ? mBotDock : nullptr; // dock for shown toolbars
ToolBarConfiguration::Write