summaryrefslogtreecommitdiff
path: root/sfx2/source/view/classificationhelper.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-02-23 14:54:48 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-02-23 16:09:02 +0100
commitaad8e562765b2981e76a008e3eca04058279469f (patch)
tree641f2c525db1f8cd7b5937c54cb7752f7963fe31 /sfx2/source/view/classificationhelper.cxx
parent633e9b9b66f1717a90db73ee6954c8145b934ecb (diff)
sfx2 classification: add or update labels
Instead of just failing to add existing ones. Given that all "optional" properties are also updated (typically to "" or "None"), no need to remove properties. Change-Id: I50e73ac1ca3d3b7d3b3650ec6abdc0ff8c156936
Diffstat (limited to 'sfx2/source/view/classificationhelper.cxx')
-rw-r--r--sfx2/source/view/classificationhelper.cxx17
1 files changed, 15 insertions, 2 deletions
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 8c1d4b550e88..19325859a0a8 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -317,19 +317,32 @@ void SfxClassificationHelper::Impl::parsePolicy()
m_aCategories = xClassificationParser->m_aCategories;
}
+bool lcl_containsProperty(const uno::Sequence<beans::Property>& rProperties, const OUString& rName)
+{
+ return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
+ {
+ return rProperty.Name == rName;
+ }) != rProperties.end();
+}
+
void SfxClassificationHelper::Impl::pushToObjectShell()
{
uno::Reference<document::XDocumentProperties> xDocumentProperties = m_rObjectShell.getDocProperties();
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+ uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
for (const std::pair<OUString, OUString>& rLabel : m_aLabels)
{
try
{
- xPropertyContainer->addProperty(rLabel.first, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rLabel.second));
+ if (lcl_containsProperty(aProperties, rLabel.first))
+ xPropertySet->setPropertyValue(rLabel.first, uno::makeAny(rLabel.second));
+ else
+ xPropertyContainer->addProperty(rLabel.first, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rLabel.second));
}
catch (const uno::Exception& rException)
{
- SAL_WARN("sfx.view", "pushToObjectShell() failed to add property " << rLabel.first << ": " << rException.Message);
+ SAL_WARN("sfx.view", "pushToObjectShell() failed for property " << rLabel.first << ": " << rException.Message);
}
}
}