sfx2/source/devtools/ObjectInspectorTreeHandler.cxx |  125 ++++++++++++++++----
 sfx2/uiconfig/ui/developmenttool.ui                 |   22 ++-
 2 files changed, 118 insertions(+), 29 deletions(-)

New commits:
commit 8d1888fca3147520c6f049ba4335932f69caf358
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Mar 5 22:28:40 2021 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Mar 12 16:03:58 2021 +0100

    devtools: new column "Info" for properties in object inspector
    
    Adds additional column "info" for properties, where additional
    property attributes are written. Currently these are mostly
    constants from beans::PropertyAttribute, but they can be others
    too (anything that is useful to the users for the current property,
    struct, sequence).
    
    Change-Id: I12d21ebdfb9352bca79def98d5aa65aa48cfe2aa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112117
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx 
b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index 0466f252166e..e0f2b4ae9d5d 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
 #include <com/sun/star/beans/Property.hpp>
 #include <com/sun/star/beans/PropertyConcept.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/beans/MethodConcept.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 
@@ -349,15 +350,18 @@ class BasicValueNode : public SimpleStringNode
 {
 protected:
     uno::Any maAny;
+    OUString mrInfo;
     uno::Reference<uno::XComponentContext> mxContext;
 
-    ObjectInspectorNodeInterface* createNodeObjectForAny(OUString const& 
rName, uno::Any& rAny);
+    ObjectInspectorNodeInterface* createNodeObjectForAny(OUString const& 
rName, uno::Any& rAny,
+                                                         OUString const& 
mrInfo);
 
 public:
-    BasicValueNode(OUString const& rName, uno::Any const& rAny,
+    BasicValueNode(OUString const& rName, uno::Any const& rAny, OUString 
const& rInfo,
                    uno::Reference<uno::XComponentContext> const& xContext)
         : SimpleStringNode(rName)
         , maAny(rAny)
+        , mrInfo(rInfo)
         , mxContext(xContext)
     {
     }
@@ -389,19 +393,16 @@ public:
         OUString aValue = AnyToString(maAny, mxContext);
         OUString aType = getAnyType(maAny);
 
-        return {
-            { 1, aValue },
-            { 2, aType },
-        };
+        return { { 1, aValue }, { 2, aType }, { 3, mrInfo } };
     }
 };
 
 class GenericPropertiesNode : public BasicValueNode
 {
 public:
-    GenericPropertiesNode(OUString const& rName, uno::Any const& rAny,
+    GenericPropertiesNode(OUString const& rName, uno::Any const& rAny, 
OUString const& rInfo,
                           uno::Reference<uno::XComponentContext> const& 
xContext)
-        : BasicValueNode(rName, rAny, xContext)
+        : BasicValueNode(rName, rAny, rInfo, xContext)
     {
     }
 
@@ -412,9 +413,9 @@ public:
 class StructNode : public BasicValueNode
 {
 public:
-    StructNode(OUString const& rName, uno::Any const& rAny,
+    StructNode(OUString const& rName, uno::Any const& rAny, OUString const& 
rInfo,
                uno::Reference<uno::XComponentContext> const& xContext)
-        : BasicValueNode(rName, rAny, xContext)
+        : BasicValueNode(rName, rAny, rInfo, xContext)
     {
     }
 
@@ -429,9 +430,9 @@ class SequenceNode : public BasicValueNode
     uno::Reference<reflection::XIdlArray> mxIdlArray;
 
 public:
-    SequenceNode(OUString const& rName, uno::Any const& rAny,
+    SequenceNode(OUString const& rName, uno::Any const& rAny, OUString const& 
rInfo,
                  uno::Reference<uno::XComponentContext> const& xContext)
-        : BasicValueNode(rName, rAny, xContext)
+        : BasicValueNode(rName, rAny, rInfo, xContext)
     {
         auto xReflection = reflection::theCoreReflection::get(mxContext);
         OUString aTypeName = maAny.getValueType().getTypeName();
@@ -456,7 +457,8 @@ public:
             uno::Any aArrayValue = mxIdlArray->get(maAny, i);
             uno::Reference<uno::XInterface> xCurrent;
 
-            auto* pObjectInspectorNode = 
createNodeObjectForAny(OUString::number(i), aArrayValue);
+            auto* pObjectInspectorNode
+                = createNodeObjectForAny(OUString::number(i), aArrayValue, "");
             if (pObjectInspectorNode)
                 lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
         }
@@ -490,7 +492,8 @@ void 
GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
         for (OUString const& rName : aNames)
         {
             uno::Any aAny = xNameAccess->getByName(rName);
-            auto* pObjectInspectorNode = createNodeObjectForAny("@" + rName, 
aAny);
+            auto* pObjectInspectorNode
+                = createNodeObjectForAny(u"@" + rName, aAny, u"name 
container");
             lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
         }
     }
@@ -502,7 +505,7 @@ void 
GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
         {
             uno::Any aAny = xIndexAccess->getByIndex(nIndex);
             auto* pObjectInspectorNode
-                = createNodeObjectForAny("@" + OUString::number(nIndex), aAny);
+                = createNodeObjectForAny(u"@" + OUString::number(nIndex), 
aAny, u"index container");
             lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
         }
     }
@@ -517,7 +520,7 @@ void 
GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
             {
                 uno::Any aAny = xEnumeration->nextElement();
                 auto* pObjectInspectorNode
-                    = createNodeObjectForAny("@{" + OUString::number(nIndex) + 
"}", aAny);
+                    = createNodeObjectForAny(u"@" + OUString::number(nIndex), 
aAny, u"enumeration");
                 lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
             }
         }
@@ -533,6 +536,8 @@ void 
GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
     if (!xInvocation.is())
         return;
 
+    const auto xInvocationAccess = xInvocation->getIntrospection();
+
     const auto aInvocationInfoSequence = xInvocation->getInfo();
     for (auto const& aInvocationInfo : aInvocationInfoSequence)
     {
@@ -540,15 +545,84 @@ void 
GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
         {
             uno::Any aCurrentAny;
             auto const& aPropertyName = aInvocationInfo.aName;
+
+            bool bIsAttribute = false;
+            bool bIsGetSetMethod = false;
+            bool bMethodGet = false;
+            bool bMethodSet = false;
+            bool bMethodIs = false;
             try
             {
                 aCurrentAny = xInvocation->getValue(aPropertyName);
+                bIsAttribute = xInvocationAccess->hasProperty(aPropertyName,
+                                                              
beans::PropertyConcept::ATTRIBUTES);
+                bIsGetSetMethod = xInvocationAccess->hasProperty(aPropertyName,
+                                                                 
beans::PropertyConcept::METHODS);
+                if (bIsGetSetMethod)
+                {
+                    bMethodGet = xInvocationAccess->hasMethod(u"get" + 
aPropertyName,
+                                                              
beans::MethodConcept::PROPERTY);
+                    bMethodSet = xInvocationAccess->hasMethod(u"set" + 
aPropertyName,
+                                                              
beans::MethodConcept::PROPERTY);
+                    bMethodIs = xInvocationAccess->hasMethod(u"is" + 
aPropertyName,
+                                                             
beans::MethodConcept::PROPERTY);
+                }
             }
             catch (...)
             {
             }
 
-            auto* pObjectInspectorNode = createNodeObjectForAny(aPropertyName, 
aCurrentAny);
+            std::vector<OUString> aInfoCollection;
+            if (bIsAttribute)
+                aInfoCollection.push_back(u"attribute");
+            if (bIsGetSetMethod)
+            {
+                bool bSet = false;
+                OUString aString;
+                if (bMethodGet || bMethodIs)
+                {
+                    aString += u"get";
+                    bSet = true;
+                }
+                if (bMethodSet)
+                {
+                    if (bSet)
+                        aString += u", ";
+                    aString += u"set";
+                }
+                aInfoCollection.push_back(u"(" + aString + u")");
+            }
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::MAYBEVOID)
+                aInfoCollection.push_back(u"may be void");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::READONLY)
+                aInfoCollection.push_back(u"read-only");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::REMOVABLE)
+                aInfoCollection.push_back(u"removeable");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::BOUND)
+                aInfoCollection.push_back(u"bound");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::CONSTRAINED)
+                aInfoCollection.push_back(u"constrained");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::TRANSIENT)
+                aInfoCollection.push_back(u"transient");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::MAYBEAMBIGUOUS)
+                aInfoCollection.push_back(u"may be ambiguous");
+            if (aInvocationInfo.PropertyAttribute & 
beans::PropertyAttribute::MAYBEDEFAULT)
+                aInfoCollection.push_back(u"may be default");
+
+            bool bSet = false;
+            OUString aInfoString;
+            for (auto const& rString : aInfoCollection)
+            {
+                if (bSet)
+                    aInfoString += ", ";
+                else
+                    bSet = true;
+
+                aInfoString += rString;
+            }
+
+            auto* pObjectInspectorNode
+                = createNodeObjectForAny(aPropertyName, aCurrentAny, 
aInfoString);
             if (pObjectInspectorNode)
                 lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
         }
