include/sfx2/sidebar/ResourceManager.hxx  |    9 ++++++++
 sfx2/source/sidebar/ResourceManager.cxx   |   24 ++++++++++++++++++---
 sfx2/source/sidebar/SidebarController.cxx |   33 ++++++++++++++++++++++--------
 3 files changed, 54 insertions(+), 12 deletions(-)

New commits:
commit 026c26ff143628ab61ebb84abd87069f500f8fca
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Mar 12 17:30:33 2025 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Mar 20 08:44:52 2025 +0100

    lok: sidebar: do not remember last active
    
    It is done in lok client, do not introduce
    additional state in core part.
    
    Also config modification is costly so good to avoid.
    
    There was rule to always open ElementsDeck in Formula context.
    Move it to a dedicated map with overrides.
    
    We need to not skip context updates when enters OLE second time.
    Introduced in commit 81055959e06848c917c4df1e4f19e1e5c6e70684
    lok: Avoid redundant call to UpdateConfigurations
    But it has negative performance impact - causing to switch decks
    on every key press when 2 users are typing.
    
    Signed-off-by: Szymon Kłos <szymon.k...@collabora.com>
    Change-Id: Ie20181db013a2b7ea1cbb8245b301e55260b8c0d
    (cherry picked from commit f0e226a0057cbbb8904bd8046febf31f7c65d936)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183123
    Tested-by: Jenkins

diff --git a/include/sfx2/sidebar/ResourceManager.hxx 
b/include/sfx2/sidebar/ResourceManager.hxx
index 9ac1130cc29b..c3ea9abbc940 100644
--- a/include/sfx2/sidebar/ResourceManager.hxx
+++ b/include/sfx2/sidebar/ResourceManager.hxx
@@ -20,6 +20,7 @@
 
 #include <unotools/confignode.hxx>
 #include <map>
+#include <vcl/EnumContext.hxx>
 #include <vector>
 #include <set>
 
@@ -89,6 +90,11 @@ public:
                                             const 
css::uno::Reference<css::frame::XController>& rxController);
 
     const OUString& GetLastActiveDeck( const Context& rContext );
