diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-23 14:18:42 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-23 16:09:02 +0100 |
commit | 27e2955e01d997a3b2be852126475cdf2aa7140b (patch) | |
tree | bd6ce90da0fa17d7e9402d945fef80e4dff18b23 /sfx2/source | |
parent | b769648a5fa17e869f4ae4f55e89e7d6cc0367c8 (diff) |
sfx2 classification: write back updated labels as document properties
The internal std::map is just for fast access, if document properties
are not updated at the end, our changes are lost on document close.
Change-Id: I34ce8e47faed96b6a9ddb5776806587d94fc4373
Diffstat (limited to 'sfx2/source')
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index 2ae3415c1fcc..014c5a849c8c 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/xml/sax/Parser.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <sfx2/objsh.hxx> #include <o3tl/make_unique.hxx> @@ -277,10 +278,19 @@ public: std::map<OUString, OUString> m_aLabels; /// Possible categories of a policy to choose from. std::map<OUString, SfxClassificationCategory> m_aCategories; + SfxObjectShell& m_rObjectShell; + Impl(SfxObjectShell& rObjectShell); void parsePolicy(); + /// Synchronize m_aLabels back to the object shell. + void pushToObjectShell(); }; +SfxClassificationHelper::Impl::Impl(SfxObjectShell& rObjectShell) + : m_rObjectShell(rObjectShell) +{ +} + void SfxClassificationHelper::Impl::parsePolicy() { OUString aPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/classification/example.xml"); @@ -305,6 +315,23 @@ void SfxClassificationHelper::Impl::parsePolicy() m_aCategories = xClassificationParser->m_aCategories; } +void SfxClassificationHelper::Impl::pushToObjectShell() +{ + uno::Reference<document::XDocumentProperties> xDocumentProperties = m_rObjectShell.getDocProperties(); + uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); + for (const std::pair<OUString, OUString>& rLabel : m_aLabels) + { + try + { + 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); + } + } +} + bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell) { uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties(); @@ -324,7 +351,7 @@ bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell) } SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell) - : m_pImpl(o3tl::make_unique<Impl>()) + : m_pImpl(o3tl::make_unique<Impl>(rObjectShell)) { uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties(); uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); @@ -443,6 +470,7 @@ void SfxClassificationHelper::SetBACName(const OUString& rName) } m_pImpl->m_aLabels = it->second.m_aLabels; + m_pImpl->pushToObjectShell(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |