include/sfx2/lokhelper.hxx | 6 ++++++ sfx2/source/view/lokhelper.cxx | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
New commits: commit 2f72fa980c2c81248c32d3b95598c23aba6ac6ed Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Tue Jun 2 11:51:52 2020 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Tue Jul 7 07:46:56 2020 +0200 introduce property-tree versions of SfxLokHelper::notifyOtherView*() Change-Id: I4ebbc166da94eab6e35984c50220dde7daf7adde Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98119 Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 3c3cfc3a2ef8..68d029ea5ddf 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -39,6 +39,8 @@ struct SFX2_DLLPUBLIC LokMouseEventData {} }; +#include <boost/property_tree/ptree_fwd.hpp> + class SFX2_DLLPUBLIC SfxLokHelper { public: @@ -75,8 +77,12 @@ public: static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType f); /// Invoke the LOK callback of all other views showing the same document as pThisView, with a payload of rKey-rPayload. static void notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload); + /// Invoke the LOK callback of all views except pThisView, with a JSON payload created from the given property tree. + static void notifyOtherViews(SfxViewShell* pThisView, int nType, const boost::property_tree::ptree& rTree); /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them. static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const OString& rKey, const OString& rPayload); + /// Same as notifyOtherViews(), the property-tree version, but works on a selected "other" view, not on all of them. + static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const boost::property_tree::ptree& rTree); /// Emits a LOK_CALLBACK_STATE_CHANGED static void sendUnoStatus(const SfxViewShell* pShell, const SfxPoolItem* pItem); /// Emits a LOK_CALLBACK_WINDOW diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index af7b75a26897..67097c444990 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -291,6 +291,16 @@ static OString lcl_escapeQuotes(const OString &rStr) return aBuf.makeStringAndClear(); } +static OString lcl_generateJSON(SfxViewShell* pView, const boost::property_tree::ptree& rTree) +{ + boost::property_tree::ptree aMessageProps = rTree; + aMessageProps.put("viewId", SfxLokHelper::getView(pView)); + aMessageProps.put("part", pView->getPart()); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aMessageProps, false /* pretty */); + return OString(aStream.str().c_str()).trim(); +} + void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const OString& rKey, const OString& rPayload) { if (DisableCallbacks::disabled()) @@ -303,6 +313,15 @@ void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr()); } +void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, + const boost::property_tree::ptree& rTree) +{ + if (DisableCallbacks::disabled()) + return; + + pOtherView->libreOfficeKitViewCallback(nType, lcl_generateJSON(pThisView, rTree).getStr()); +} + void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload) { if (DisableCallbacks::disabled()) @@ -318,6 +337,24 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS } } +void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const boost::property_tree::ptree& rTree) +{ + if (SfxLokHelper::getViewsCount() <= 1 || DisableCallbacks::disabled()) + return; + + // Payload is only dependent on pThisView. + OString aPayload = lcl_generateJSON(pThisView, rTree); + + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + if (pViewShell != pThisView) + pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr()); + + pViewShell = SfxViewShell::GetNext(*pViewShell); + } +} + namespace { OUString lcl_getNameForSlot(const SfxViewShell* pShell, sal_uInt16 nWhich) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits