From 22aa6508e0a65e65a6f9410b498fe4fd6c236639 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 29 Jan 2019 18:01:21 +0100 Subject: framework: allow dispatching a command on the main thread This is similar to commit 2dc3a6c273cb82506842864481d78df7294debbf (framework: allow loading a component on the main thread, 2018-12-19), just it allows saving (via .uno:Save) and other commands operating in a similar environment. The use-case is that once a document is loaded on the main thread (see commit message of the above mentioned commit), then saving also has to happen on the main thread, or OLE objects on Windows may be lost. Change-Id: I7321659550b556e96085ac20f197a87d5d13f1ed Reviewed-on: https://gerrit.libreoffice.org/67089 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- framework/source/services/dispatchhelper.cxx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/framework/source/services/dispatchhelper.cxx b/framework/source/services/dispatchhelper.cxx index 3a1e6166197d..53a55d873249 100644 --- a/framework/source/services/dispatchhelper.cxx +++ b/framework/source/services/dispatchhelper.cxx @@ -26,6 +26,8 @@ #include #include +#include +#include namespace framework{ @@ -47,6 +49,19 @@ DispatchHelper::DispatchHelper( const css::uno::Reference< css::uno::XComponentC { } +/** + * Proxy around DispatchHelper::executeDispatch(), as + * vcl::solarthread::syncExecute() does not seem to accept lambdas. + */ +static css::uno::Any +executeDispatchStatic(DispatchHelper* pThis, + const css::uno::Reference& xDispatch, + const css::util::URL& aURL, bool SyncronFlag, + const css::uno::Sequence& lArguments) +{ + return pThis->executeDispatch(xDispatch, aURL, SyncronFlag, lArguments); +} + /** dtor. */ DispatchHelper::~DispatchHelper() @@ -103,7 +118,14 @@ css::uno::Any SAL_CALL DispatchHelper::executeDispatch( // search dispatcher css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, sTargetFrameName, nSearchFlags); - return executeDispatch(xDispatch, aURL, true, lArguments); + utl::MediaDescriptor aDescriptor(lArguments); + bool bOnMainThread = aDescriptor.getUnpackedValueOrDefault("OnMainThread", false); + + if (bOnMainThread) + return vcl::solarthread::syncExecute( + std::bind(&executeDispatchStatic, this, xDispatch, aURL, true, lArguments)); + else + return executeDispatch(xDispatch, aURL, true, lArguments); } -- cgit