[Libreoffice-commits] core.git: sfx2/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Fri Feb 12 04:01:32 UTC 2021


 sfx2/source/devtools/ObjectInspectorTreeHandler.cxx |  127 +++++++++++---------
 1 file changed, 72 insertions(+), 55 deletions(-)

New commits:
commit 5809b0a41bda8f749c4af7eec411077364b4da65
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Feb 10 17:33:33 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Feb 12 05:00:42 2021 +0100

    devtools: move columns and expander handling to the node object
    
    If we need to show the expander and what the values of the columns
    are was until now handeled when the tree node was inserted. Now
    delegate the responsibility for this to the node object, which
    can extract this information from the filled parameters. This
    simplifies a couple of things and makes the code more readable.
    
    Change-Id: I77fcba874f8bb4278cfaf3d8a2846b3fc8faca80
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110739
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index c5f48bfd9b32..c4e3a67e916f 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -141,8 +141,15 @@ public:
 
     virtual OUString getObjectName() = 0;
 
+    virtual bool shouldShowExpander() { return false; }
+
     virtual void fillChildren(std::unique_ptr<weld::TreeView>& rTree, weld::TreeIter const& rParent)
         = 0;
+
+    virtual std::vector<std::pair<sal_Int32, OUString>> getColumnValues()
+    {
+        return std::vector<std::pair<sal_Int32, OUString>>();
+    }
 };
 
 class ObjectInspectorNode : public ObjectInspectorNodeInterface
@@ -158,50 +165,58 @@ public:
     }
 };
 
-OUString lclAppendNode(std::unique_ptr<weld::TreeView>& pTree, ObjectInspectorNodeInterface* pEntry,
-                       bool bChildrenOnDemand = false)
+OUString lclAppendNode(std::unique_ptr<weld::TreeView>& pTree, ObjectInspectorNodeInterface* pEntry)
 {
     OUString sName = pEntry->getObjectName();
     OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
     std::unique_ptr<weld::TreeIter> pCurrent = pTree->make_iterator();
-    pTree->insert(nullptr, -1, &sName, &sId, nullptr, nullptr, bChildrenOnDemand, pCurrent.get());
+    pTree->insert(nullptr, -1, &sName, &sId, nullptr, nullptr, pEntry->shouldShowExpander(),
+                  pCurrent.get());
     pTree->set_text_emphasis(*pCurrent, true, 0);
+
+    for (auto const& rPair : pEntry->getColumnValues())
+    {
+        pTree->set_text(*pCurrent, rPair.second, rPair.first);
+    }
+
     return sId;
 }
 
 OUString lclAppendNodeToParent(std::unique_ptr<weld::TreeView>& pTree,
-                               weld::TreeIter const& rParent, ObjectInspectorNodeInterface* pEntry,
-                               bool bChildrenOnDemand = false)
+                               weld::TreeIter const& rParent, ObjectInspectorNodeInterface* pEntry)
 {
     OUString sName = pEntry->getObjectName();
     OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
     std::unique_ptr<weld::TreeIter> pCurrent = pTree->make_iterator();
-    pTree->insert(&rParent, -1, &sName, &sId, nullptr, nullptr, bChildrenOnDemand, pCurrent.get());
+    pTree->insert(&rParent, -1, &sName, &sId, nullptr, nullptr, pEntry->shouldShowExpander(),
+                  pCurrent.get());
     pTree->set_text_emphasis(*pCurrent, true, 0);
-    return sId;
-}
 
-OUString lclAppendNodeWithIterToParent(std::unique_ptr<weld::TreeView>& pTree,
-                                       weld::TreeIter const& rParent, weld::TreeIter& rCurrent,
-                                       ObjectInspectorNodeInterface* pEntry,
-                                       bool bChildrenOnDemand = false)
-{
-    OUString sName = pEntry->getObjectName();
-    OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
-    pTree->insert(&rParent, -1, &sName, &sId, nullptr, nullptr, bChildrenOnDemand, &rCurrent);
-    pTree->set_text_emphasis(rCurrent, true, 0);
+    for (auto const& rPair : pEntry->getColumnValues())
+    {
+        pTree->set_text(*pCurrent, rPair.second, rPair.first);
+    }
+
     return sId;
 }
 
 class ObjectInspectorNamedNode : public ObjectInspectorNode
 {
-public:
+protected:
     OUString msName;
+    uno::Any maAny;
+    uno::Reference<uno::XComponentContext> mxContext;
 
+public:
     ObjectInspectorNamedNode(OUString const& rName,
-                             css::uno::Reference<css::uno::XInterface> const& xObject)
+                             css::uno::Reference<css::uno::XInterface> const& xObject,
+                             uno::Any aAny = uno::Any(),
+                             uno::Reference<uno::XComponentContext> const& xContext
+                             = uno::Reference<uno::XComponentContext>())
         : ObjectInspectorNode(xObject)
         , msName(rName)
+        , maAny(aAny)
+        , mxContext(xContext)
     {
     }
 
@@ -211,6 +226,22 @@ public:
                       weld::TreeIter const& /*rParent*/) override
     {
     }
+
+    std::vector<std::pair<sal_Int32, OUString>> getColumnValues() override
+    {
+        if (maAny.hasValue())
+        {
+            OUString aValue = AnyToString(maAny);
+            OUString aType = getAnyType(maAny, mxContext);
+
+            return {
+                { 1, aValue },
+                { 2, aType },
+            };
+        }
+
+        return ObjectInspectorNodeInterface::getColumnValues();
+    }
 };
 
 class ServicesNode : public ObjectInspectorNamedNode
