desktop/source/lib/init.cxx | 50 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-)
New commits: commit b40be03b49f3352a309bec6b0c4e37cac9c4bb88 Author: Pranav Kant <pran...@collabora.co.uk> Date: Thu Jul 14 12:30:46 2016 +0530 lok: Skip saving unmodified doc if DontSaveIfUnmodified=true Reviewed-on: https://gerrit.libreoffice.org/27212 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: pranavk <pran...@collabora.co.uk> (cherry picked from commit b91bb2f2702a82255969ae1da298159ee109d14a) Change-Id: Ia2687bd4bef61df1ff101cab2a19394859b7df58 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4cd1649..2bd3277 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -308,6 +308,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" { @@ -1458,10 +1471,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 = comphelper::LibreOfficeKit::isViewCallback() ? SfxLokHelper::getView() : 0; // handle potential interaction if (gImpl && aCommand == ".uno:Save") @@ -1475,11 +1490,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 = comphelper::LibreOfficeKit::isViewCallback() ? SfxLokHelper::getView() : 0; if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers[nView]) { bResult = comphelper::dispatchCommand(aCommand, comphelper::containerToSequence(aPropertyValuesVector), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits