include/sfx2/sidebar/SidebarController.hxx |   12 +----
 include/sfx2/sidebar/TabBar.hxx            |    7 +--
 sfx2/source/sidebar/SidebarController.cxx  |   64 +----------------------------
 sfx2/source/sidebar/TabBar.cxx             |   56 ++++++++++++++++++++++++-
 4 files changed, 64 insertions(+), 75 deletions(-)

New commits:
commit 4cd1c580a7eb20ab36623295c35c49cb63a0ee65
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Jun 17 13:35:12 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 27 16:41:21 2024 +0200

    tdf#159835 sfx2: Move logic to populate sidebar menus to TabBar
    
    Move the logic to populate the menus from
    `SidebarController::PopulatePopupMenus` (called
    by `SidebarController::ShowPopupMenu`) to
    `TabBar::OnToolboxClicked`. The latter called
    `SidebarController::ShowPopupMenu`.
    (In a first step, take over the existing implementation
    but leave further changes for following commits.)
    
    `TabBar::OnToolboxClicked` already collects all the deck
    data relevant for the menus and the menus are members of that
    class, so it seems more straighforward to populate
    the menus there right away.
    The only information needed from `SidebarController`
    is whether the sidebar is docked or not, so add a
    new method `SidebarController::IsDocked` to retrieve that
    information.
    
    Rename `SidebarController::ShowPopupMenu` to
    `SidebarController::ConnectMenuActivateHandlers` as
    it only connects the signals now, and rename
    `PopupMenuProvider` to `PopupMenuSignalConnectFunction`
    accordingly.
    
    This commit does some refactoring in preparation of
    fixing tdf#159835, no change in behavior intended (yet).
    
    Change-Id: I8236f2467239e6a2f485d468656e961478eeb09c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169005
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins
    (cherry picked from commit 008c3049b8aaaf3d40675bddc31b0198493fa761)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169245
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/include/sfx2/sidebar/SidebarController.hxx 
b/include/sfx2/sidebar/SidebarController.hxx
index 06e092bceec8..63fc4435848f 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -113,6 +113,8 @@ public:
     const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02;
     const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02;
 
+    bool IsDocked() const;
+
     void OpenThenSwitchToDeck(std::u16string_view rsDeckId);
     void OpenThenToggleDeck(const OUString& rsDeckId);
 
@@ -251,14 +253,8 @@ private:
         const DeckDescriptor& rDeckDescriptor,
         const Context& rContext);
 
-    void ShowPopupMenu (
-        weld::Menu& rMainMenu,
-        weld::Menu& rSubMenu,
-        const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
-    void PopulatePopupMenus(
-        weld::Menu& rMainButton,
-        weld::Menu& rSubMenu,
-        const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
+    void ConnectMenuActivateHandlers(weld::Menu& rMainMenu, weld::Menu& 
rSubMenu) const;
+
     DECL_DLLPRIVATE_LINK(OnMenuItemSelected, const OUString&, void);
     DECL_DLLPRIVATE_LINK(OnSubMenuItemSelected, const OUString&, void);
     void BroadcastPropertyChange();
diff --git a/include/sfx2/sidebar/TabBar.hxx b/include/sfx2/sidebar/TabBar.hxx
index bb7e48f3cd51..765dffc1435f 100644
--- a/include/sfx2/sidebar/TabBar.hxx
+++ b/include/sfx2/sidebar/TabBar.hxx
@@ -54,13 +54,12 @@ public:
         bool mbIsEnabled;
     };
     typedef ::std::function<void (
-            weld::Menu& rMainMenu, weld::Menu& rSubMenu,
-            const ::std::vector<DeckMenuData>& rMenuData)> PopupMenuProvider;
+            weld::Menu& rMainMenu, weld::Menu& rSubMenu)> 
PopupMenuSignalConnectFunction;
     TabBar (
         vcl::Window* pParentWindow,
         const css::uno::Reference<css::frame::XFrame>& rxFrame,
         ::std::function<void (const OUString& rsDeckId)> 
aDeckActivationFunctor,
-        PopupMenuProvider aPopupMenuProvider,
+        PopupMenuSignalConnectFunction aPopupMenuSignalConnectFunction,
         SidebarController& rParentSidebarController);
 
     weld::Container* GetContainer() { return m_xContainer.get(); }
@@ -119,7 +118,7 @@ private:
     typedef ::std::vector<std::unique_ptr<Item>> ItemContainer;
     ItemContainer maItems;
     const ::std::function<void (const OUString& rsDeckId)> 
maDeckActivationFunctor;
-    PopupMenuProvider maPopupMenuProvider;
+    PopupMenuSignalConnectFunction maPopupMenuSignalConnectFunction;
 
     void CreateTabItem(weld::Toolbar& rButton, const DeckDescriptor& 
rDeckDescriptor);
     css::uno::Reference<css::graphic::XGraphic> GetItemImage(const 
DeckDescriptor& rDeskDescriptor) const;
diff --git a/sfx2/source/sidebar/SidebarController.cxx 
b/sfx2/source/sidebar/SidebarController.cxx
index d7234553e86a..ce02e434833c 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -117,8 +117,7 @@ SidebarController::SidebarController (
               mpParentWindow,
               mxFrame,
               [this](const OUString& rsDeckId) { return 
this->OpenThenToggleDeck(rsDeckId); },
-              [this](weld::Menu& rMainMenu, weld::Menu& rSubMenu,
-                     const ::std::vector<TabBar::DeckMenuData>& rMenuData) { 
return this->ShowPopupMenu(rMainMenu, rSubMenu, rMenuData); },
+              [this](weld::Menu& rMainMenu, weld::Menu& rSubMenu) { return 
this->ConnectMenuActivateHandlers(rMainMenu, rSubMenu); },
               *this)),
       maCurrentContext(OUString(), OUString()),
       maRequestedContext(OUString(), OUString()),
@@ -623,6 +622,8 @@ void collectUIInformation(const OUString& rDeckId)
 
 }
 
+bool SidebarController::IsDocked() const { return 
!mpParentWindow->IsFloatingMode(); }
+
 void SidebarController::OpenThenToggleDeck (
     const OUString& rsDeckId)
 {
@@ -1083,69 +1084,12 @@ IMPL_LINK(SidebarController, WindowEventHandler, 
VclWindowEvent&, rEvent, void)
     }
 }
 
-void SidebarController::ShowPopupMenu(
-    weld::Menu& rMainMenu, weld::Menu& rSubMenu,
-    const ::std::vector<TabBar::DeckMenuData>& rMenuData) const
+void SidebarController::ConnectMenuActivateHandlers(weld::Menu& rMainMenu, 
weld::Menu& rSubMenu) const
 {
-    PopulatePopupMenus(rMainMenu, rSubMenu, rMenuData);
     rMainMenu.connect_activate(LINK(const_cast<SidebarController*>(this), 
SidebarController, OnMenuItemSelected));
     rSubMenu.connect_activate(LINK(const_cast<SidebarController*>(this), 
SidebarController, OnSubMenuItemSelected));
 }
 
