inspector: Improve search in property list
Use a search bar with a search entry instead of the builtin treeview search popup.
This commit is contained in:
@ -31,7 +31,9 @@
|
|||||||
|
|
||||||
#include "gtkcelllayout.h"
|
#include "gtkcelllayout.h"
|
||||||
#include "gtktreeview.h"
|
#include "gtktreeview.h"
|
||||||
|
#include "gtktreeselection.h"
|
||||||
#include "gtkpopover.h"
|
#include "gtkpopover.h"
|
||||||
|
#include "gtksearchbar.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -58,12 +60,62 @@ struct _GtkInspectorPropListPrivate
|
|||||||
gulong notify_handler_id;
|
gulong notify_handler_id;
|
||||||
GtkInspectorObjectTree *object_tree;
|
GtkInspectorObjectTree *object_tree;
|
||||||
gboolean child_properties;
|
gboolean child_properties;
|
||||||
|
GtkTreeViewColumn *name_column;
|
||||||
GtkTreeViewColumn *attribute_column;
|
GtkTreeViewColumn *attribute_column;
|
||||||
GtkWidget *tree;
|
GtkWidget *tree;
|
||||||
|
GtkWidget *search_entry;
|
||||||
|
GtkWidget *search_bar;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
key_press_event (GtkWidget *window,
|
||||||
|
GdkEvent *event,
|
||||||
|
GtkInspectorPropList *pl)
|
||||||
|
{
|
||||||
|
if (gtk_widget_get_mapped (GTK_WIDGET (pl)))
|
||||||
|
{
|
||||||
|
if (event->key.keyval == GDK_KEY_Return ||
|
||||||
|
event->key.keyval == GDK_KEY_ISO_Enter ||
|
||||||
|
event->key.keyval == GDK_KEY_KP_Enter)
|
||||||
|
{
|
||||||
|
GtkTreeSelection *selection;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GtkTreePath *path;
|
||||||
|
|
||||||
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pl->priv->tree));
|
||||||
|
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
||||||
|
{
|
||||||
|
path = gtk_tree_model_get_path (model, &iter);
|
||||||
|
gtk_tree_view_row_activated (GTK_TREE_VIEW (pl->priv->tree),
|
||||||
|
path,
|
||||||
|
pl->priv->name_column);
|
||||||
|
gtk_tree_path_free (path);
|
||||||
|
|
||||||
|
return GDK_EVENT_STOP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return gtk_search_bar_handle_event (GTK_SEARCH_BAR (pl->priv->search_bar), event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
hierarchy_changed (GtkWidget *widget,
|
||||||
|
GtkWidget *previous_toplevel)
|
||||||
|
{
|
||||||
|
if (previous_toplevel)
|
||||||
|
g_signal_handlers_disconnect_by_func (previous_toplevel, key_press_event, widget);
|
||||||
|
g_signal_connect (gtk_widget_get_toplevel (widget), "key-press-event",
|
||||||
|
G_CALLBACK (key_press_event), widget);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
|
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
|
||||||
{
|
{
|
||||||
@ -72,10 +124,14 @@ gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
|
|||||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pl->priv->model),
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pl->priv->model),
|
||||||
COLUMN_NAME,
|
COLUMN_NAME,
|
||||||
GTK_SORT_ASCENDING);
|
GTK_SORT_ASCENDING);
|
||||||
|
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (pl->priv->tree),
|
||||||
|
GTK_ENTRY (pl->priv->search_entry));
|
||||||
pl->priv->prop_iters = g_hash_table_new_full (g_str_hash,
|
pl->priv->prop_iters = g_hash_table_new_full (g_str_hash,
|
||||||
g_str_equal,
|
g_str_equal,
|
||||||
NULL,
|
NULL,
|
||||||
(GDestroyNotify) gtk_tree_iter_free);
|
(GDestroyNotify) gtk_tree_iter_free);
|
||||||
|
|
||||||
|
g_signal_connect (pl, "hierarchy-changed", G_CALLBACK (hierarchy_changed), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -226,6 +282,8 @@ gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
|
|||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, model);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, model);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, attribute_column);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, attribute_column);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, tree);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, tree);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, search_entry);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, search_bar);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, row_activated);
|
gtk_widget_class_bind_template_callback (widget_class, row_activated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,17 @@
|
|||||||
</object>
|
</object>
|
||||||
<template class="GtkInspectorPropList" parent="GtkBox">
|
<template class="GtkInspectorPropList" parent="GtkBox">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSearchBar" id="search_bar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSearchEntry" id="search_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="max-width-chars">40</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="GtkScrolledWindow">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -23,6 +34,8 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="model">model</property>
|
<property name="model">model</property>
|
||||||
<property name="tooltip-column">3</property>
|
<property name="tooltip-column">3</property>
|
||||||
|
<property name="search-column">0</property>
|
||||||
|
<property name="enable-search">True</property>
|
||||||
<signal name="row-activated" handler="row_activated"/>
|
<signal name="row-activated" handler="row_activated"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTreeViewColumn">
|
<object class="GtkTreeViewColumn">
|
||||||
|
|||||||
Reference in New Issue
Block a user