[Libreoffice-commits] core.git: desktop/source
Pranav Kant
pranavk at collabora.co.uk
Mon Jul 18 05:46:01 UTC 2016
desktop/source/lib/init.cxx | 50 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
New commits:
commit b91bb2f2702a82255969ae1da298159ee109d14a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Jul 14 12:30:46 2016 +0530
lok: Skip saving unmodified doc if DontSaveIfUnmodified=true
Change-Id: Ia2687bd4bef61df1ff101cab2a19394859b7df58
Reviewed-on: https://gerrit.libreoffice.org/27212
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: pranavk <pranavk at collabora.co.uk>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b319167..9e15484 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -294,6 +294,19 @@ static std::vector<beans::PropertyValue> jsonToPropertyValuesVector(const char*
return aArguments;
}
+static boost::property_tree::ptree unoAnyToPropertyTree(const uno::Any& anyItem)
+{
+ boost::property_tree::ptree aTree;
+ OUString aType = anyItem.getValueTypeName();
+ aTree.put("type", aType.toUtf8().getStr());
+
+ if (aType == "string")
+ aTree.put("value", anyItem.get<OUString>().toUtf8().getStr());
+ // TODO: Add more as required
+
+ return aTree;
+}
+
extern "C"
{
@@ -1438,10 +1451,12 @@ public:
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
{
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
std::vector<beans::PropertyValue> aPropertyValuesVector(jsonToPropertyValuesVector(pArguments));
+ std::size_t nView = SfxLokHelper::getView();
// handle potential interaction
if (gImpl && aCommand == ".uno:Save")
@@ -1455,11 +1470,42 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
aValue.Value <<= xInteraction;
aPropertyValuesVector.push_back(aValue);
+
+ // Check if DontSaveIfUnmodified is specified
+ bool bDontSaveIfUnmodified = false;
+ auto it = aPropertyValuesVector.begin();
+ while (it != aPropertyValuesVector.end())
+ {
+ if (it->Name == "DontSaveIfUnmodified")
+ {
+ bDontSaveIfUnmodified = it->Value.get<bool>();
+
+ // Also remove this param before handling to core
+ it = aPropertyValuesVector.erase(it);
+ }
+ else
+ it++;
+ }
+
+ // skip saving and tell the result via UNO_COMMAND_RESULT
+ if (bDontSaveIfUnmodified && !pDocSh->IsModified())
+ {
+ boost::property_tree::ptree aTree;
+ aTree.put("commandName", pCommand);
+ aTree.put("success", false);
+
+ // Add the reason for not saving
+ const uno::Any aResultValue = uno::makeAny(OUString("unmodified"));
+ aTree.add_child("result", unoAnyToPropertyTree(aResultValue));
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, strdup(aStream.str().c_str()));
+ return;
+ }
}
bool bResult = false;
-
- std::size_t nView = SfxLokHelper::getView();
if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers[nView])
{
bResult = comphelper::dispatchCommand(aCommand, comphelper::containerToSequence(aPropertyValuesVector),
More information about the Libreoffice-commits
mailing list