From ef70f2e53de65a49aa8e4077732353d4b4dcec02 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 30 May 2023 07:48:11 +0200 Subject: [PATCH] Gui: Unavailable toolbars default to visible when made available ================================================================ https://github.com/FreeCAD/FreeCAD/issues/9208#issuecomment-1567469254 Issue: - Unavailable toolbars default to not visible (as they are unavailable) - However, when made available, they remain not visible. There may be cases when this is indeed the wanted behaviour, but they are not the ones we are facing. - In the latter, the user expects the toolbars to show (and the configuration file to be saved with all toolbars showing. Solution: - Change the default behaviour of Unavailable toolbars when forcing them to be available, so that they are visible when made available. - If then the case arises that we have toolbars where we would prefer then to be left not visible when making them available (so they are listed in the toolbar context menu to make them visible, but not visible per default), then we would need to create another toolbar policy class "UnavailableHidden". - I chose not to add it directly (although it is straightforward) in fear that we will never need it, and it would make the code more complex to understand and thus maintain. --- src/Gui/ToolBarManager.cpp | 11 ++++++++++- src/Gui/ToolBarManager.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Gui/ToolBarManager.cpp b/src/Gui/ToolBarManager.cpp index 12c3b862cb..210ca41f29 100644 --- a/src/Gui/ToolBarManager.cpp +++ b/src/Gui/ToolBarManager.cpp @@ -536,7 +536,16 @@ void ToolBarManager::setState(const QString& name, State state) tb->toggleViewAction()->setVisible(true); - showhide(tb, policy); + // Unavailable policy defaults to a Visible toolbars when made available + auto show = visibility( policy == ToolBarItem::DefaultVisibility::Visible || + policy == ToolBarItem::DefaultVisibility::Unavailable); + + if(show) { + tb->show(); + } + else { + tb->hide(); + } } else if (state == State::ForceHidden) { tb->toggleViewAction()->setVisible(false); // not visible in context menus diff --git a/src/Gui/ToolBarManager.h b/src/Gui/ToolBarManager.h index 1aa631ea94..a84da34cbc 100644 --- a/src/Gui/ToolBarManager.h +++ b/src/Gui/ToolBarManager.h @@ -44,7 +44,8 @@ public: Hidden, // toolbar hidden by default, visibility toggle action is enabled Unavailable, // toolbar visibility is managed independently by client code and defaults to // hidden, visibility toggle action is disabled by default (it is unavailable - // to the UI). + // to the UI). Upon being forced to be available, these toolbars default to + // visible. }; ToolBarItem();