+    const std::map<OUString, OUString>& GetDeckOverrides() {
+        if (maApplicationDeckOverrides.empty())
+            SetupOverrides();
+        return maApplicationDeckOverrides;
+    }
     void SetLastActiveDeck( const Context& rContext, const OUString& rsDeckId 
);
 
     /** Remember the expansions state per panel and context.
@@ -107,10 +113,13 @@ private:
     PanelContainer maPanels;
     mutable std::set<OUString> maProcessedApplications;
     std::map<OUString, OUString> maLastActiveDecks;
+    // always jump to Deck on Application type, override last used
+    std::map<OUString, OUString> maApplicationDeckOverrides;
 
     void ReadDeckList();
     void ReadPanelList();
     void ReadLastActive();
+    void SetupOverrides();
     static void ReadContextList(const utl::OConfigurationNode& rNode,
                          ContextList& rContextList,
                          const OUString& rsDefaultMenuCommand);
diff --git a/sfx2/source/sidebar/ResourceManager.cxx 
b/sfx2/source/sidebar/ResourceManager.cxx
index 794e906f6a28..2450332bfc0e 100644
--- a/sfx2/source/sidebar/ResourceManager.cxx
+++ b/sfx2/source/sidebar/ResourceManager.cxx
@@ -33,7 +33,6 @@
 
 #include <comphelper/diagnose_ex.hxx>
 #include <sal/log.hxx>
-#include <vcl/EnumContext.hxx>
 #include <o3tl/string_view.hxx>
 
 #include <com/sun/star/frame/ModuleManager.hpp>
@@ -237,6 +236,7 @@ const ResourceManager::PanelContextDescriptorContainer& 
ResourceManager::GetMatc
 
 const OUString& ResourceManager::GetLastActiveDeck( const Context& rContext )
 {
+    assert(!comphelper::LibreOfficeKit::isActive());
     if( maLastActiveDecks.find( rContext.msApplication ) == 
maLastActiveDecks.end())
         return maLastActiveDecks[u"any"_ustr];
     else
@@ -245,6 +245,7 @@ const OUString& ResourceManager::GetLastActiveDeck( const 
Context& rContext )
 
 void ResourceManager::SetLastActiveDeck( const Context& rContext, const 
OUString &rsDeckId )
 {
+    assert(!comphelper::LibreOfficeKit::isActive());
     maLastActiveDecks[rContext.msApplication] = rsDeckId;
 }
 
@@ -299,6 +300,9 @@ void ResourceManager::ReadDeckList()
 
 void ResourceManager::SaveDecksSettings(const Context& rContext)
 {
+    if (comphelper::LibreOfficeKit::isActive())
+        return;
+
     for (auto const& deck : maDecks)
     {
        const ContextList::Entry* pMatchingEntry = 
deck->maContextList.GetMatch(rContext);
@@ -403,6 +407,9 @@ void ResourceManager::SaveDeckSettings(const 
DeckDescriptor* pDeckDesc)
 
 void ResourceManager::SaveLastActiveDeck(const Context& rContext, const 
OUString& rActiveDeck)
 {
+    if (comphelper::LibreOfficeKit::isActive())
+        return;
+
     maLastActiveDecks[rContext.msApplication] = rActiveDeck;
 
     std::set<OUString> aLastActiveDecks;
@@ -467,6 +474,9 @@ void ResourceManager::ReadPanelList()
 
 void ResourceManager::ReadLastActive()
 {
+    if (comphelper::LibreOfficeKit::isActive())
+        return;
+
     const Sequence <OUString> aLastActive 
(officecfg::Office::UI::Sidebar::Content::LastActiveDeck::get());
 
     for (const auto& rDeckInfo : aLastActive)
@@ -488,9 +498,15 @@ void ResourceManager::ReadLastActive()
     }
 
     // Set up a default for Math - will do nothing if already set
-    maLastActiveDecks.emplace(
-        
vcl::EnumContext::GetApplicationName(vcl::EnumContext::Application::Formula),
-        "ElementsDeck");
+    for (const auto& aOverrideDeck : GetDeckOverrides())
+        maLastActiveDecks.emplace(aOverrideDeck.first, aOverrideDeck.second);
+}
+
+void ResourceManager::SetupOverrides()
+{
+    maApplicationDeckOverrides = {
+        { 
vcl::EnumContext::GetApplicationName(vcl::EnumContext::Application::Formula), 
"ElementsDeck" }
+    };
 }
 
 void ResourceManager::ReadContextList (
diff --git a/sfx2/source/sidebar/SidebarController.cxx 
b/sfx2/source/sidebar/SidebarController.cxx
index 11c3150b8c33..1924856e1e4e 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -362,8 +362,12 @@ void SAL_CALL SidebarController::notifyContextChangeEvent 
(const css::ui::Contex
         maContextChangeUpdate.RequestCall(); // async call, not a prob
                                              // calling with held
                                              // solarmutex
-        // TODO: this call is redundant but mandatory for unit test to update 
context on document loading
-        if (!comphelper::LibreOfficeKit::isActive())
+
+        bool bSwitchedApp = maRequestedContext.msApplication != 
maCurrentContext.msApplication;
+        // Happens on reattach of sidebar to frame or context change
+        // LOK performance impact: prevents to switch sidebar on every 
keypress in multi user case
+        // Allow when enters embedded OLE (eg. Math formula editor second time)
+        if (!comphelper::LibreOfficeKit::isActive() || bSwitchedApp)
             UpdateConfigurations();
     }
 }
@@ -550,8 +554,10 @@ void SidebarController::UpdateConfigurations()
         && mnRequestedForceFlags == SwitchFlag_NoForce)
         return;
 
-    if ((maCurrentContext.msApplication != "none") &&
-            !maCurrentContext.msApplication.isEmpty())
+    bool bIsLOK = comphelper::LibreOfficeKit::isActive();
+
+    if (!bIsLOK && maCurrentContext.msApplication != "none" &&
+        !maCurrentContext.msApplication.isEmpty())
     {
         mpResourceManager->SaveDecksSettings(maCurrentContext);
         mpResourceManager->SetLastActiveDeck(maCurrentContext, 
msCurrentDeckId);
@@ -559,11 +565,22 @@ void SidebarController::UpdateConfigurations()
 
     // get last active deck for this application on first update
     if (!maRequestedContext.msApplication.isEmpty() &&
-            (maCurrentContext.msApplication != 
maRequestedContext.msApplication))
+        (maCurrentContext.msApplication != maRequestedContext.msApplication))
     {
-        OUString sLastActiveDeck = mpResourceManager->GetLastActiveDeck( 
maRequestedContext );
-        if (!sLastActiveDeck.isEmpty())
-            msCurrentDeckId = sLastActiveDeck;
+        if (bIsLOK)
+        {
+            // LOK has no last-used memory
+            const auto& rOverrides = mpResourceManager->GetDeckOverrides();
+            const auto aOverride = 
rOverrides.find(maRequestedContext.msApplication);
+            if (aOverride != rOverrides.end())
+                msCurrentDeckId = aOverride->second;
+        }
+        else
+        {
+            OUString sLastActiveDeck = mpResourceManager->GetLastActiveDeck( 
maRequestedContext );
+            if (!sLastActiveDeck.isEmpty())
+                msCurrentDeckId = sLastActiveDeck;
+        }
     }
 
     maCurrentContext = maRequestedContext;

Reply via email to