Kaydet (Commit) 22aa6508 authored tarafından Miklos Vajna's avatar Miklos Vajna

framework: allow dispatching a command on the main thread

This is similar to commit 2dc3a6c2
(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/67089Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst 1554ec84
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <com/sun/star/frame/XNotifyingDispatch.hpp> #include <com/sun/star/frame/XNotifyingDispatch.hpp>
#include <comphelper/profilezone.hxx> #include <comphelper/profilezone.hxx>
#include <unotools/mediadescriptor.hxx>
#include <vcl/threadex.hxx>
namespace framework{ namespace framework{
...@@ -47,6 +49,19 @@ DispatchHelper::DispatchHelper( const css::uno::Reference< css::uno::XComponentC ...@@ -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<css::frame::XDispatch>& xDispatch,
const css::util::URL& aURL, bool SyncronFlag,
const css::uno::Sequence<css::beans::PropertyValue>& lArguments)
{
return pThis->executeDispatch(xDispatch, aURL, SyncronFlag, lArguments);
}
/** dtor. /** dtor.
*/ */
DispatchHelper::~DispatchHelper() DispatchHelper::~DispatchHelper()
...@@ -103,7 +118,14 @@ css::uno::Any SAL_CALL DispatchHelper::executeDispatch( ...@@ -103,7 +118,14 @@ css::uno::Any SAL_CALL DispatchHelper::executeDispatch(
// search dispatcher // search dispatcher
css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, sTargetFrameName, nSearchFlags); 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);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment