[gtk] inspector: Highlight CSS node on selection



commit 0657a539404c2fc00c56211c935fdba9a01b4fe2
Author: Benjamin Otte <otte redhat com>
Date:   Fri Oct 5 22:07:07 2018 +0200

    inspector: Highlight CSS node on selection
    
    Fixes #1383

 gtk/inspector/css-node-tree.c | 71 ++++++++++++++++++++++++++++++++++++++++++-
 gtk/inspector/css-node-tree.h |  8 +++--
 gtk/inspector/window.c        | 37 ++++++++++++++++++----
 gtk/inspector/window.ui       |  4 ++-
 4 files changed, 109 insertions(+), 11 deletions(-)
---
diff --git a/gtk/inspector/css-node-tree.c b/gtk/inspector/css-node-tree.c
index fa9fcc24fe..4d38356d3f 100644
--- a/gtk/inspector/css-node-tree.c
+++ b/gtk/inspector/css-node-tree.c
@@ -62,6 +62,14 @@ enum
   COLUMN_PROP_LOCATION
 };
 
+enum
+{
+  PROP_0,
+  PROP_NODE,
+
+  N_PROPS
+};
+
 struct _GtkInspectorCssNodeTreePrivate
 {
   GtkWidget *node_tree;
@@ -76,6 +84,8 @@ struct _GtkInspectorCssNodeTreePrivate
   GtkCssNode *node;
 };
 
+static GParamSpec *properties[N_PROPS] = { NULL, };
+
 G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssNodeTree, gtk_inspector_css_node_tree, GTK_TYPE_BOX)
 
 typedef struct {
@@ -168,6 +178,41 @@ gtk_inspector_css_node_tree_unset_node (GtkInspectorCssNodeTree *cnt)
     }
 }
 
+static void
+gtk_inspector_css_node_tree_get_property (GObject    *object,
+                                          guint       property_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec)
+{
+  GtkInspectorCssNodeTree *cnt = GTK_INSPECTOR_CSS_NODE_TREE (object);
+  GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
+
+  switch (property_id)
+    {
+    case PROP_NODE:
+      g_value_set_object (value, priv->node);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_inspector_css_node_tree_set_property (GObject      *object,
+                                          guint         property_id,
+                                          const GValue *value,
+                                          GParamSpec   *pspec)
+{
+  switch (property_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
 static void
 gtk_inspector_css_node_tree_finalize (GObject *object)
 {
@@ -202,8 +247,19 @@ gtk_inspector_css_node_tree_class_init (GtkInspectorCssNodeTreeClass *klass)
 
   ensure_css_sections ();
 
+  object_class->set_property = gtk_inspector_css_node_tree_set_property;
+  object_class->get_property = gtk_inspector_css_node_tree_get_property;
   object_class->finalize = gtk_inspector_css_node_tree_finalize;
 
+  properties[PROP_NODE] =
+    g_param_spec_object ("node",
+                         "Node",
+                         "Currently inspected CSS node",
+                         GTK_TYPE_CSS_NODE,
+                         G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/css-node-tree.ui");
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_tree);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_name_column);
@@ -458,8 +514,21 @@ gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
   gtk_inspector_css_node_tree_unset_node (cnt);
 
   priv->node = node;
+  if (node)
+    {
+      g_signal_connect (node, "style-changed", G_CALLBACK (gtk_inspector_css_node_tree_update_style_cb), 
cnt);
+    }
 
-  g_signal_connect (node, "style-changed", G_CALLBACK (gtk_inspector_css_node_tree_update_style_cb), cnt);
+  g_object_notify_by_pspec (G_OBJECT (cnt), properties[PROP_NODE]);
 }
 
+GtkCssNode *
+gtk_inspector_css_node_tree_get_node (GtkInspectorCssNodeTree *cnt)
+{
+  GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
+
+  return priv->node;
+}
+
+// vim: set et sw=2 ts=2:
 // vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/css-node-tree.h b/gtk/inspector/css-node-tree.h
index 8de2c8e6b8..e1357a7dcb 100644
--- a/gtk/inspector/css-node-tree.h
+++ b/gtk/inspector/css-node-tree.h
@@ -50,9 +50,11 @@ typedef struct _GtkInspectorCssNodeTreeClass
 
 G_BEGIN_DECLS
 
-GType      gtk_inspector_css_node_tree_get_type       (void);
-void       gtk_inspector_css_node_tree_set_object     (GtkInspectorCssNodeTree *cnt,
-                                                       GObject                 *object);
+GType           gtk_inspector_css_node_tree_get_type            (void);
+void            gtk_inspector_css_node_tree_set_object          (GtkInspectorCssNodeTree        *cnt,
+                                                                 GObject                        *object);
+
+GtkCssNode *    gtk_inspector_css_node_tree_get_node            (GtkInspectorCssNodeTree        *cnt);
 
 G_END_DECLS
 
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index 5f4c1eb07f..3239cd5770 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -44,16 +44,17 @@
 #include "magnifier.h"
 #include "recorder.h"
 
-#include "gtklabel.h"
+#include "gdk-private.h"
+#include "gskrendererprivate.h"
 #include "gtkbutton.h"
+#include "gtkcsswidgetnodeprivate.h"
+#include "gtklabel.h"
+#include "gtkmodulesprivate.h"
+#include "gtkprivate.h"
 #include "gtkstack.h"
 #include "gtktreeviewcolumn.h"
-#include "gtkmodulesprivate.h"
-#include "gtkwindowprivate.h"
 #include "gtkwindowgroup.h"
-#include "gtkprivate.h"
-#include "gdk-private.h"
-#include "gskrendererprivate.h"
+#include "gtkwindowprivate.h"
 
 G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
 
@@ -118,6 +119,29 @@ on_object_selected (GtkInspectorObjectTree *wt,
     gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
 }
 
+static void
+notify_node (GtkInspectorCssNodeTree *cnt,
+             GParamSpec              *pspec,
+             GtkInspectorWindow      *iw)
+{
+  GtkCssNode *node;
+  GtkWidget *widget = NULL;
+
+  for (node = gtk_inspector_css_node_tree_get_node (cnt);
+       node != NULL;
+       node = gtk_css_node_get_parent (node))
+    {
+      if (!GTK_IS_CSS_WIDGET_NODE (node))
+        continue;
+
+      widget = gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (node));
+      if (widget != NULL)
+        break;
+    }
+  if (widget)
+    gtk_inspector_flash_widget (iw, widget);
+}
+
 static void
 close_object_details (GtkWidget *button, GtkInspectorWindow *iw)
 {
@@ -296,6 +320,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, open_object_details);
   gtk_widget_class_bind_template_callback (widget_class, close_object_details);
   gtk_widget_class_bind_template_callback (widget_class, object_details_changed);
+  gtk_widget_class_bind_template_callback (widget_class, notify_node);
 }
 
 static GdkDisplay *
diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui
index 67b97fb0cb..73a945dc97 100644
--- a/gtk/inspector/window.ui
+++ b/gtk/inspector/window.ui
@@ -330,7 +330,9 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkInspectorCssNodeTree" id="widget_css_node_tree"/>
+                      <object class="GtkInspectorCssNodeTree" id="widget_css_node_tree">
+                        <signal name="notify::node" handler="notify_node"/>
+                      </object>
                       <packing>
                         <property name="name">css-nodes</property>
                         <property name="title" translatable="yes">CSS Nodes</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]