[gtk] inspector: Fix editing in the property list



commit 9a1da43890d4e5187c5ea33c6d0b7b52376e1778
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Apr 12 19:48:23 2019 -0400

    inspector: Fix editing in the property list
    
    The type-to-search was interfering with using
    entries in the list. Avoid that by watching
    where the focus is.

 gtk/inspector/prop-list.c | 56 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c
index f1cbeb23b8..895b774ec4 100644
--- a/gtk/inspector/prop-list.c
+++ b/gtk/inspector/prop-list.c
@@ -41,6 +41,7 @@
 #include "gtklayoutmanager.h"
 #include "gtklistbox.h"
 #include "gtksizegroup.h"
+#include "gtkroot.h"
 
 enum
 {
@@ -199,27 +200,64 @@ constructed (GObject *object)
 }
 
 static void
-map (GtkWidget *widget)
+update_key_capture (GtkInspectorPropList *pl)
 {
-  GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (widget);
-  GtkWidget *toplevel;
+  GtkWidget *capture_widget;
+
+  if (gtk_widget_get_mapped (GTK_WIDGET (pl)))
+    {
+      GtkWidget *toplevel;
+      GtkWidget *focus;
+
+      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (pl));
+      focus = gtk_root_get_focus (GTK_ROOT (toplevel));
+
+      if (GTK_IS_EDITABLE (focus) &&
+          gtk_widget_is_ancestor (focus, pl->priv->list2))
+        capture_widget = NULL;
+      else
+        capture_widget = toplevel;
+    }
+  else
+    capture_widget = NULL;
+
+  gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (pl->priv->search_entry),
+                                           capture_widget);
+}
 
+static void
+map (GtkWidget *widget)
+{
   GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->map (widget);
 
-  toplevel = gtk_widget_get_toplevel (widget);
-  gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (pl->priv->search_entry), toplevel);
+  update_key_capture (GTK_INSPECTOR_PROP_LIST (widget));
 }
 
 static void
 unmap (GtkWidget *widget)
 {
-  GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (widget);
+  GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unmap (widget);
 
-  gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (pl->priv->search_entry), NULL);
+  update_key_capture (GTK_INSPECTOR_PROP_LIST (widget));
+}
 
-  GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unmap (widget);
+static void
+root (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->root (widget);
+
+  g_signal_connect_swapped (gtk_widget_get_root (widget), "notify::focus-widget",
+                            G_CALLBACK (update_key_capture), widget);
 }
 
+static void
+unroot (GtkWidget *widget)
+{
+  g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
+                                        update_key_capture, widget);
+
+  GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unroot (widget);
+}
 
 static void
 gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
@@ -234,6 +272,8 @@ gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
 
   widget_class->map = map;
   widget_class->unmap = unmap;
+  widget_class->root = root;
+  widget_class->unroot = unroot;
 
   g_object_class_install_property (object_class, PROP_OBJECT_TREE,
       g_param_spec_object ("object-tree", "Object Tree", "Object tree",


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