lok::Document::postUnoCommand: allow passing arguments
Change-Id: I6c24a8e392473f3985d3bde9b76a3148fd03bc9a
This commit is contained in:
parent
5dc81ae201
commit
6a8719b12e
@ -15,6 +15,7 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#define LOK_USE_UNSTABLE_API
|
||||
#include <LibreOfficeKit/LibreOfficeKit.h>
|
||||
@ -52,6 +53,7 @@
|
||||
#include <unotools/syslocaleoptions.hxx>
|
||||
#include <unotools/mediadescriptor.hxx>
|
||||
#include <osl/module.hxx>
|
||||
#include <comphelper/sequence.hxx>
|
||||
|
||||
#include <app.hxx>
|
||||
|
||||
@ -207,7 +209,8 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
|
||||
int nY,
|
||||
int nCount);
|
||||
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
|
||||
const char* pCommand);
|
||||
const char* pCommand,
|
||||
const char* pArguments);
|
||||
static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
|
||||
int nType,
|
||||
int nX,
|
||||
@ -701,11 +704,38 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
|
||||
pDoc->postKeyEvent(nType, nCharCode, nKeyCode);
|
||||
}
|
||||
|
||||
static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand)
|
||||
static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues)
|
||||
{
|
||||
boost::property_tree::ptree aTree;
|
||||
std::stringstream aStream(pJSON);
|
||||
boost::property_tree::read_json(aStream, aTree);
|
||||
|
||||
std::vector<beans::PropertyValue> aArguments;
|
||||
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
|
||||
{
|
||||
const std::string& rType = rPair.second.get<std::string>("type");
|
||||
const std::string& rValue = rPair.second.get<std::string>("value");
|
||||
|
||||
beans::PropertyValue aValue;
|
||||
aValue.Name = OUString::fromUtf8(rPair.first.c_str());
|
||||
if (rType == "string")
|
||||
aValue.Value <<= OUString::fromUtf8(rValue.c_str());
|
||||
else if (rType == "boolean")
|
||||
aValue.Value <<= OString(rValue.c_str()).toBoolean();
|
||||
else
|
||||
SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
|
||||
aArguments.push_back(aValue);
|
||||
}
|
||||
rPropertyValues = comphelper::containerToSequence(aArguments);
|
||||
}
|
||||
|
||||
static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand, const char* pArguments)
|
||||
{
|
||||
OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
|
||||
|
||||
if (!comphelper::dispatchCommand(aCommand, uno::Sequence<beans::PropertyValue>()))
|
||||
uno::Sequence<beans::PropertyValue> aPropertyValues;
|
||||
jsonToPropertyValues(pArguments, aPropertyValues);
|
||||
if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
|
||||
{
|
||||
gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
|
||||
}
|
||||
|
@ -132,7 +132,8 @@ struct _LibreOfficeKitDocumentClass
|
||||
|
||||
/// @see lok::Document::postUnoCommand
|
||||
void (*postUnoCommand) (LibreOfficeKitDocument* pThis,
|
||||
const char* pCommand);
|
||||
const char* pCommand,
|
||||
const char* pArguments);
|
||||
|
||||
/// @see lok::Document::setTextSelection
|
||||
void (*setTextSelection) (LibreOfficeKitDocument* pThis,
|
||||
|
@ -181,11 +181,27 @@ public:
|
||||
/**
|
||||
* Posts an UNO command to the document.
|
||||
*
|
||||
* Example argument string:
|
||||
*
|
||||
* {
|
||||
* "SearchItem.SearchString":
|
||||
* {
|
||||
* "type": "string",
|
||||
* "value": "foobar"
|
||||
* },
|
||||
* "SearchItem.Backward":
|
||||
* {
|
||||
* "type": "boolean",
|
||||
* "value": "false"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param pCommand uno command to be posted to the document, like ".uno:Bold"
|
||||
* @param pArguments arguments of the uno command.
|
||||
*/
|
||||
inline void postUnoCommand(const char* pCommand)
|
||||
inline void postUnoCommand(const char* pCommand, const char* pArguments = 0)
|
||||
{
|
||||
mpDoc->pClass->postUnoCommand(mpDoc, pCommand);
|
||||
mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ void lok_docview_set_edit (LOKDocView* pDocView,
|
||||
gboolean lok_docview_get_edit (LOKDocView* pDocView);
|
||||
|
||||
/// Posts the .uno: command to the LibreOfficeKit.
|
||||
void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand);
|
||||
void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand, const char* pArguments);
|
||||
|
||||
/// Posts a keyboard event to LibreOfficeKit.
|
||||
void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
|
||||
|
@ -156,7 +156,7 @@ void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
|
||||
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
|
||||
const std::string& rString = g_aToolItemCommandNames[pItem];
|
||||
g_info("toggleToolItem: lok_docview_post_command('%s')", rString.c_str());
|
||||
lok_docview_post_command(pLOKDocView, rString.c_str());
|
||||
lok_docview_post_command(pLOKDocView, rString.c_str(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1162,9 +1162,9 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
|
||||
return pDocView->m_pImpl->m_bEdit;
|
||||
}
|
||||
|
||||
SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand)
|
||||
SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand, const char* pArguments)
|
||||
{
|
||||
pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand);
|
||||
pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand, pArguments);
|
||||
}
|
||||
|
||||
SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData)
|
||||
|
Loading…
x
Reference in New Issue
Block a user