include/sfx2/classificationhelper.hxx | 4 + include/svx/ClassificationCommon.hxx | 3 sfx2/source/view/classificationcontroller.cxx | 101 ++++++++++++++++++++------ sfx2/source/view/classificationhelper.cxx | 36 +++++++++ svx/source/dialog/ClassificationCommon.cxx | 12 --- sw/source/core/edit/edfcol.cxx | 2 6 files changed, 120 insertions(+), 38 deletions(-)
New commits: commit 85f2a1e3eb21228ba932b27dbe375aa241e242bf Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Fri Nov 17 10:30:41 2017 +0900 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 <c...@libreoffice.org> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx index a2699623c4be..54eb5cb0c40e 100644 --- a/include/sfx2/classificationhelper.hxx +++ b/include/sfx2/classificationhelper.hxx @@ -220,6 +220,10 @@ public: } }; +SFX2_DLLPUBLIC sfx::ClassificationCreationOrigin getCreationOriginProperty( + css::uno::Reference<css::beans::XPropertyContainer> const & rxPropertyContainer, + sfx::ClassificationKeyCreator const & rKeyCreator); + } #endif diff --git a/include/svx/ClassificationCommon.hxx b/include/svx/ClassificationCommon.hxx index c08ecd7293ad..2c1d6548ff27 100644 --- a/include/svx/ClassificationCommon.hxx +++ b/include/svx/ClassificationCommon.hxx @@ -48,9 +48,6 @@ SVX_DLLPUBLIC void insertCreationOrigin(css::uno::Reference<css::beans::XPropert sfx::ClassificationKeyCreator const & rKeyCreator, sfx::ClassificationCreationOrigin eOrigin); -SVX_DLLPUBLIC sfx::ClassificationCreationOrigin getCreationOriginProperty(css::uno::Reference<css::beans::XPropertyContainer> const & rxPropertyContainer, - sfx::ClassificationKeyCreator const & rKeyCreator); - } } // end svx::classification namespace 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; +} } diff --git a/svx/source/dialog/ClassificationCommon.cxx b/svx/source/dialog/ClassificationCommon.cxx index 53200046d3e5..779fac5490c8 100644 --- a/svx/source/dialog/ClassificationCommon.cxx +++ b/svx/source/dialog/ClassificationCommon.cxx @@ -118,18 +118,6 @@ void insertCreationOrigin(uno::Reference<beans::XPropertyContainer> const & rxPr addOrInsertDocumentProperty(rxPropertyContainer, rKeyCreator.makeCreationOriginKey(), sValue); } -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; -} - } } // end svx::classification namespace diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 35a470a5bcad..d713d1ddca4f 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -2075,7 +2075,7 @@ void SwEditShell::ClassifyDocPerHighestParagraphClass() // Check the origin, if "manual" (created via advanced classification dialog), // then we just need to set the category name. - if (svx::classification::getCreationOriginProperty(xPropertyContainer, aKeyCreator) == sfx::ClassificationCreationOrigin::MANUAL) + if (sfx::getCreationOriginProperty(xPropertyContainer, aKeyCreator) == sfx::ClassificationCreationOrigin::MANUAL) { aHelper.SetBACName(sHighestClass, eHighestClassType); }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits