summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2015-03-12 14:04:31 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-16 09:38:09 +0100
commita250e9d3ecf899796e7cfbdd2266e494353580c0 (patch)
treea4b0f21f904888c713488e80b41537d8d4ce5b5c /comphelper
parent4a8afa003b854e74807389c8f82fd4609485f1b8 (diff)
Factor out the .uno: command dispatching to a separate function / file.
Change-Id: I8486933d57d42992e66be7f17443320cfc2ad629
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/Library_comphelper.mk1
-rw-r--r--comphelper/source/misc/dispatchcommand.cxx64
2 files changed, 65 insertions, 0 deletions
diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index 7a263c9b5b60..e36fe31c2713 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -82,6 +82,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/misc/componentmodule \
comphelper/source/misc/configuration \
comphelper/source/misc/configurationhelper \
+ comphelper/source/misc/dispatchcommand \
comphelper/source/misc/docpasswordhelper \
comphelper/source/misc/docpasswordrequest \
comphelper/source/misc/documentinfo \
diff --git a/comphelper/source/misc/dispatchcommand.cxx b/comphelper/source/misc/dispatchcommand.cxx
new file mode 100644
index 000000000000..dd43523fcc2f
--- /dev/null
+++ b/comphelper/source/misc/dispatchcommand.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <comphelper/dispatchcommand.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/URLTransformer.hpp>
+
+using namespace css;
+
+namespace comphelper {
+
+bool dispatchCommand(const OUString& rCommand)
+{
+ // Target where we will execute the .uno: command
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
+
+ uno::Reference<frame::XFrame> xFrame(xDesktop->getActiveFrame());
+ if (!xFrame.is())
+ xFrame = uno::Reference<frame::XFrame>(xDesktop, uno::UNO_QUERY);
+
+ uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, uno::UNO_QUERY);
+ if (!xDispatchProvider.is())
+ return false;
+
+ util::URL aCommandURL;
+ aCommandURL.Complete = rCommand;
+ uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext);
+ xParser->parseStrict(aCommandURL);
+
+ uno::Reference<frame::XDispatch> xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0);
+ if (!xDisp.is())
+ return false;
+
+ // And do the work...
+ xDisp->dispatch(aCommandURL, uno::Sequence<beans::PropertyValue>());
+
+ return true;
+}
+
+} // namespace comphelper
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */