diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-11-17 10:30:41 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-11-17 05:11:13 +0100 |
commit | 85f2a1e3eb21228ba932b27dbe375aa241e242bf (patch) | |
tree | f33e1ad5584c04f189bb63c64cf28a4848f530eb /sfx2 | |
parent | 9da4b3ee827e83b816514e4eb071e5322cb5ad01 (diff) |
TSCP: disable toolbar pop-up if category was set with dialog
In addition move reading of origin to classificationhelper as we
need to read it there.
Change-Id: I472b073587e68e6896f915477603a25db9b310d3
Reviewed-on: https://gerrit.libreoffice.org/44848
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/view/classificationcontroller.cxx | 101 | ||||
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 36 |
2 files changed, 115 insertions, 22 deletions
diff --git a/sfx2/source/view/classificationcontroller.cxx b/sfx2/source/view/classificationcontroller.cxx index d334eca23688..ab0531fbb83d 100644 --- a/sfx2/source/view/classificationcontroller.cxx +++ b/sfx2/source/view/classificationcontroller.cxx @@ -58,7 +58,7 @@ class ClassificationCategoriesController : public ClassificationCategoriesContro rtl::Reference<comphelper::ConfigurationListener> m_xListener; ClassificationPropertyListener m_aPropertyListener; - DECL_STATIC_LINK(ClassificationCategoriesController, SelectHdl, ListBox&, void); + DECL_LINK(SelectHdl, ListBox&, void); public: explicit ClassificationCategoriesController(const uno::Reference<uno::XComponentContext>& rContext); @@ -97,6 +97,9 @@ public: { return m_pCategory; } + sfx::ClassificationCreationOrigin getExistingClassificationOrigin(); + void toggleInteractivityOnOrigin(); + void setCategoryStateFromPolicy(SfxClassificationHelper & rHelper); }; namespace @@ -168,16 +171,29 @@ uno::Reference<awt::XWindow> ClassificationCategoriesController::createItemWindo return uno::Reference<awt::XWindow>(VCLUnoHelper::GetInterface(m_pClassification)); } -IMPL_STATIC_LINK(ClassificationCategoriesController, SelectHdl, ListBox&, rCategory, void) +IMPL_LINK(ClassificationCategoriesController, SelectHdl, ListBox&, rCategory, void) { - OUString aEntry = rCategory.GetSelectedEntry(); - - OUString aType = getCategoryType(); - uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ - {"Name", uno::makeAny(aEntry)}, - {"Type", uno::makeAny(aType)}, - })); - comphelper::dispatchCommand(".uno:ClassificationApply", aPropertyValues); + m_pClassification->toggleInteractivityOnOrigin(); + + if (m_pClassification->getExistingClassificationOrigin() == sfx::ClassificationCreationOrigin::MANUAL) + { + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + if (!pObjectShell) + return; + SfxClassificationHelper aHelper(pObjectShell->getDocProperties()); + m_pClassification->setCategoryStateFromPolicy(aHelper); + } + else + { + OUString aEntry = rCategory.GetSelectedEntry(); + + OUString aType = getCategoryType(); + uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ + {"Name", uno::makeAny(aEntry)}, + {"Type", uno::makeAny(aType)}, + })); + comphelper::dispatchCommand(".uno:ClassificationApply", aPropertyValues); + } } void ClassificationCategoriesController::statusChanged(const frame::FeatureStateEvent& /*rEvent*/) @@ -191,22 +207,26 @@ void ClassificationCategoriesController::statusChanged(const frame::FeatureState SfxClassificationHelper aHelper(pObjectShell->getDocProperties()); - VclPtr<ListBox> pCategories = m_pClassification->getCategory(); - if (pCategories->GetEntryCount() == 0) + //toggle if the pop-up is enabled/disabled + m_pClassification->toggleInteractivityOnOrigin(); + + // check if classification was set via the advanced dialog + if (m_pClassification->getExistingClassificationOrigin() != sfx::ClassificationCreationOrigin::MANUAL) { - std::vector<OUString> aNames = aHelper.GetBACNames(); - for (const OUString& rName : aNames) - pCategories->InsertEntry(rName); - // Normally VclBuilder::makeObject() does this. - pCategories->EnableAutoSize(true); + VclPtr<ListBox> pCategories = m_pClassification->getCategory(); + 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. - const OUString& rCategoryName = aHelper.GetBACName(SfxClassificationHelper::getPolicyType()); - if (!rCategoryName.isEmpty()) - { - m_pClassification->getCategory()->SelectEntry(rCategoryName); - } + m_pClassification->setCategoryStateFromPolicy(aHelper); + } void ClassificationCategoriesController::removeEntries() @@ -236,6 +256,7 @@ ClassificationControl::ClassificationControl(vcl::Window* pParent) break; } Size aTextSize(m_pLabel->GetTextWidth(aText), m_pLabel->GetTextHeight()); + // Padding. aTextSize.Width() += 12; m_pLabel->SetText(aText); @@ -298,9 +319,45 @@ void ClassificationControl::DataChanged(const DataChangedEvent& rEvent) if ((rEvent.GetType() == DataChangedEventType::SETTINGS) && (rEvent.GetFlags() & AllSettingsFlags::STYLE)) SetOptimalSize(); + toggleInteractivityOnOrigin(); + Window::DataChanged(rEvent); } +sfx::ClassificationCreationOrigin ClassificationControl::getExistingClassificationOrigin() +{ + SfxObjectShell* pObjectShell = SfxObjectShell::Current(); + if (!pObjectShell) + return sfx::ClassificationCreationOrigin::NONE; + + uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjectShell->getDocProperties(); + uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); + + sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType()); + return sfx::getCreationOriginProperty(xPropertyContainer, aKeyCreator); +} + +void ClassificationControl::toggleInteractivityOnOrigin() +{ + if (getExistingClassificationOrigin() == sfx::ClassificationCreationOrigin::MANUAL) + { + Disable(); + } + else + { + Enable(); + } +} + +void ClassificationControl::setCategoryStateFromPolicy(SfxClassificationHelper & rHelper) +{ + const OUString& rCategoryName = rHelper.GetBACName(SfxClassificationHelper::getPolicyType()); + if (!rCategoryName.isEmpty()) + { + getCategory()->SelectEntry(rCategoryName); + } +} + } // namespace sfx2 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* SAL_CALL com_sun_star_sfx2_ClassificationCategoriesController_get_implementation(uno::XComponentContext* pContext, const uno::Sequence<uno::Any>&) diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index a1e4aea55324..e1381e85cd01 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -939,6 +939,42 @@ SfxClassificationPolicyType SfxClassificationHelper::getPolicyType() sal_Int32 nPolicyTypeNumber = officecfg::Office::Common::Classification::Policy::get(); auto eType = static_cast<SfxClassificationPolicyType>(nPolicyTypeNumber); return eType; +} + +namespace sfx +{ + +namespace +{ + +OUString getProperty(uno::Reference<beans::XPropertyContainer> const& rxPropertyContainer, + OUString const& rName) +{ + try + { + uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY); + return xPropertySet->getPropertyValue(rName).get<OUString>(); + } + catch (const css::uno::Exception&) + { + } + + return OUString(); +} + +} // end anonymous namespace + +sfx::ClassificationCreationOrigin getCreationOriginProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, + sfx::ClassificationKeyCreator const & rKeyCreator) +{ + OUString sValue = getProperty(rxPropertyContainer, rKeyCreator.makeCreationOriginKey()); + if (sValue.isEmpty()) + return sfx::ClassificationCreationOrigin::NONE; + + return (sValue == "BAF_POLICY") + ? sfx::ClassificationCreationOrigin::BAF_POLICY + : sfx::ClassificationCreationOrigin::MANUAL; +} } |