From 0d9d0ca83fc072979ffda84d993055f44793d05d Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 11 Aug 2022 15:08:01 +0300 Subject: lok: Simplify context change notification Change-Id: I3ead4deb5bdfe638bc49e05bfba0d8c630687958 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138141 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/sfx2/lokhelper.hxx | 4 +++- sfx2/source/sidebar/ContextChangeBroadcaster.cxx | 13 ++++++------- sfx2/source/view/lokhelper.cxx | 11 ++++++++--- svx/source/sidebar/ContextChangeEventMultiplexer.cxx | 3 +-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 0b18c0fa7b5e..909b6335733d 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -44,6 +44,8 @@ struct SFX2_DLLPUBLIC LokMouseEventData #include +namespace com::sun::star::ui { struct ContextChangeEventObject; }; + class SFX2_DLLPUBLIC SfxLokHelper { public: @@ -115,7 +117,7 @@ public: static void notifyAllViews(int nType, const OString& rPayload); /// Notify about the editing context change. - static void notifyContextChange(SfxViewShell const* pViewShell, const OUString& aApplication, const OUString& aContext); + static void notifyContextChange(const css::ui::ContextChangeEventObject& rEvent); // Notify about the given type needing an update. static void notifyUpdate(SfxViewShell const* pViewShell, int nType); diff --git a/sfx2/source/sidebar/ContextChangeBroadcaster.cxx b/sfx2/source/sidebar/ContextChangeBroadcaster.cxx index 0350929eedf1..d2d55b700fbc 100644 --- a/sfx2/source/sidebar/ContextChangeBroadcaster.cxx +++ b/sfx2/source/sidebar/ContextChangeBroadcaster.cxx @@ -86,18 +86,17 @@ void ContextChangeBroadcaster::BroadcastContextChange ( return; } - // notify the LOK too - if (comphelper::LibreOfficeKit::isActive()) - { - if (SfxViewShell* pViewShell = SfxViewShell::Get(rxFrame->getController())) - SfxLokHelper::notifyContextChange(pViewShell, rsModuleName, rsContextName); - } - const css::ui::ContextChangeEventObject aEvent( rxFrame->getController(), rsModuleName, rsContextName); + // notify the LOK too + if (comphelper::LibreOfficeKit::isActive()) + { + SfxLokHelper::notifyContextChange(aEvent); + } + css::uno::Reference xMultiplexer ( css::ui::ContextChangeEventMultiplexer::get( ::comphelper::getProcessComponentContext())); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 1d39838bfbf8..aa38c5dbee98 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -608,15 +609,19 @@ void SfxLokHelper::notifyAllViews(int nType, const OString& rPayload) } } -void SfxLokHelper::notifyContextChange(SfxViewShell const* pViewShell, const OUString& aApplication, const OUString& aContext) +void SfxLokHelper::notifyContextChange(const css::ui::ContextChangeEventObject& rEvent) { if (DisableCallbacks::disabled()) return; + SfxViewShell* pViewShell = SfxViewShell::Get({ rEvent.Source, css::uno::UNO_QUERY }); + if (!pViewShell) + return; + OString aBuffer = - OUStringToOString(aApplication.replace(' ', '_'), RTL_TEXTENCODING_UTF8) + + OUStringToOString(rEvent.ApplicationName.replace(' ', '_'), RTL_TEXTENCODING_UTF8) + " " + - OUStringToOString(aContext.replace(' ', '_'), RTL_TEXTENCODING_UTF8); + OUStringToOString(rEvent.ContextName.replace(' ', '_'), RTL_TEXTENCODING_UTF8); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_CHANGED, aBuffer.getStr()); } diff --git a/svx/source/sidebar/ContextChangeEventMultiplexer.cxx b/svx/source/sidebar/ContextChangeEventMultiplexer.cxx index ce552b0ac837..dd44e706aeec 100644 --- a/svx/source/sidebar/ContextChangeEventMultiplexer.cxx +++ b/svx/source/sidebar/ContextChangeEventMultiplexer.cxx @@ -53,8 +53,7 @@ void ContextChangeEventMultiplexer::NotifyContextChange ( // notify the LOK too after all the change have taken effect. if (comphelper::LibreOfficeKit::isActive()) { - if (SfxViewShell* pViewShell = SfxViewShell::Get(rxController)) - SfxLokHelper::notifyContextChange(pViewShell, GetModuleName(rxController->getFrame()), vcl::EnumContext::GetContextName(eContext)); + SfxLokHelper::notifyContextChange(aEvent); } } -- cgit