include/sfx2/devtools/ObjectInspectorTreeHandler.hxx | 5 + sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 68 ++++++++++++++----- sfx2/uiconfig/ui/developmenttool.ui | 1 3 files changed, 56 insertions(+), 18 deletions(-)
New commits: commit 1beb97dfc2d8c8e9ee06001ac59a22a3208214d1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Mar 11 23:26:29 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Mar 13 12:47:54 2021 +0100 devtools: show superclass tree in interface and services tree view Change-Id: I508b568bbb5b0559c265a3f058e689eeeb326b83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112372 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx index 65a16be8c890..58b4c833961c 100644 --- a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx +++ b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx @@ -15,8 +15,9 @@ #include <vcl/commandevent.hxx> #include <vcl/svapp.hxx> -#include <com/sun/star/uno/XInterface.hpp> #include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <memory> #include <deque> @@ -34,6 +35,8 @@ private: std::deque<css::uno::Any> maInspectionStack; + css::uno::Reference<css::uno::XComponentContext> mxContext; + static void clearObjectInspectorChildren(std::unique_ptr<weld::TreeView>& pTreeView, weld::TreeIter const& rParent); static void handleExpanding(std::unique_ptr<weld::TreeView>& pTreeView, diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index 33f2b5c90e85..553e7616308b 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -12,9 +12,6 @@ #include <sfx2/devtools/ObjectInspectorTreeHandler.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/uno/Reference.hxx> - #include <com/sun/star/beans/theIntrospection.hpp> #include <com/sun/star/beans/XIntrospection.hpp> #include <com/sun/star/beans/XIntrospectionAccess.hpp> @@ -190,6 +187,14 @@ OUString getAnyType(const uno::Any& aValue) return aTypeName.replaceAll("com.sun.star", "css"); } +uno::Reference<reflection::XIdlClass> +convertTypeToIdlClass(const uno::Type& rType, + const uno::Reference<uno::XComponentContext>& xContext) +{ + auto xReflection = reflection::theCoreReflection::get(xContext); + return xReflection->forName(rType.getTypeName()); +} + // Object inspector nodes class ObjectInspectorNodeInterface @@ -346,6 +351,43 @@ public: } }; +class ClassNode : public ObjectInspectorNodeInterface +{ +private: + uno::Reference<reflection::XIdlClass> mxClass; + + static bool isXInterface(uno::Reference<reflection::XIdlClass> const& xClass) + { + return xClass->getName() == "com.sun.star.uno.XInterface"; + } + +public: + ClassNode(uno::Reference<reflection::XIdlClass> const& xClass) + : mxClass(xClass) + { + } + + bool shouldShowExpander() override + { + auto const& xSuperClasses = mxClass->getSuperclasses(); + return xSuperClasses.getLength() > 2 + || (xSuperClasses.getLength() == 1 && !isXInterface(xSuperClasses[0])); + } + + OUString getObjectName() override { return mxClass->getName(); } + + void fillChildren(std::unique_ptr<weld::TreeView>& rTree, + const weld::TreeIter* pParent) override + { + auto const& xSuperClasses = mxClass->getSuperclasses(); + for (auto const& xSuper : xSuperClasses) + { + if (!isXInterface(xSuper)) + lclAppendNodeToParent(rTree, pParent, new ClassNode(xSuper)); + } + } +}; + class BasicValueNode : public SimpleStringNode { protected: @@ -434,9 +476,7 @@ public: uno::Reference<uno::XComponentContext> const& xContext) : BasicValueNode(rName, rAny, rInfo, xContext) { - auto xReflection = reflection::theCoreReflection::get(mxContext); - OUString aTypeName = maAny.getValueType().getTypeName(); - auto xClass = xReflection->forName(aTypeName); + auto xClass = convertTypeToIdlClass(maAny.getValueType(), mxContext); mxIdlArray = xClass->getArray(); } @@ -717,6 +757,7 @@ ObjectInspectorTreeHandler::ObjectInspectorTreeHandler( , mpClassNameLabel(pClassNameLabel) , mpObjectInspectorToolbar(pObjectInspectorToolbar) , mpObjectInspectorNotebook(pObjectInspectorNotebook) + , mxContext(comphelper::getProcessComponentContext()) { mpInterfacesTreeView->connect_expanding( LINK(this, ObjectInspectorTreeHandler, ExpandingHandlerInterfaces)); @@ -965,14 +1006,15 @@ void ObjectInspectorTreeHandler::appendInterfaces(uno::Reference<uno::XInterface { if (!xInterface.is()) return; + uno::Reference<lang::XTypeProvider> xTypeProvider(xInterface, uno::UNO_QUERY); if (xTypeProvider.is()) { const auto xSequenceTypes = xTypeProvider->getTypes(); for (auto const& xType : xSequenceTypes) { - OUString aName = xType.getTypeName(); - lclAppendNode(mpInterfacesTreeView, new SimpleStringNode(aName)); + auto xClass = convertTypeToIdlClass(xType, mxContext); + lclAppendNode(mpInterfacesTreeView, new ClassNode(xClass)); } } } @@ -994,8 +1036,7 @@ void ObjectInspectorTreeHandler::appendProperties(uno::Reference<uno::XInterface { if (!xInterface.is()) return; - GenericPropertiesNode aNode("", uno::Any(xInterface), "", - comphelper::getProcessComponentContext()); + GenericPropertiesNode aNode("", uno::Any(xInterface), "", mxContext); aNode.fillChildren(mpPropertiesTreeView, nullptr); } @@ -1004,8 +1045,7 @@ void ObjectInspectorTreeHandler::appendMethods(uno::Reference<uno::XInterface> c if (!xInterface.is()) return; - uno::Reference<beans::XIntrospection> xIntrospection - = beans::theIntrospection::get(comphelper::getProcessComponentContext()); + uno::Reference<beans::XIntrospection> xIntrospection = beans::theIntrospection::get(mxContext); auto xIntrospectionAccess = xIntrospection->inspect(uno::Any(xInterface)); const auto xMethods = xIntrospectionAccess->getMethods(beans::MethodConcept::ALL); @@ -1045,10 +1085,6 @@ void ObjectInspectorTreeHandler::inspectObject(uno::Reference<uno::XInterface> c if (!xInterface.is()) return; - uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); - if (!xContext.is()) - return; - // Set implementation name auto xServiceInfo = uno::Reference<lang::XServiceInfo>(xInterface, uno::UNO_QUERY); OUString aImplementationName = xServiceInfo->getImplementationName(); diff --git a/sfx2/uiconfig/ui/developmenttool.ui b/sfx2/uiconfig/ui/developmenttool.ui index 9f23752d7f26..40223847ddd4 100644 --- a/sfx2/uiconfig/ui/developmenttool.ui +++ b/sfx2/uiconfig/ui/developmenttool.ui @@ -168,7 +168,6 @@ <property name="vexpand">True</property> <property name="model">object_inspector_interfaces_liststore</property> <property name="search-column">0</property> - <property name="show-expanders">False</property> <property name="enable-tree-lines">True</property> <child internal-child="selection"> <object class="GtkTreeSelection"/> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits