sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 39 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-)
New commits: commit d547d76c3bee10447de6fd90185212a177349386 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Feb 12 19:00:19 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Feb 12 13:29:55 2021 +0100 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 <qui...@gmail.com> 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 { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits