inspector: Fix prop-list search

Instead of handle_event(), use set_key_capture_widget().

Also, use the fact that we now propagate key events throughout the
stage, and connect to the GtkInspectorPropList instead of the toplevel.
We only want the search bar to be active while that widget is mapped
and able to receive events.

And also, handle the "search bar" visibility on ::search-started.
This commit is contained in:
Carlos Garnacho 2019-04-03 13:11:44 +02:00
parent 9cb9843367
commit dc88a1ebc4

View File

@ -81,56 +81,11 @@ search_close_clicked (GtkWidget *button,
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title"); gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
} }
static gboolean
key_pressed (GtkEventController *controller,
guint keyval,
guint keycode,
GdkModifierType state,
GtkInspectorPropList *pl)
{
if (!gtk_widget_get_mapped (GTK_WIDGET (pl)))
return GDK_EVENT_PROPAGATE;
if (gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (pl->priv->search_entry),
gtk_get_current_event ()))
{
gtk_stack_set_visible_child (GTK_STACK (pl->priv->search_stack), pl->priv->search_entry);
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static void static void
destroy_controller (GtkEventController *controller) show_search_entry (GtkInspectorPropList *pl)
{ {
gtk_widget_remove_controller (gtk_event_controller_get_widget (controller), controller); gtk_stack_set_visible_child (GTK_STACK (pl->priv->search_stack),
} pl->priv->search_entry);
static void
root (GtkWidget *widget)
{
GtkEventController *controller;
GtkWidget *toplevel;
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->root (widget);
toplevel = gtk_widget_get_toplevel (widget);
controller = gtk_event_controller_key_new ();
g_object_set_data_full (G_OBJECT (toplevel), "prop-controller", controller, (GDestroyNotify)destroy_controller);
g_signal_connect (controller, "key-pressed", G_CALLBACK (key_pressed), widget);
gtk_widget_add_controller (toplevel, controller);
}
static void
unroot (GtkWidget *widget)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
g_object_set_data (G_OBJECT (toplevel), "prop-controller", NULL);
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unroot (widget);
} }
static void static void
@ -274,6 +229,11 @@ constructed (GObject *object)
g_signal_connect (pl->priv->search_entry, "stop-search", g_signal_connect (pl->priv->search_entry, "stop-search",
G_CALLBACK (search_close_clicked), pl); G_CALLBACK (search_close_clicked), pl);
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (pl->priv->search_entry),
GTK_WIDGET (pl->priv->tree));
g_signal_connect_swapped (pl->priv->search_entry, "search-started",
G_CALLBACK (show_search_entry), pl);
} }
static void static void
@ -287,9 +247,6 @@ gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->constructed = constructed; object_class->constructed = constructed;
widget_class->root = root;
widget_class->unroot = unroot;
g_object_class_install_property (object_class, PROP_OBJECT_TREE, g_object_class_install_property (object_class, PROP_OBJECT_TREE,
g_param_spec_object ("object-tree", "Object Tree", "Object tree", g_param_spec_object ("object-tree", "Object Tree", "Object tree",
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));