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 e628f8e1c73a1a89befc46793743dff71987b947 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed Mar 12 17:30:33 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Mar 20 14:33:08 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 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183035 Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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 433cd5091f31..9260438ad62c 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["any"]; 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 805514a7871f..313a7323e665 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -361,8 +361,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(); } } @@ -549,8 +553,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); @@ -558,11 +564,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;