[Libreoffice-commits] core.git: svx/source svx/uiconfig

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 10 13:15:47 UTC 2021


 svx/source/devtools/DevelopmentToolDockingWindow.cxx |  195 +++++++++++++++++--
 svx/uiconfig/ui/developmenttool.ui                   |   24 +-
 2 files changed, 203 insertions(+), 16 deletions(-)

New commits:
commit e71350e037dcd49f24c939395ab6436051382c83
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Feb 1 15:42:54 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Feb 10 14:15:04 2021 +0100

    devtools: add values for properties in object inspector tree view
    
    Change-Id: Ia53ea2cbc9797cd787d1ea3d841f947a515055e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110251
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
index 40e5bcc76857..da3b8d5896b5 100644
--- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx
+++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
@@ -21,6 +21,10 @@
 #include <com/sun/star/beans/Property.hpp>
 #include <com/sun/star/beans/PropertyConcept.hpp>
 #include <com/sun/star/beans/MethodConcept.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <com/sun/star/reflection/theCoreReflection.hpp>
+#include <com/sun/star/reflection/XIdlReflection.hpp>
 #include <com/sun/star/reflection/XIdlMethod.hpp>
 
 #include <comphelper/processfactory.hxx>
@@ -193,6 +197,156 @@ void DevelopmentToolDockingWindow::selectionChanged(
     updateSelection();
 }
 
+namespace
+{
+uno::Reference<reflection::XIdlClass>
+TypeToIdlClass(const uno::Type& rType, const uno::Reference<uno::XComponentContext>& xContext)
+{
+    auto xReflection = reflection::theCoreReflection::get(xContext);
+
+    uno::Reference<reflection::XIdlClass> xRetClass;
+    typelib_TypeDescription* pTD = nullptr;
+    rType.getDescription(&pTD);
+    if (pTD)
+    {
+        OUString sOWName(pTD->pTypeName);
+        xRetClass = xReflection->forName(sOWName);
+    }
+    return xRetClass;
+}
+
+OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponentContext>& xContext)
+{
+    uno::Type aValType = aValue.getValueType();
+    uno::TypeClass eType = aValType.getTypeClass();
+
+    OUString aRetStr;
+    switch (eType)
+    {
+        case uno::TypeClass_TYPE:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <TYPE>";
+            break;
+        }
+        case uno::TypeClass_INTERFACE:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <INTERFACE>";
+            break;
+        }
+        case uno::TypeClass_SERVICE:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <SERVICE>";
+            break;
+        }
+        case uno::TypeClass_STRUCT:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <STRUCT>";
+            break;
+        }
+        case uno::TypeClass_TYPEDEF:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <TYPEDEF>";
+            break;
+        }
+        case uno::TypeClass_ENUM:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <ENUM>";
+            break;
+        }
+        case uno::TypeClass_EXCEPTION:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <EXCEPTION>";
+            break;
+        }
+        case uno::TypeClass_SEQUENCE:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <SEQUENCE>";
+            break;
+        }
+        case uno::TypeClass_VOID:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <VOID>";
+            break;
+        }
+        case uno::TypeClass_ANY:
+        {
+            auto xIdlClass = TypeToIdlClass(aValType, xContext);
+            aRetStr = xIdlClass->getName() + " <ANY>";
+            break;
+        }
+        case uno::TypeClass_UNKNOWN:
+            aRetStr = "<Unknown>";
+            break;
+        case uno::TypeClass_BOOLEAN:
+        {
+            bool bBool = aValue.get<bool>();
+            aRetStr = bBool ? u"True" : u"False";
+            break;
+        }
+        case uno::TypeClass_CHAR:
+        {
+            sal_Unicode aChar = aValue.get<sal_Unicode>();
+            aRetStr = OUString::number(aChar);
+            break;
+        }
+        case uno::TypeClass_STRING:
+        {
+            aRetStr = "\"" + aValue.get<OUString>() + "\"";
+            break;
+        }
+        case uno::TypeClass_FLOAT:
+        {
+            auto aNumber = aValue.get<float>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+        case uno::TypeClass_DOUBLE:
+        {
+            auto aNumber = aValue.get<double>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+        case uno::TypeClass_BYTE:
+        {
+            auto aNumber = aValue.get<sal_Int8>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+        case uno::TypeClass_SHORT:
+        {
+            auto aNumber = aValue.get<sal_Int16>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+        case uno::TypeClass_LONG:
+        {
+            auto aNumber = aValue.get<sal_Int32>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+        case uno::TypeClass_HYPER:
+        {
+            auto aNumber = aValue.get<sal_Int64>();
+            aRetStr = OUString::number(aNumber);
+            break;
+        }
+
+        default:
+            break;
+    }
+    return aRetStr;
+}
+}
+
 void DevelopmentToolDockingWindow::introspect(uno::Reference<uno::XInterface> const& xInterface)
 {
     if (!xInterface.is())
@@ -230,19 +384,38 @@ void DevelopmentToolDockingWindow::introspect(uno::Reference<uno::XInterface> co
 
     uno::Reference<beans::XIntrospectionAccess> xIntrospectionAccess;
     xIntrospectionAccess = xIntrospection->inspect(uno::makeAny(xInterface));
+    {
+        OUString aPropertiesString("Properties");
 
-    OUString aPropertiesString("Properties");
-    mpClassListBox->insert(nullptr, -1, &aPropertiesString, nullptr, nullptr, nullptr, false,
-                           pParent.get());
-    mpClassListBox->set_text_emphasis(*pParent, true, 0);
+        mpClassListBox->insert(nullptr, -1, &aPropertiesString, nullptr, nullptr, nullptr, false,
+                               pParent.get());
+        mpClassListBox->set_text_emphasis(*pParent, true, 0);
 
-    const auto xProperties = xIntrospectionAccess->getProperties(
-        beans::PropertyConcept::ALL - beans::PropertyConcept::DANGEROUS);
-    for (auto const& xProperty : xProperties)
-    {
-        mpClassListBox->insert(pParent.get(), -1, &xProperty.Name, nullptr, nullptr, nullptr, false,
-                               pResult.get());
-        mpClassListBox->set_text_emphasis(*pResult, false, 0);
+        uno::Reference<beans::XPropertySet> xPropertySet(xInterface, uno::UNO_QUERY);
+
+        const auto xProperties = xIntrospectionAccess->getProperties(
+            beans::PropertyConcept::ALL - beans::PropertyConcept::DANGEROUS);
+        for (auto const& xProperty : xProperties)
+        {
+            mpClassListBox->insert(pParent.get(), -1, &xProperty.Name, nullptr, nullptr, nullptr,
+                                   false, pResult.get());
+
+            if (xPropertySet.is())
+            {
+                OUString aValue;
+                try
+                {
+                    uno::Any aAny = xPropertySet->getPropertyValue(xProperty.Name);
+                    aValue = AnyToString(aAny, xContext);
+                }
+                catch (const beans::UnknownPropertyException&)
+                {
+                    aValue = "UnknownPropertyException";
+                }
+
+                mpClassListBox->set_text(*pResult, aValue, 1);
+            }
+        }
     }
 
     {
diff --git a/svx/uiconfig/ui/developmenttool.ui b/svx/uiconfig/ui/developmenttool.ui
index 8310d0fffae8..e3f3bc78e9e8 100644
--- a/svx/uiconfig/ui/developmenttool.ui
+++ b/svx/uiconfig/ui/developmenttool.ui
@@ -2,7 +2,7 @@
 <!-- Generated with glade 3.38.2 -->
 <interface domain="svx">
   <requires lib="gtk+" version="3.20"/>
-  <object class="GtkTreeStore" id="liststore">
+  <object class="GtkTreeStore" id="liststore1">
     <columns>
       <!-- column-name text -->
       <column type="gchararray"/>
@@ -10,10 +10,12 @@
       <column type="gchararray"/>
     </columns>
   </object>
-  <object class="GtkTreeStore" id="liststore1">
+  <object class="GtkTreeStore" id="object_inspector_liststore">
     <columns>
       <!-- column-name text -->
       <column type="gchararray"/>
+      <!-- column-name value -->
+      <column type="gchararray"/>
       <!-- column-name id -->
       <column type="gchararray"/>
     </columns>
@@ -156,7 +158,7 @@
                     <property name="receives-default">True</property>
                     <property name="hexpand">True</property>
                     <property name="vexpand">True</property>
-                    <property name="model">liststore</property>
+                    <property name="model">object_inspector_liststore</property>
                     <property name="search-column">0</property>
                     <property name="enable-tree-lines">True</property>
                     <child internal-child="selection">
@@ -165,9 +167,9 @@
                     <child>
                       <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                         <property name="resizable">True</property>
-                        <property name="title" translatable="yes" context="developmenttool|class">Class</property>
+                        <property name="title" translatable="yes" context="developmenttool|object">Object</property>
                         <child>
-                          <object class="GtkCellRendererText" id="cellrenderertext1">
+                          <object class="GtkCellRendererText" id="obj_insp_cellrenderertext1">
                             <property name="ellipsize">end</property>
                           </object>
                           <attributes>
@@ -177,6 +179,18 @@
                         </child>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+                        <property name="resizable">True</property>
+                        <property name="title" translatable="yes" context="developmenttool|value">Value</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="obj_insp_cellrenderertext2"/>
+                          <attributes>
+                            <attribute name="text">1</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>


More information about the Libreoffice-commits mailing list