summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.co.uk>2016-07-14 12:30:46 +0530
committerpranavk <pranavk@collabora.co.uk>2016-07-18 05:45:39 +0000
commitb91bb2f2702a82255969ae1da298159ee109d14a (patch)
tree45ddf7dd79ac95e91f0489932df06c03280f2ae5 /desktop
parentee6f818083a69cb2f264fe47fa7d4dfab0a0cca7 (diff)
lok: Skip saving unmodified doc if DontSaveIfUnmodified=true
Change-Id: Ia2687bd4bef61df1ff101cab2a19394859b7df58 Reviewed-on: https://gerrit.libreoffice.org/27212 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx50
1 files changed, 48 insertions, 2 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b31916779aad..9e15484cf0d4 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),