include/sfx2/devtools/ObjectInspectorTreeHandler.hxx |    3 +
 sfx2/UIConfig_sfx.mk                                 |    1 
 sfx2/source/devtools/ObjectInspectorTreeHandler.cxx  |   42 +++++++++++++++++++
 sfx2/uiconfig/ui/devtoolsmenu.ui                     |   17 +++++++
 4 files changed, 63 insertions(+)

New commits:
commit c68631373e491936260f2e3b4abc9826d634e410
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Feb 23 22:54:06 2021 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Feb 26 08:05:21 2021 +0100

    devtools: add popup menu for properties to inspect objects
    
    With this change it is possible to inspect an object that is
    listed in the properties (instead of expanding the tree view
    node).
    
    Change-Id: I8b2229af650b46064c82bdd3fe93192d352d32e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111530
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx 
b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx
index 9bb27e4a72cc..7008a398df5a 100644
--- a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx
+++ b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx
@@ -12,6 +12,8 @@
 
 #include <sfx2/dllapi.h>
 #include <vcl/weld.hxx>
+#include <vcl/commandevent.hxx>
+#include <vcl/svapp.hxx>
 
 #include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/uno/Reference.hxx>
@@ -48,6 +50,7 @@ public:
     DECL_LINK(ExpandingHandlerServices, const weld::TreeIter&, bool);
     DECL_LINK(ExpandingHandlerProperties, const weld::TreeIter&, bool);
     DECL_LINK(ExpandingHandlerMethods, const weld::TreeIter&, bool);
+    DECL_LINK(PopupMenuHandler, const CommandEvent&, bool);
 
     void introspect(css::uno::Reference<css::uno::XInterface> const& 
xInterface);
 
diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk
index ac2a3f8c9010..7bdbd7a85a1e 100644
--- a/sfx2/UIConfig_sfx.mk
+++ b/sfx2/UIConfig_sfx.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\
        sfx2/uiconfig/ui/decktitlebar \
        sfx2/uiconfig/ui/descriptioninfopage \
        sfx2/uiconfig/ui/developmenttool \
+       sfx2/uiconfig/ui/devtoolsmenu \
        sfx2/uiconfig/ui/documentfontspage \
        sfx2/uiconfig/ui/documentinfopage \
        sfx2/uiconfig/ui/documentpropertiesdialog \
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx 
b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index 98ed6cd2bae4..52e6111a65f4 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -367,6 +367,8 @@ public:
     {
     }
 
+    uno::Any getAny() { return maAny; }
+
     bool shouldShowExpander() override
     {
         if (maAny.hasValue())
@@ -607,6 +609,9 @@ ObjectInspectorTreeHandler::ObjectInspectorTreeHandler(
         LINK(this, ObjectInspectorTreeHandler, ExpandingHandlerProperties));
     mpMethodsTreeView->connect_expanding(
         LINK(this, ObjectInspectorTreeHandler, ExpandingHandlerMethods));
+
+    mpPropertiesTreeView->connect_popup_menu(
+        LINK(this, ObjectInspectorTreeHandler, PopupMenuHandler));
 }
 
 void 
ObjectInspectorTreeHandler::handleExpanding(std::unique_ptr<weld::TreeView>& 
pTreeView,
@@ -648,6 +653,43 @@ IMPL_LINK(ObjectInspectorTreeHandler, 
ExpandingHandlerMethods, weld::TreeIter co
     return true;
 }
 
+IMPL_LINK(ObjectInspectorTreeHandler, PopupMenuHandler, const CommandEvent&, 
rCommandEvent, bool)
+{
+    if (rCommandEvent.GetCommand() != CommandEventId::ContextMenu)
+        return false;
+
+    uno::Any aAny;
+    OUString sID = mpPropertiesTreeView->get_selected_id();
+    if (sID.isEmpty())
+        return false;
+
+    auto* pNode = 
reinterpret_cast<ObjectInspectorNodeInterface*>(sID.toInt64());
+    if (pNode)
+    {
+        auto* pBasicValueNode = dynamic_cast<BasicValueNode*>(pNode);
+        if (pBasicValueNode)
+        {
+            aAny = pBasicValueNode->getAny();
+            uno::Reference<uno::XInterface> xInterface(aAny, uno::UNO_QUERY);
+            if (xInterface.is())
+            {
+                std::unique_ptr<weld::Builder> 
xBuilder(Application::CreateBuilder(
+                    mpPropertiesTreeView.get(), "sfx/ui/devtoolsmenu.ui"));
+                std::unique_ptr<weld::Menu> 
xMenu(xBuilder->weld_menu("inspect_menu"));
+
+                OString sCommand(xMenu->popup_at_rect(
+                    mpPropertiesTreeView.get(),
+                    tools::Rectangle(rCommandEvent.GetMousePosPixel(), Size(1, 
1))));
+                if (sCommand == "inspect")
+                {
+                    introspect(xInterface);
+                }
+            }
+        }
+    }
+    return true;
+}
+
 void ObjectInspectorTreeHandler::clearObjectInspectorChildren(
     std::unique_ptr<weld::TreeView>& pTreeView, weld::TreeIter const& rParent)
 {
diff --git a/sfx2/uiconfig/ui/devtoolsmenu.ui b/sfx2/uiconfig/ui/devtoolsmenu.ui
new file mode 100644
index 000000000000..608de5bd2639
--- /dev/null
+++ b/sfx2/uiconfig/ui/devtoolsmenu.ui
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="svx">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="inspect_menu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+    <child>
+      <object class="GtkMenuItem" id="inspect">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="devtoolsmenu|inspect">Inspect</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+  </object>
+</interface>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to