cui/source/options/optaboutconfig.cxx | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
New commits: commit 7c5ca44c48b05ba73defd48057a82db7dc833e0c Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Tue Apr 5 14:40:53 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Tue Apr 5 17:16:45 2022 +0200 Expert Configuration: Allow modifying nil values The Expert Configuration's approach of classifying configuration properties based on their dynamic css::uno::Any types is hopelessly naive and broken, but lets add a little hack to at least allow setting a non-nil value for a nillable property of non-any type that was nil. (This change was motivated by the comment at <https://gerrit.libreoffice.org/c/core/+/132495/1..2/officecfg/registry/schema/org/openoffice/Office/Common.xcs#b2394> "allow to override the generator/producer string in output documents": "The default value is needed because otherwise the advanced settings editor in Tools->Configure->Advanced claims the type is 'void' and doesn't allow editing it." Change-Id: Ia8eef454919b05bda23e56639e93c765ba3a8b13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132575 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/cui/source/options/optaboutconfig.cxx b/cui/source/options/optaboutconfig.cxx index 728134a55575..226839d20c98 100644 --- a/cui/source/options/optaboutconfig.cxx +++ b/cui/source/options/optaboutconfig.cxx @@ -15,12 +15,18 @@ #include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XNameReplace.hpp> #include <com/sun/star/container/XHierarchicalName.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/TypeClass.hpp> #include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/util/SearchFlags.hpp> #include <com/sun/star/util/SearchAlgorithms2.hpp> +#include <cppu/unotype.hxx> #include <rtl/ustrbuf.hxx> #include <unotools/textsearch.hxx> #include <vcl/event.hxx> @@ -582,6 +588,39 @@ IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void ) OUString sPropertyType = m_xPrefBox->get_text(*m_xScratchIter, 2); OUString sPropertyValue = m_xPrefBox->get_text(*m_xScratchIter, 3); + // If the configuration property has a nil value, determine its static type: + if (sPropertyType == "void") + { + css::uno::Reference<css::beans::XPropertySetInfo> info( + CuiAboutConfigTabPage::getConfigAccess(pUserData->sPropertyPath, false), + css::uno::UNO_QUERY_THROW); + css::uno::Type t; + try { + t = info->getPropertyByName(sPropertyName).Type; + } catch (css::beans::UnknownPropertyException &) { + TOOLS_WARN_EXCEPTION("cui.options", pUserData->sPropertyPath << " " << sPropertyName); + } + // If the configuration property is of type any (or an UnknownPropertyException was caught + // above), stick to "void" for now (ideally, properties of type any would allow setting + // values of arbitrary type, regardless of their current value, in this dialog anyway): + if (t != cppu::UnoType<void>::get()) { + sPropertyType = t.getTypeName(); + switch (t.getTypeClass()) { + case css::uno::TypeClass_BOOLEAN: + sPropertyValue = "false"; + break; + case css::uno::TypeClass_SHORT: + case css::uno::TypeClass_LONG: + case css::uno::TypeClass_HYPER: + case css::uno::TypeClass_DOUBLE: + sPropertyValue = "0"; + break; + default: + break; + } + } + } + auto pProperty = std::make_shared<Prop_Impl>( pUserData->sPropertyPath, sPropertyName, Any( sPropertyValue ) ); bool bSaveChanges = false; @@ -741,6 +780,7 @@ IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void ) AddToModifiedVector( pProperty ); //update listbox value. + m_xPrefBox->set_text(*m_xScratchIter, sPropertyType, 2); m_xPrefBox->set_text(*m_xScratchIter, sDialogValue, 3); //update m_prefBoxEntries auto it = std::find_if(m_prefBoxEntries.begin(), m_prefBoxEntries.end(),