summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-01-15 11:57:50 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-01-15 14:56:20 +0100
commitdf8a65e3b5b4a4e9213450407c08c74503f36a29 (patch)
tree76899ac4bab6185146eb535864e3286c7279701c /xmloff
parent6965233068aad71b7a2f21a8cf9f86e856c99c1a (diff)
tdf#136861 ODT export: fix writing resolved state for non-ranged comments
It was probably not intentional to write the resolved state only in case the annotation has a name. Conflicts: xmloff/qa/unit/text.cxx Change-Id: Ia3a6b2320e2288528c43c832211ebfcde492881e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109364 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/CppunitTest_xmloff_text.mk1
-rw-r--r--xmloff/qa/unit/text.cxx66
-rw-r--r--xmloff/source/text/txtflde.cxx23
3 files changed, 78 insertions, 12 deletions
diff --git a/xmloff/CppunitTest_xmloff_text.mk b/xmloff/CppunitTest_xmloff_text.mk
index e3259672605b..8e757fd584b2 100644
--- a/xmloff/CppunitTest_xmloff_text.mk
+++ b/xmloff/CppunitTest_xmloff_text.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \
sal \
test \
unotest \
+ utl \
))
$(eval $(call gb_CppunitTest_use_sdk_api,xmloff_text))
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index d7da798bafab..73e03fa8aa8e 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -11,8 +11,15 @@
#include <unotest/macros_test.hxx>
#include <comphelper/processfactory.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+
+#include <comphelper/propertysequence.hxx>
+#include <unotools/tempfile.hxx>
using namespace ::com::sun::star;
@@ -56,6 +63,65 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMailMergeInEditeng)
CPPUNIT_ASSERT(getComponent().is());
}
+static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xComponent,
+ const OUString& rCommand,
+ const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+ uno::Reference<frame::XController> xController
+ = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
+ CPPUNIT_ASSERT(xController.is());
+ uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFrame.is());
+
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+ CPPUNIT_ASSERT(xDispatchHelper.is());
+
+ xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved)
+{
+ getComponent() = loadFromDesktop("private:factory/swriter");
+ uno::Sequence<beans::PropertyValue> aCommentProps = comphelper::InitPropertySequence({
+ { "Text", uno::makeAny(OUString("comment")) },
+ });
+ lcl_dispatchCommand(getComponent(), ".uno:InsertAnnotation", aCommentProps);
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xPortionEnum = xPara->createEnumeration();
+ uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xField(xPortion->getPropertyValue("TextField"),
+ uno::UNO_QUERY);
+ xField->setPropertyValue("Resolved", uno::makeAny(true));
+
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({
+ { "FilterName", uno::makeAny(OUString("writer8")) },
+ });
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+ getComponent()->dispose();
+
+ getComponent() = loadFromDesktop(aTempFile.GetURL());
+ xTextDocument.set(getComponent(), uno::UNO_QUERY);
+ xParaEnumAccess.set(xTextDocument->getText(), uno::UNO_QUERY);
+ xParaEnum = xParaEnumAccess->createEnumeration();
+ xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+ xPortionEnum = xPara->createEnumeration();
+ xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY);
+ xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY);
+ bool bResolved = false;
+ xField->getPropertyValue("Resolved") >>= bResolved;
+ // Without the accompanying fix in place, this test would have failed, as the resolved state was
+ // not saved for non-range comments.
+ CPPUNIT_ASSERT(bResolved);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx
index 80eb961952a4..a15c50641bab 100644
--- a/xmloff/source/text/txtflde.cxx
+++ b/xmloff/source/text/txtflde.cxx
@@ -1752,18 +1752,17 @@ void XMLTextFieldExport::ExportFieldHelper(
if (!aName.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, aName);
- SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion();
- if (eVersion & SvtSaveOptions::ODFSVER_EXTENDED)
- {
- bool b = GetBoolProperty("Resolved", rPropSet);
- OUString aResolvedText;
- OUStringBuffer aResolvedTextBuffer;
- ::sax::Converter::convertBool(aResolvedTextBuffer, b);
- aResolvedText = aResolvedTextBuffer.makeStringAndClear();
-
- GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_RESOLVED,
- aResolvedText);
- }
+ }
+ SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion();
+ if (eVersion & SvtSaveOptions::ODFSVER_EXTENDED)
+ {
+ bool b = GetBoolProperty("Resolved", rPropSet);
+ OUString aResolvedText;
+ OUStringBuffer aResolvedTextBuffer;
+ ::sax::Converter::convertBool(aResolvedTextBuffer, b);
+ aResolvedText = aResolvedTextBuffer.makeStringAndClear();
+
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_RESOLVED, aResolvedText);
}
SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE,
XML_ANNOTATION, false, true);