-void SidebarController::PopulatePopupMenus(weld::Menu& rMenu, weld::Menu& 
rCustomizationMenu,
-                                           const 
std::vector<TabBar::DeckMenuData>& rMenuData) const
-{
-    // Add one entry for every tool panel element to individually make
-    // them visible or hide them.
-    sal_Int32 nIndex (0);
-    for (const auto& rItem : rMenuData)
-    {
-        OUString sIdent("select" + OUString::number(nIndex));
-        rMenu.insert(nIndex, sIdent, rItem.msDisplayName,
-                     nullptr, nullptr, nullptr, TRISTATE_FALSE);
-        rMenu.set_active(sIdent, rItem.mbIsCurrentDeck);
-        rMenu.set_sensitive(sIdent, rItem.mbIsEnabled && rItem.mbIsActive);
-
-        if (!comphelper::LibreOfficeKit::isActive())
-        {
-            if (rItem.mbIsCurrentDeck)
-            {
-                // Don't allow the currently visible deck to be disabled.
-                OUString sSubIdent("nocustomize" + OUString::number(nIndex));
-                rCustomizationMenu.insert(nIndex, sSubIdent, 
rItem.msDisplayName,
-                                          nullptr, nullptr, nullptr, 
TRISTATE_FALSE);
-                rCustomizationMenu.set_active(sSubIdent, true);
-            }
-            else
-            {
-                OUString sSubIdent("customize" + OUString::number(nIndex));
-                rCustomizationMenu.insert(nIndex, sSubIdent, 
rItem.msDisplayName,
-                                          nullptr, nullptr, nullptr, 
TRISTATE_TRUE);
-                rCustomizationMenu.set_active(sSubIdent, rItem.mbIsEnabled && 
rItem.mbIsActive);
-            }
-        }
-
-        ++nIndex;
-    }
-
-    bool bHideLock = true;
-    bool bHideUnLock = true;
-    // LOK doesn't support docked/undocked; Sidebar is floating but rendered 
docked in browser.
-    if (!comphelper::LibreOfficeKit::isActive())
-    {
-        // Add entry for docking or un-docking the tool panel.
-        if (mpParentWindow->IsFloatingMode())
-            bHideLock = false;
-        else
-            bHideUnLock = false;
-    }
-    rMenu.set_visible("locktaskpanel", !bHideLock);
-    rMenu.set_visible("unlocktaskpanel", !bHideUnLock);
-
-    // No Restore or Customize options for LoKit.
-    rMenu.set_visible("customization", 
!comphelper::LibreOfficeKit::isActive());
-}
-
 IMPL_LINK(SidebarController, OnMenuItemSelected, const OUString&, rCurItemId, 
void)
 {
     if (rCurItemId == "unlocktaskpanel")
diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx
index ffc6959e3904..b764964012c0 100644
--- a/sfx2/source/sidebar/TabBar.cxx
+++ b/sfx2/source/sidebar/TabBar.cxx
@@ -47,7 +47,7 @@ namespace sfx2::sidebar {
 TabBar::TabBar(vcl::Window* pParentWindow,
                const Reference<frame::XFrame>& rxFrame,
                std::function<void (const OUString&)> aDeckActivationFunctor,
-               PopupMenuProvider  aPopupMenuProvider,
+               PopupMenuSignalConnectFunction aPopupMenuSignalConnectFunction,
                SidebarController& rParentSidebarController
               )
     : InterimItemWindow(pParentWindow, "sfx/ui/tabbar.ui", "TabBar")
@@ -57,7 +57,7 @@ TabBar::TabBar(vcl::Window* pParentWindow,
     , mxContents(mxAuxBuilder->weld_widget("TabBarContents"))
     , mxMeasureBox(mxAuxBuilder->weld_widget("measure"))
     , maDeckActivationFunctor(std::move(aDeckActivationFunctor))
-    , maPopupMenuProvider(std::move(aPopupMenuProvider))
+    , 
maPopupMenuSignalConnectFunction(std::move(aPopupMenuSignalConnectFunction))
     , mrParentSidebarController(rParentSidebarController)
 {
     set_id("TabBar"); // for uitest
@@ -374,7 +374,57 @@ IMPL_LINK_NOARG(TabBar, OnToolboxClicked, 
weld::Toggleable&, void)
             mxSubMenu->remove(sIdent);
     }
 
-    maPopupMenuProvider(*mxMainMenu, *mxSubMenu, aMenuData);
+    // 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)
+    {
+        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);
+
+        if (!comphelper::LibreOfficeKit::isActive())
+        {
+            if (rItem.mbIsCurrentDeck)
+            {
+                // 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->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);
+            }
+        }
+
+        ++nIndex;
+    }
+
+    bool bHideLock = true;
+    bool bHideUnLock = true;
+    // LOK doesn't support docked/undocked; Sidebar is floating but rendered 
docked in browser.
+    if (!comphelper::LibreOfficeKit::isActive())
+    {
+        // Add entry for docking or un-docking the tool panel.
+        if (!mrParentSidebarController.IsDocked())
+            bHideLock = false;
+        else
+            bHideUnLock = false;
+    }
+    mxMainMenu->set_visible("locktaskpanel", !bHideLock);
+    mxMainMenu->set_visible("unlocktaskpanel", !bHideUnLock);
+
+    // No Restore or Customize options for LoKit.
+    mxMainMenu->set_visible("customization", 
!comphelper::LibreOfficeKit::isActive());
+
+    maPopupMenuSignalConnectFunction(*mxMainMenu, *mxSubMenu);
 }
 
 void TabBar::EnableMenuButton(const bool bEnable)

Reply via email to