comphelper/source/misc/sequenceashashmap.cxx | 3 + include/comphelper/JsonToPropertyValues_with_boost.hxx | 28 +++++++++++++++++ include/sfx2/lokhelper.hxx | 4 ++ sd/source/ui/view/drviews2.cxx | 4 ++ sfx2/source/view/lokhelper.cxx | 28 +++++++++++++++++ sw/source/uibase/shells/textsh1.cxx | 4 ++ 6 files changed, 70 insertions(+), 1 deletion(-)
New commits: commit 2f157a9eac2fab72af4b8019c9d10b4f3be1aa50 Author: Mike Kaganski <[email protected]> AuthorDate: Mon Oct 6 18:10:53 2025 +0500 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Oct 13 08:50:33 2025 +0200 LOK Transform API: add generic UnoCommand command There already was UnoCommand support inside SlideCommands. This change introduces it at top level. The syntax of the command is: {"UnoCommand": { "name": ".uno:Foo", "arguments": { "Arg1": { "type": "long", "value": 0 }, "Arg2": { "type": "long", "value": 1 } } }} Change-Id: I0015e937495ad1ae756c5366b555a3b0d5fb09ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192001 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/comphelper/source/misc/sequenceashashmap.cxx b/comphelper/source/misc/sequenceashashmap.cxx index 46a23db43ba9..7c3c99016912 100644 --- a/comphelper/source/misc/sequenceashashmap.cxx +++ b/comphelper/source/misc/sequenceashashmap.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/reflection/XIdlField.hpp> #include <com/sun/star/reflection/theCoreReflection.hpp> +#include <comphelper/JsonToPropertyValues_with_boost.hxx> #include <comphelper/sequenceashashmap.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> @@ -302,7 +303,7 @@ void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate) } } -static std::vector<css::beans::PropertyValue> JsonToPropertyValues(const boost::property_tree::ptree& aTree) +std::vector<css::beans::PropertyValue> JsonToPropertyValues(const boost::property_tree::ptree& aTree) { std::vector<beans::PropertyValue> aArguments; boost::property_tree::ptree aNodeNull, aNodeValue; diff --git a/include/comphelper/JsonToPropertyValues_with_boost.hxx b/include/comphelper/JsonToPropertyValues_with_boost.hxx new file mode 100644 index 000000000000..2c67cc8f3a77 --- /dev/null +++ b/include/comphelper/JsonToPropertyValues_with_boost.hxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sal/config.h> + +#include <vector> + +#include <boost/property_tree/ptree_fwd.hpp> + +#include <com/sun/star/beans/PropertyValue.hpp> + +#include <comphelper/comphelperdllapi.h> + +namespace comphelper +{ +COMPHELPER_DLLPUBLIC std::vector<css::beans::PropertyValue> +JsonToPropertyValues(const boost::property_tree::ptree& rJson); +} // namespace comphelper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 099c45025328..ab8dc309afa1 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -30,6 +30,8 @@ #include <string_view> #include <unordered_map> +#include <boost/property_tree/ptree_fwd.hpp> + #define LOK_NOTIFY_LOG_TO_CLIENT 1 #define LOK_LOG_STREAM(level, area, stream) \ @@ -270,6 +272,8 @@ public: /// Registers function pointers in comphelper/ to set/get of the current LOK view. static void registerViewCallbacks(); + static void dispatchUnoCommand(const boost::property_tree::ptree& tree); + private: static int createView(SfxViewFrame& rViewFrame, ViewShellDocId docId); }; diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 1c64ad96806b..b2affde7eafe 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -1372,6 +1372,10 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) } } } + else if (aItem.first == "UnoCommand") + { + SfxLokHelper::dispatchUnoCommand(aItem.second); + } } rReq.Done(); } diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index f554ae32daad..4512b0ad4a57 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -16,13 +16,18 @@ #include <sfx2/lokcomponenthelpers.hxx> #include <sfx2/lokhelper.hxx> +#include <sfx2/lokunocmdlist.hxx> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/ui/ContextChangeEventObject.hpp> #include <com/sun/star/xml/crypto/SEInitializer.hpp> #include <com/sun/star/xml/crypto/XCertificateCreator.hpp> +#include <comphelper/dispatchcommand.hxx> +#include <comphelper/JsonToPropertyValues_with_boost.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/sequence.hxx> #include <o3tl/string_view.hxx> #include <rtl/strbuf.hxx> #include <vcl/lok.hxx> @@ -1190,6 +1195,29 @@ void SfxLokHelper::registerViewCallbacks() }); } +void SfxLokHelper::dispatchUnoCommand(const boost::property_tree::ptree& tree) +{ + auto command = OStringToOUString(tree.get_child("name").get_value<std::string>(), + RTL_TEXTENCODING_UTF8); + // Check if the uno command is allowed + if (std::u16string_view rest; + !command.startsWith(".uno:", &rest) || !GetKitUnoCommandList().contains(rest)) + { + LOK_WARN("lok.transform", + "UnoCommand command is not recognized: '" << command << "'"); + return; + } + std::vector<beans::PropertyValue> arguments; + if (auto args = tree.get_child_optional("arguments")) + { + arguments = comphelper::JsonToPropertyValues(*args); + } + // Make the uno command synchron + arguments.push_back(comphelper::makePropertyValue(u"SynchronMode"_ustr, true)); + + comphelper::dispatchCommand(command, comphelper::containerToSequence(arguments)); +} + namespace { struct LOKAsyncEventData diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index d79da729e054..32d6127576ea 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -3552,6 +3552,10 @@ void SwTextShell::Execute(SfxRequest &rReq) } } } + else if (aItem.first == "UnoCommand") + { + SfxLokHelper::dispatchUnoCommand(aItem.second); + } } } break;
