summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-05-27 11:38:42 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-05-27 12:11:46 +0200
commit79baafccf3d390810f516b2cf9cb3ad2b4e9e63b (patch)
treee795e64c75b64c1232616d365be8fea60f0e2085 /xmloff
parentbd6cb0d8219b117b1a72774c26d54774c72602da (diff)
sw content controls, date: add current date handling
While working on the DOCX import for dates, it turns out there is a need to store the selected date in machine-readable format as well. This is useful, because once the timestamp is formatted, the user is allowed to hand-edit the result, so otherwise the selected date would be lost. This commit adds: - doc model & UNO API - click handler (store the selected date, default to the current date in the date picker if possible) - ODT filter - DOCX export And tests for all these. Change-Id: I00f4e87ebfe0e8a19486367c32d472ccd2ff16a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135035 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/qa/unit/data/content-control-date.fodt2
-rw-r--r--xmloff/qa/unit/text.cxx6
-rw-r--r--xmloff/source/text/txtparae.cxx6
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx9
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx1
5 files changed, 23 insertions, 1 deletions
diff --git a/xmloff/qa/unit/data/content-control-date.fodt b/xmloff/qa/unit/data/content-control-date.fodt
index dd3749a02e99..c49e51339c3b 100644
--- a/xmloff/qa/unit/data/content-control-date.fodt
+++ b/xmloff/qa/unit/data/content-control-date.fodt
@@ -2,7 +2,7 @@
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:body>
<office:text>
- <text:p><loext:content-control loext:date="true" loext:date-format="YYYY-MM-DD" loext:date-rfc-language-tag="en-US">choose a date</loext:content-control></text:p>
+ <text:p><loext:content-control loext:date="true" loext:date-format="YYYY-MM-DD" loext:date-rfc-language-tag="en-US" loext:current-date="2022-05-25T00:00:00Z">choose a date</loext:content-control></text:p>
</office:text>
</office:body>
</office:document>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index 303f31c4ca40..2aed79376fe0 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -732,6 +732,8 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlExport)
xContentControlProps->setPropertyValue("Date", uno::Any(true));
xContentControlProps->setPropertyValue("DateFormat", uno::Any(OUString("YYYY-MM-DD")));
xContentControlProps->setPropertyValue("DateLanguage", uno::Any(OUString("en-US")));
+ xContentControlProps->setPropertyValue("CurrentDate",
+ uno::Any(OUString("2022-05-25T00:00:00Z")));
xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
// When exporting to ODT:
@@ -752,6 +754,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlExport)
assertXPath(pXmlDoc, "//loext:content-control", "date", "true");
assertXPath(pXmlDoc, "//loext:content-control", "date-format", "YYYY-MM-DD");
assertXPath(pXmlDoc, "//loext:content-control", "date-rfc-language-tag", "en-US");
+ assertXPath(pXmlDoc, "//loext:content-control", "current-date", "2022-05-25T00:00:00Z");
}
CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlImport)
@@ -788,6 +791,9 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlImport)
OUString aDateLanguage;
xContentControlProps->getPropertyValue("DateLanguage") >>= aDateLanguage;
CPPUNIT_ASSERT_EQUAL(OUString("en-US"), aDateLanguage);
+ OUString aCurrentDate;
+ xContentControlProps->getPropertyValue("CurrentDate") >>= aCurrentDate;
+ CPPUNIT_ASSERT_EQUAL(OUString("2022-05-25T00:00:00Z"), aCurrentDate);
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 4c4537db064a..5d9bd3768d01 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3966,6 +3966,12 @@ void XMLTextParagraphExport::ExportContentControl(
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE_RFC_LANGUAGE_TAG, aDateLanguage);
}
+ OUString aCurrentDate;
+ xPropertySet->getPropertyValue("CurrentDate") >>= aCurrentDate;
+ if (!aCurrentDate.isEmpty())
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CURRENT_DATE, aCurrentDate);
+ }
}
SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false,
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index dbe6b824504c..a597a28a686c 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -112,6 +112,11 @@ void XMLContentControlContext::startFastElement(
m_aDateLanguage = rIter.toString();
break;
}
+ case XML_ELEMENT(LO_EXT, XML_CURRENT_DATE):
+ {
+ m_aCurrentDate = rIter.toString();
+ break;
+ }
default:
XMLOFF_WARN_UNKNOWN("xmloff", rIter);
}
@@ -193,6 +198,10 @@ void XMLContentControlContext::endFastElement(sal_Int32)
{
xPropertySet->setPropertyValue("DateLanguage", uno::Any(m_aDateLanguage));
}
+ if (!m_aCurrentDate.isEmpty())
+ {
+ xPropertySet->setPropertyValue("CurrentDate", uno::Any(m_aCurrentDate));
+ }
}
css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 623ef97e8df3..2c3ecfb9cafb 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -47,6 +47,7 @@ class XMLContentControlContext : public SvXMLImportContext
bool m_bDate = false;
OUString m_aDateFormat;
OUString m_aDateLanguage;
+ OUString m_aCurrentDate;
public:
XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints,