diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-06-17 14:45:34 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-06-18 05:26:41 +0200 |
commit | ca364f8f16f0c64589d15e7bc44fe6eaebe8f5b2 (patch) | |
tree | 0b3e27e886d6e8b5e5b14ff929ce569ca83ff38b | |
parent | 008c3049b8aaaf3d40675bddc31b0198493fa761 (diff) |
tdf#159835 sfx2: Simplify TabBar::OnToolboxClicked
Now that the logic from `SidebarController::PopulatePopupMenus`
has been moved here in
Change-Id: I8236f2467239e6a2f485d468656e961478eeb09c
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Mon Jun 17 13:35:12 2024 +0200
tdf#159835 sfx2: Move logic to populate sidebar menus to TabBar
as well, simplify `TabBar::OnToolboxClicked`:
No longer use one loop to build a vector of entries
and another to process these, but use a single loop
for that instead.
Drop the now unused `DeckMenuData` class.
Change-Id: I884f3b70bb4d85b9a52421e9de6042cda80cfa0b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169006
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
-rw-r--r-- | include/sfx2/sidebar/TabBar.hxx | 12 | ||||
-rw-r--r-- | sfx2/source/sidebar/TabBar.cxx | 48 |
2 files changed, 20 insertions, 40 deletions
diff --git a/include/sfx2/sidebar/TabBar.hxx b/include/sfx2/sidebar/TabBar.hxx index 54d018aae018..bc2b2a4e4d04 100644 --- a/include/sfx2/sidebar/TabBar.hxx +++ b/include/sfx2/sidebar/TabBar.hxx @@ -41,18 +41,6 @@ class TabBar final : public InterimItemWindow { friend class TabBarUIObject; public: - /** DeckMenuData has entries for display name, and a flag: - - isCurrentDeck for the deck selection data - - isEnabled for the show/hide menu - */ - class DeckMenuData - { - public: - OUString msDisplayName; - bool mbIsCurrentDeck; - bool mbIsActive; - bool mbIsEnabled; - }; typedef ::std::function<void ( weld::Menu& rMainMenu, weld::Menu& rSubMenu)> PopupMenuSignalConnectFunction; TabBar ( diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx index bb5ec5471f9b..d9608e36d49f 100644 --- a/sfx2/source/sidebar/TabBar.cxx +++ b/sfx2/source/sidebar/TabBar.cxx @@ -334,23 +334,6 @@ IMPL_LINK_NOARG(TabBar, OnToolboxClicked, weld::Toggleable&, void) if (!mxMenuButton->get_active()) return; - std::vector<DeckMenuData> aMenuData; - - for (auto const& item : maItems) - { - std::shared_ptr<DeckDescriptor> xDeckDescriptor = mrParentSidebarController.GetResourceManager()->GetDeckDescriptor(item->msDeckId); - - if (!xDeckDescriptor) - continue; - - DeckMenuData aData; - aData.msDisplayName = xDeckDescriptor->msTitle; - aData.mbIsCurrentDeck = item->mxButton->get_item_active(u"toggle"_ustr); - aData.mbIsActive = !item->mbIsHidden; - aData.mbIsEnabled = item->mxButton->get_sensitive(); - aMenuData.push_back(aData); - } - for (int i = mxMainMenu->n_children() - 1; i >= 0; --i) { OUString sIdent = mxMainMenu->get_id(i); @@ -367,30 +350,39 @@ IMPL_LINK_NOARG(TabBar, OnToolboxClicked, weld::Toggleable&, void) // Add one entry for every tool panel element to individually make // them visible or hide them. sal_Int32 nIndex (0); - for (const auto& rItem : aMenuData) + for (auto const& rItem : maItems) { + std::shared_ptr<DeckDescriptor> xDeckDescriptor + = mrParentSidebarController.GetResourceManager()->GetDeckDescriptor(rItem->msDeckId); + + if (!xDeckDescriptor) + continue; + + const OUString sDisplayName = xDeckDescriptor->msTitle; OUString sIdent("select" + OUString::number(nIndex)); - mxMainMenu->insert(nIndex, sIdent, rItem.msDisplayName, - nullptr, nullptr, nullptr, TRISTATE_FALSE); - mxMainMenu->set_active(sIdent, rItem.mbIsCurrentDeck); - mxMainMenu->set_sensitive(sIdent, rItem.mbIsEnabled && rItem.mbIsActive); + const bool bCurrentDeck = rItem->mxButton->get_item_active(u"toggle"_ustr); + const bool bActive = !rItem->mbIsHidden; + const bool bEnabled = rItem->mxButton->get_sensitive(); + mxMainMenu->insert(nIndex, sIdent, sDisplayName, nullptr, nullptr, nullptr, TRISTATE_FALSE); + mxMainMenu->set_active(sIdent, bCurrentDeck); + mxMainMenu->set_sensitive(sIdent, bEnabled && bActive); if (!comphelper::LibreOfficeKit::isActive()) { - if (rItem.mbIsCurrentDeck) + if (bCurrentDeck) { // Don't allow the currently visible deck to be disabled. OUString sSubIdent("nocustomize" + OUString::number(nIndex)); - mxSubMenu->insert(nIndex, sSubIdent, rItem.msDisplayName, - nullptr, nullptr, nullptr, TRISTATE_FALSE); + mxSubMenu->insert(nIndex, sSubIdent, sDisplayName, nullptr, nullptr, nullptr, + TRISTATE_FALSE); mxSubMenu->set_active(sSubIdent, true); } else { OUString sSubIdent("customize" + OUString::number(nIndex)); - mxSubMenu->insert(nIndex, sSubIdent, rItem.msDisplayName, - nullptr, nullptr, nullptr, TRISTATE_TRUE); - mxSubMenu->set_active(sSubIdent, rItem.mbIsEnabled && rItem.mbIsActive); + mxSubMenu->insert(nIndex, sSubIdent, sDisplayName, nullptr, nullptr, nullptr, + TRISTATE_TRUE); + mxSubMenu->set_active(sSubIdent, bEnabled && bActive); } } |