diff options
-rw-r--r-- | include/sfx2/classificationhelper.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/classificationcontroller.cxx | 49 | ||||
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 35 |
3 files changed, 60 insertions, 26 deletions
diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx index cc7a66f3de33..8d7b0b1688d2 100644 --- a/include/sfx2/classificationhelper.hxx +++ b/include/sfx2/classificationhelper.hxx @@ -78,6 +78,8 @@ public: void UpdateInfobar(SfxViewFrame& rViewFrame); /// Does a best-effort conversion of rType to SfxClassificationPolicyType. static SfxClassificationPolicyType stringToPolicyType(const OUString& rType); + /// Returns the string representation of a SfxClassificationPolicyType element. + static const OUString& policyTypeToString(SfxClassificationPolicyType eType); /// Brief text located at the top of each document's pages. static const OUString& PROP_DOCHEADER(); diff --git a/sfx2/source/view/classificationcontroller.cxx b/sfx2/source/view/classificationcontroller.cxx index 6ac651c6d6f3..5b8ca213c149 100644 --- a/sfx2/source/view/classificationcontroller.cxx +++ b/sfx2/source/view/classificationcontroller.cxx @@ -95,6 +95,8 @@ public: virtual void dispose() override; virtual void Resize() override; VclPtr<ListBox> getCategories(SfxClassificationPolicyType eType); + std::size_t getLabelsSize(); + OUString getCategoryType(ListBox& rCategory); }; ClassificationPropertyListener::ClassificationPropertyListener(const rtl::Reference<comphelper::ConfigurationListener>& xListener, ClassificationCategoriesController& rController) @@ -158,7 +160,11 @@ uno::Reference<awt::XWindow> ClassificationCategoriesController::createItemWindo if (pToolbar) { m_pClassification = VclPtr<ClassificationControl>::Create(pToolbar); - m_pClassification->getCategories(SfxClassificationPolicyType::IntellectualProperty)->SetSelectHdl(LINK(this, ClassificationCategoriesController, SelectHdl)); + for (size_t i = m_pClassification->getLabelsSize(); i > 0; --i) + { + auto eType = static_cast<SfxClassificationPolicyType>(i); + m_pClassification->getCategories(eType)->SetSelectHdl(LINK(this, ClassificationCategoriesController, SelectHdl)); + } } return uno::Reference<awt::XWindow>(VCLUnoHelper::GetInterface(m_pClassification)); @@ -167,9 +173,12 @@ uno::Reference<awt::XWindow> ClassificationCategoriesController::createItemWindo IMPL_LINK_TYPED(ClassificationCategoriesController, SelectHdl, ListBox&, rCategory, void) { OUString aEntry = rCategory.GetSelectEntry(); + + OUString aType = m_pClassification->getCategoryType(rCategory); uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( { {"Name", uno::makeAny(aEntry)}, + {"Type", uno::makeAny(aType)}, })); comphelper::dispatchCommand(".uno:ClassificationApply", aPropertyValues); } @@ -184,17 +193,22 @@ void ClassificationCategoriesController::statusChanged(const frame::FeatureState return; SfxClassificationHelper aHelper(pObjectShell->getDocProperties()); - VclPtr<ListBox> pCategories = m_pClassification->getCategories(SfxClassificationPolicyType::IntellectualProperty); - if (pCategories->GetEntryCount() == 0) + for (size_t i = m_pClassification->getLabelsSize(); i > 0; --i) { - std::vector<OUString> aNames = aHelper.GetBACNames(); - for (const OUString& rName : aNames) - pCategories->InsertEntry(rName); - // Normally VclBuilder::makeObject() does this. - pCategories->EnableAutoSize(true); + auto eType = static_cast<SfxClassificationPolicyType>(i); + VclPtr<ListBox> pCategories = m_pClassification->getCategories(eType); + if (pCategories->GetEntryCount() == 0) + { + std::vector<OUString> aNames = aHelper.GetBACNames(); + for (const OUString& rName : aNames) + pCategories->InsertEntry(rName); + // Normally VclBuilder::makeObject() does this. + pCategories->EnableAutoSize(true); + } } // Restore state based on the doc. model. + VclPtr<ListBox> pCategories = m_pClassification->getCategories(SfxClassificationPolicyType::IntellectualProperty); const OUString& rCategoryName = aHelper.GetBACName(); if (!rCategoryName.isEmpty()) pCategories->SelectEntry(rCategoryName); @@ -289,6 +303,25 @@ VclPtr<ListBox> ClassificationControl::getCategories(SfxClassificationPolicyType return m_pCategories[eType]; } +std::size_t ClassificationControl::getLabelsSize() +{ + return m_pLabels.size(); +} + +OUString ClassificationControl::getCategoryType(ListBox& rCategory) +{ + OUString aRet; + + auto it = std::find_if(m_pCategories.begin(), m_pCategories.end(), [&rCategory](const std::pair<SfxClassificationPolicyType, VclPtr<ListBox>>& rPair) + { + return rPair.second.get() == &rCategory; + }); + if (it != m_pCategories.end()) + aRet = SfxClassificationHelper::policyTypeToString(it->first); + + return aRet; +} + void ClassificationControl::SetOptimalSize() { // Same as SvxColorDockingWindow. diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index 101933fd9a5e..eebe37c452fa 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -82,24 +82,6 @@ const OUString& PROP_PREFIX_NATIONALSECURITY() return sProp; } -/// Converts a SfxClassificationPolicyType to a TSCP_BAILSv1 string value. -const OUString& policyTypeToString(SfxClassificationPolicyType eType) -{ - switch (eType) - { - case SfxClassificationPolicyType::ExportControl: - return PROP_PREFIX_EXPORTCONTROL(); - break; - case SfxClassificationPolicyType::NationalSecurity: - return PROP_PREFIX_NATIONALSECURITY(); - break; - default: - break; - } - - return SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY(); -} - /// Represents one category of a classification policy. class SfxClassificationCategory { @@ -807,6 +789,23 @@ SfxClassificationPolicyType SfxClassificationHelper::stringToPolicyType(const OU return SfxClassificationPolicyType::IntellectualProperty; } +const OUString& SfxClassificationHelper::policyTypeToString(SfxClassificationPolicyType eType) +{ + switch (eType) + { + case SfxClassificationPolicyType::ExportControl: + return PROP_PREFIX_EXPORTCONTROL(); + break; + case SfxClassificationPolicyType::NationalSecurity: + return PROP_PREFIX_NATIONALSECURITY(); + break; + case SfxClassificationPolicyType::IntellectualProperty: + break; + } + + return PROP_PREFIX_INTELLECTUALPROPERTY(); +} + const OUString& SfxClassificationHelper::PROP_DOCHEADER() { static OUString sProp("Marking:document-header"); |