diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-02-12 19:00:19 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-02-12 13:29:55 +0100 |
commit | d547d76c3bee10447de6fd90185212a177349386 (patch) | |
tree | d01a0cc0df6dcd9bc3845c4ee48d4bc594a6abe3 /sfx2/source | |
parent | d8cc3e7c9cbdd2959cc7b1c529909c7e4dac6e35 (diff) |
devtools: handle enum values and convert to enum names
Until now enum values were ignored, but now we show the converted
enum numeric values to enum names, whcih is easier to understand
than ust pure numberic values.
Change-Id: I7579a731c20eda92f518ba0214619d8a98185cec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110805
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sfx2/source')
-rw-r--r-- | sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index b00bbfc72c81..4d6d1bdad7bc 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -27,6 +27,9 @@ #include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/reflection/XIdlArray.hpp> +#include <com/sun/star/reflection/XEnumTypeDescription.hpp> + +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/script/XInvocation.hpp> #include <com/sun/star/script/Invocation.hpp> @@ -35,11 +38,15 @@ #include <com/sun/star/lang/XTypeProvider.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/extract.hxx> using namespace css; namespace { +constexpr OUStringLiteral constTypeDescriptionManagerSingletonName + = u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"; + uno::Reference<reflection::XIdlClass> TypeToIdlClass(const uno::Type& rType, const uno::Reference<uno::XComponentContext>& xContext) { @@ -56,12 +63,17 @@ TypeToIdlClass(const uno::Type& rType, const uno::Reference<uno::XComponentConte return xRetClass; } -OUString AnyToString(const uno::Any& aValue) +OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponentContext>& xContext) { + OUString aRetStr; + + // return early if we don't have any value + if (!aValue.hasValue()) + return aRetStr; + uno::Type aValType = aValue.getValueType(); uno::TypeClass eType = aValType.getTypeClass(); - OUString aRetStr; switch (eType) { case uno::TypeClass_INTERFACE: @@ -145,6 +157,27 @@ OUString AnyToString(const uno::Any& aValue) aRetStr = OUString::number(aNumber); break; } + case uno::TypeClass_ENUM: + { + sal_Int32 nIntValue = 0; + if (cppu::enum2int(nIntValue, aValue)) + { + uno::Reference<container::XHierarchicalNameAccess> xManager; + xManager.set(xContext->getValueByName(constTypeDescriptionManagerSingletonName), + uno::UNO_QUERY); + + uno::Reference<reflection::XEnumTypeDescription> xTypeDescription; + xTypeDescription.set(xManager->getByHierarchicalName(aValType.getTypeName()), + uno::UNO_QUERY); + + uno::Sequence<sal_Int32> aValues = xTypeDescription->getEnumValues(); + sal_Int32 nValuesIndex + = std::find(aValues.begin(), aValues.end(), nIntValue) - aValues.begin(); + uno::Sequence<OUString> aNames = xTypeDescription->getEnumNames(); + aRetStr = aNames[nValuesIndex]; + } + break; + } default: break; @@ -282,7 +315,7 @@ public: { if (maAny.hasValue()) { - OUString aValue = AnyToString(maAny); + OUString aValue = AnyToString(maAny, mxContext); OUString aType = getAnyType(maAny, mxContext); return { |