From aad8e562765b2981e76a008e3eca04058279469f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 23 Feb 2016 14:54:48 +0100 Subject: 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 --- sfx2/source/view/classificationhelper.cxx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'sfx2') 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& 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 xDocumentProperties = m_rObjectShell.getDocProperties(); uno::Reference xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); + uno::Reference xPropertySet(xPropertyContainer, uno::UNO_QUERY); + uno::Sequence aProperties = xPropertySet->getPropertySetInfo()->getProperties(); for (const std::pair& 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); } } } -- cgit