From 516af7178262b6448040fc22617c1935aea7e361 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Tue, 19 Sep 2017 09:15:52 +0100 Subject: [PATCH] Fix for #1554: toolbars open undocked if previously hidden Problem: 1. If a toolbar is docked and hidden, when config is written, dock is set to 0 (undocked). 2. When config is read, if a toolbar is docked, then the show field is ignored, and the toolbar is always shown. Summary of fix: 1. Introduce a new version of the dock field (DockV2) to minimise the problems when running previous versions of Audacity, having run a version with this patch(as suggested by Paul). 2. In ToolManage::WriteConfig, for a docked toolbar which is hidden, DockV2 is set to the dock number, and not 0. 3. In ToolManager::ReadConfig, for a hidden docked toolbar in the config, the toolbar is docked, but is not included in the configuration. Note, that if a version of Audacity without this fix is run after running a version with this fix: 1. The dock of each toolbar is reset to its default value. 2. In addition, for 2.1.3, 2.2.0 and 2.2.1 whether a toolbar is shown or hidden is reset to its default value. --- src/toolbars/ToolDock.cpp | 17 +++++++++-------- src/toolbars/ToolManager.cpp | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/toolbars/ToolDock.cpp b/src/toolbars/ToolDock.cpp index 3f2a4a55e..e5155847f 100644 --- a/src/toolbars/ToolDock.cpp +++ b/src/toolbars/ToolDock.cpp @@ -237,7 +237,11 @@ bool ToolBarConfiguration::Read { bool result = true; - if (pConfiguration) { + // Future: might remember visibility in the configuration, not forgetting + // positions of hidden bars. + gPrefs->Read( wxT("Show"), &visible, defaultVisible); + + if (pConfiguration && visible) { int ord; gPrefs->Read( wxT("Order"), &ord, -1 ); // Index was written 1-based @@ -267,10 +271,6 @@ bool ToolBarConfiguration::Read } } - // Future: might remember visibility in the configuration, not forgetting - // positions of hidden bars. - gPrefs->Read( wxT("Show"), &visible, defaultVisible); - return result; } @@ -376,8 +376,8 @@ void ToolDock::Undock( ToolBar *bar ) if( mConfiguration.Contains( bar ) ) { mConfiguration.Remove( bar ); - mBars[ bar->GetId() ] = nullptr; } + mBars[ bar->GetId() ] = nullptr; } // @@ -403,14 +403,15 @@ void ToolDock::Dock( ToolBar *bar, bool deflate, ToolBarConfiguration::Position ); // Park the NEW bar in the correct berth - if (!mConfiguration.Contains(bar)) + if (!mConfiguration.Contains(bar) && bar->IsVisible()) mConfiguration.Insert( bar, position ); // Inform toolbar of change bar->SetDocked( this, false ); // Rearrange our world - LayoutToolBars(); + if (bar->IsVisible()) + LayoutToolBars(); Updated(); } diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index 4f35f0bb4..b8a1e4262 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -681,6 +681,7 @@ void ToolManager::ReadConfig() { wxString oldpath = gPrefs->GetPath(); wxArrayInt unordered[ DockCount ]; + std::vector dockedAndHidden; bool show[ ToolBarCount ]; int width[ ToolBarCount ]; int height[ ToolBarCount ]; @@ -728,7 +729,10 @@ void ToolManager::ReadConfig() #endif // Read in all the settings - gPrefs->Read( wxT("Dock"), &dock, -1); + gPrefs->Read( wxT("Dock"), &dock, -1); // legacy version of DockV2 + if (dock == -1) + gPrefs->Read( wxT("DockV2"), &dock, -1); + const bool found = (dock != -1); if (found) someFound = true; @@ -808,6 +812,9 @@ void ToolManager::ReadConfig() } } #endif + // make a note of docked and hidden toolbars + if (!show[ndx]) + dockedAndHidden.push_back(bar); if (!ordered) { @@ -917,6 +924,13 @@ void ToolManager::ReadConfig() } } + // hidden docked toolbars + for (auto bar : dockedAndHidden) { + bar->SetVisible(false ); + bar->GetDock()->Dock(bar, false); + bar->Expose(false); + } + // Restore original config path gPrefs->SetPath( oldpath ); @@ -958,8 +972,12 @@ void ToolManager::WriteConfig() bool bo = mBotDock->GetConfiguration().Contains( bar ); // Save - gPrefs->Write( wxT("Dock"), (int) (to ? TopDockID : bo ? BotDockID : NoDockID )); - auto dock = to ? mTopDock : bo ? mBotDock : nullptr; + 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. + + dock = to ? mTopDock : bo ? mBotDock : nullptr; // dock for shown toolbars ToolBarConfiguration::Write (dock ? &dock->GetConfiguration() : nullptr, bar);