@@ -221,6 +252,8 @@ public:
     {
     }
 
+    bool shouldShowExpander() override { return true; }
+
     void fillChildren(std::unique_ptr<weld::TreeView>& pTree,
                       weld::TreeIter const& rParent) override
     {
@@ -237,15 +270,14 @@ public:
 class GenericPropertiesNode : public ObjectInspectorNamedNode
 {
 public:
-    uno::Reference<uno::XComponentContext> mxContext;
-
     GenericPropertiesNode(OUString const& rName, uno::Reference<uno::XInterface> const& xObject,
-                          uno::Reference<uno::XComponentContext> const& xContext)
-        : ObjectInspectorNamedNode(rName, xObject)
-        , mxContext(xContext)
+                          uno::Any aAny, uno::Reference<uno::XComponentContext> const& xContext)
+        : ObjectInspectorNamedNode(rName, xObject, aAny, xContext)
     {
     }
 
+    bool shouldShowExpander() override { return true; }
+
     void fillChildren(std::unique_ptr<weld::TreeView>& pTree,
                       weld::TreeIter const& rParent) override;
 };
@@ -255,7 +287,7 @@ class PropertiesNode : public GenericPropertiesNode
 public:
     PropertiesNode(uno::Reference<uno::XInterface> const& xObject,
                    uno::Reference<uno::XComponentContext> const& xContext)
-        : GenericPropertiesNode("Properties", xObject, xContext)
+        : GenericPropertiesNode("Properties", xObject, uno::Any(), xContext)
     {
     }
 };
@@ -268,6 +300,8 @@ public:
     {
     }
 
+    bool shouldShowExpander() override { return true; }
+
     void fillChildren(std::unique_ptr<weld::TreeView>& pTree,
                       weld::TreeIter const& rParent) override
     {
@@ -288,15 +322,14 @@ public:
 class MethodsNode : public ObjectInspectorNamedNode
 {
 public:
-    uno::Reference<uno::XComponentContext> mxContext;
-
     MethodsNode(css::uno::Reference<css::uno::XInterface> const& xObject,
                 uno::Reference<uno::XComponentContext> const& xContext)
-        : ObjectInspectorNamedNode("Methods", xObject)
-        , mxContext(xContext)
+        : ObjectInspectorNamedNode("Methods", xObject, uno::Any(xObject), xContext)
     {
     }
 
+    bool shouldShowExpander() override { return true; }
+
     void fillChildren(std::unique_ptr<weld::TreeView>& pTree,
                       weld::TreeIter const& rParent) override
     {
@@ -330,8 +363,6 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
 
     for (auto const& xProperty : xProperties)
     {
-        OUString aValue;
-        OUString aType;
         uno::Any aAny;
         uno::Reference<uno::XInterface> xCurrent = mxObject;
 
@@ -340,14 +371,10 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
             if (xInvocation->hasProperty(xProperty.Name))
             {
                 aAny = xInvocation->getValue(xProperty.Name);
-                aValue = AnyToString(aAny);
-                aType = getAnyType(aAny, mxContext);
             }
         }
         catch (...)
         {
-            aValue = "<?>";
-            aType = "?";
         }
 
         bool bComplex = false;
@@ -361,27 +388,17 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
             }
         }
 
-        std::unique_ptr<weld::TreeIter> pCurrent = pTree->make_iterator();
         if (bComplex)
         {
-            lclAppendNodeWithIterToParent(
-                pTree, rParent, *pCurrent,
-                new GenericPropertiesNode(xProperty.Name, xCurrent, mxContext), true);
+            lclAppendNodeToParent(
+                pTree, rParent,
+                new GenericPropertiesNode(xProperty.Name, xCurrent, aAny, mxContext));
         }
         else
         {
-            lclAppendNodeWithIterToParent(pTree, rParent, *pCurrent,
-                                          new ObjectInspectorNamedNode(xProperty.Name, xCurrent),
-                                          false);
-        }
-
-        if (!aValue.isEmpty())
-        {
-            pTree->set_text(*pCurrent, aValue, 1);
-        }
-        if (!aType.isEmpty())
-        {
-            pTree->set_text(*pCurrent, aType, 2);
+            lclAppendNodeToParent(
+                pTree, rParent,
+                new ObjectInspectorNamedNode(xProperty.Name, xCurrent, aAny, mxContext));
         }
     }
 }
@@ -450,10 +467,10 @@ void ObjectInspectorTreeHandler::introspect(uno::Reference<uno::XInterface> cons
     mpObjectInspectorTree->freeze();
     mpObjectInspectorTree->clear();
 
-    lclAppendNode(mpObjectInspectorTree, new ServicesNode(xInterface), true);
-    lclAppendNode(mpObjectInspectorTree, new InterfacesNode(xInterface), true);
-    lclAppendNode(mpObjectInspectorTree, new PropertiesNode(xInterface, xContext), true);
-    lclAppendNode(mpObjectInspectorTree, new MethodsNode(xInterface, xContext), true);
+    lclAppendNode(mpObjectInspectorTree, new ServicesNode(xInterface));
+    lclAppendNode(mpObjectInspectorTree, new InterfacesNode(xInterface));
+    lclAppendNode(mpObjectInspectorTree, new PropertiesNode(xInterface, xContext));
+    lclAppendNode(mpObjectInspectorTree, new MethodsNode(xInterface, xContext));
 
     mpObjectInspectorTree->thaw();
 }


More information about the Libreoffice-commits mailing list