[gtk/prop-list: 2/2] inspector: Make prop list sortable again
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 2/2] inspector: Make prop list sortable again
- Date: Tue, 3 Dec 2019 19:16:11 +0000 (UTC)
commit 5c5addb0da44e33eea48838451fc5d30d74af042
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 3 02:27:43 2019 -0500
inspector: Make prop list sortable again
gtk/inspector/prop-list.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
gtk/inspector/prop-list.ui | 6 +++---
2 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c
index 5a49278d63..12213af619 100644
--- a/gtk/inspector/prop-list.c
+++ b/gtk/inspector/prop-list.c
@@ -67,6 +67,9 @@ struct _GtkInspectorPropListPrivate
GtkWidget *search_stack;
GtkWidget *list2;
GtkFilter *filter;
+ GtkColumnViewColumn *name;
+ GtkColumnViewColumn *type;
+ GtkColumnViewColumn *origin;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
@@ -87,7 +90,7 @@ show_search_entry (GtkInspectorPropList *pl)
}
static char *
-holder_prop (gpointer object)
+holder_prop (gpointer item)
{
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
@@ -114,6 +117,7 @@ static void
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
{
GtkExpression *expression;
+ GtkSorter *sorter;
pl->priv = gtk_inspector_prop_list_get_instance_private (pl);
gtk_widget_init_template (GTK_WIDGET (pl));
@@ -126,6 +130,36 @@ gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
NULL, NULL);
gtk_string_filter_set_expression (GTK_STRING_FILTER (pl->priv->filter), expression);
+
+ sorter = gtk_string_sorter_new ();
+ gtk_string_sorter_set_expression (GTK_STRING_SORTER (sorter), expression);
+ gtk_column_view_column_set_sorter (pl->priv->name, sorter);
+ g_object_unref (sorter);
+
+ gtk_expression_unref (expression);
+
+ expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
+ 0, NULL,
+ (GCallback)holder_type,
+ NULL, NULL);
+
+ sorter = gtk_string_sorter_new ();
+ gtk_string_sorter_set_expression (GTK_STRING_SORTER (sorter), expression);
+ gtk_column_view_column_set_sorter (pl->priv->type, sorter);
+ g_object_unref (sorter);
+
+ gtk_expression_unref (expression);
+
+ expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
+ 0, NULL,
+ (GCallback)holder_origin,
+ NULL, NULL);
+
+ sorter = gtk_string_sorter_new ();
+ gtk_string_sorter_set_expression (GTK_STRING_SORTER (sorter), expression);
+ gtk_column_view_column_set_sorter (pl->priv->origin, sorter);
+ g_object_unref (sorter);
+
gtk_expression_unref (expression);
}
@@ -423,6 +457,9 @@ gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/prop-list.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, list2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, name);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, type);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, origin);
gtk_widget_class_bind_template_callback (widget_class, setup_name_cb);
gtk_widget_class_bind_template_callback (widget_class, bind_name_cb);
gtk_widget_class_bind_template_callback (widget_class, setup_type_cb);
@@ -556,6 +593,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
GListStore *store;
GListModel *list;
GListModel *filtered;
+ GtkSortListModel *sorted;
if (!object)
return FALSE;
@@ -593,13 +631,16 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), pl->priv->filter));
- list = G_LIST_MODEL (gtk_no_selection_new (filtered));
+ sorted = gtk_sort_list_model_new (filtered, NULL);
+ list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list2), list);
+ gtk_column_view_set_sort_model (GTK_COLUMN_VIEW (pl->priv->list2), sorted);
gtk_widget_show (GTK_WIDGET (pl));
g_object_unref (list);
+ g_object_unref (sorted);
g_object_unref (filtered);
g_object_unref (store);
diff --git a/gtk/inspector/prop-list.ui b/gtk/inspector/prop-list.ui
index 35457f484d..2c0537fb29 100644
--- a/gtk/inspector/prop-list.ui
+++ b/gtk/inspector/prop-list.ui
@@ -15,7 +15,7 @@
<child>
<object class="GtkColumnView" id="list2">
<child>
- <object class="GtkColumnViewColumn">
+ <object class="GtkColumnViewColumn" id="name">
<property name="title">Name</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
@@ -26,7 +26,7 @@
</object>
</child>
<child>
- <object class="GtkColumnViewColumn">
+ <object class="GtkColumnViewColumn" id="type">
<property name="title">Type</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
@@ -37,7 +37,7 @@
</object>
</child>
<child>
- <object class="GtkColumnViewColumn">
+ <object class="GtkColumnViewColumn" id="origin">
<property name="title">Defined At</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]