@@ -568,7 +642,7 @@ void 
StructNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, const weld
         OUString aFieldName = xField->getName();
         uno::Any aFieldValue = xField->get(maAny);
 
-        auto* pObjectInspectorNode = createNodeObjectForAny(aFieldName, 
aFieldValue);
+        auto* pObjectInspectorNode = createNodeObjectForAny(aFieldName, 
aFieldValue, "");
         if (pObjectInspectorNode)
         {
             lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
@@ -576,25 +650,25 @@ void 
StructNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, const weld
     }
 }
 
-ObjectInspectorNodeInterface* BasicValueNode::createNodeObjectForAny(OUString 
const& rName,
-                                                                     uno::Any& 
rAny)
+ObjectInspectorNodeInterface*
+BasicValueNode::createNodeObjectForAny(OUString const& rName, uno::Any& rAny, 
OUString const& rInfo)
 {
     switch (rAny.getValueType().getTypeClass())
     {
         case uno::TypeClass_INTERFACE:
-            return new GenericPropertiesNode(rName, rAny, mxContext);
+            return new GenericPropertiesNode(rName, rAny, rInfo, mxContext);
 
         case uno::TypeClass_SEQUENCE:
-            return new SequenceNode(rName, rAny, mxContext);
+            return new SequenceNode(rName, rAny, rInfo, mxContext);
 
         case uno::TypeClass_STRUCT:
-            return new StructNode(rName, rAny, mxContext);
+            return new StructNode(rName, rAny, rInfo, mxContext);
 
         default:
             break;
     }
 
-    return new BasicValueNode(rName, rAny, mxContext);
+    return new BasicValueNode(rName, rAny, rInfo, mxContext);
 }
 
 // helper functions
@@ -916,7 +990,8 @@ void 
ObjectInspectorTreeHandler::appendProperties(uno::Reference<uno::XInterface
 {
     if (!xInterface.is())
         return;
-    GenericPropertiesNode aNode("", uno::Any(xInterface), 
comphelper::getProcessComponentContext());
+    GenericPropertiesNode aNode("", uno::Any(xInterface), "",
+                                comphelper::getProcessComponentContext());
     aNode.fillChildren(mpPropertiesTreeView, nullptr);
 }
 
diff --git a/sfx2/uiconfig/ui/developmenttool.ui 
b/sfx2/uiconfig/ui/developmenttool.ui
index 8326083cde5a..22c1f5f315f1 100644
--- a/sfx2/uiconfig/ui/developmenttool.ui
+++ b/sfx2/uiconfig/ui/developmenttool.ui
@@ -40,6 +40,8 @@
       <column type="gchararray"/>
       <!-- column-name type -->
       <column type="gchararray"/>
+      <!-- column-name info -->
+      <column type="gchararray"/>
       <!-- column-name id -->
       <column type="gchararray"/>
     </columns>
@@ -218,7 +220,7 @@
                           <object class="GtkTreeSelection"/>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="treeviewcolumn7">
+                          <object class="GtkTreeViewColumn" 
id="services_treeviewcolumn1">
                             <property name="resizable">True</property>
                             <property name="title" translatable="yes" 
context="developmenttool|name">Name</property>
                             <child>
@@ -268,7 +270,7 @@
                           <object class="GtkTreeSelection"/>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="treeviewcolumn1">
+                          <object class="GtkTreeViewColumn" 
id="properties_treeviewcolumn1">
                             <property name="resizable">True</property>
                             <property name="title" translatable="yes" 
context="developmenttool|object">Object</property>
                             <child>
@@ -280,7 +282,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="treeviewcolumn2">
+                          <object class="GtkTreeViewColumn" 
id="properties_treeviewcolumn2">
                             <property name="resizable">True</property>
                             <property name="title" translatable="yes" 
context="developmenttool|value">Value</property>
                             <child>
@@ -292,7 +294,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="treeviewcolumn3">
+                          <object class="GtkTreeViewColumn" 
id="properties_treeviewcolumn3">
                             <property name="resizable">True</property>
                             <property name="title" translatable="yes" 
context="developmenttool|type">Type</property>
                             <child>
@@ -303,6 +305,18 @@
                             </child>
                           </object>
                         </child>
+                        <child>
+                          <object class="GtkTreeViewColumn" 
id="properties_treeviewcolumn4">
+                            <property name="resizable">True</property>
+                            <property name="title" translatable="yes" 
context="developmenttool|info">Info</property>
+                            <child>
+                              <object class="GtkCellRendererText" 
id="obj_insp_cellrenderertext5"/>
+                              <attributes>
+                                <attribute name="text">3</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to