From 98b84def812554e7abdb3dc0b7fe7329ff22fdcf Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 12 Jun 2023 12:31:25 -0700 Subject: [PATCH] libsysprof-gtk: allow sorting by function name --- .../sysprof-callgraph-view-private.h | 1 + src/libsysprof-gtk/sysprof-callgraph-view.c | 16 ++++++++++++++++ src/libsysprof-gtk/sysprof-callgraph-view.ui | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/libsysprof-gtk/sysprof-callgraph-view-private.h b/src/libsysprof-gtk/sysprof-callgraph-view-private.h index f120dc6c..61f7edf8 100644 --- a/src/libsysprof-gtk/sysprof-callgraph-view-private.h +++ b/src/libsysprof-gtk/sysprof-callgraph-view-private.h @@ -37,6 +37,7 @@ struct _SysprofCallgraphView GtkColumnView *callers_column_view; GtkColumnView *descendants_column_view; GtkColumnView *functions_column_view; + GtkCustomSorter *functions_name_sorter; GtkScrolledWindow *scrolled_window; GtkWidget *paned; diff --git a/src/libsysprof-gtk/sysprof-callgraph-view.c b/src/libsysprof-gtk/sysprof-callgraph-view.c index b6c79d4b..af44c3b8 100644 --- a/src/libsysprof-gtk/sysprof-callgraph-view.c +++ b/src/libsysprof-gtk/sysprof-callgraph-view.c @@ -215,6 +215,7 @@ sysprof_callgraph_view_class_init (SysprofCallgraphViewClass *klass) gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, callers_column_view); gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, descendants_column_view); gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, functions_column_view); + gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, functions_name_sorter); gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, paned); gtk_widget_class_bind_template_child (widget_class, SysprofCallgraphView, scrolled_window); gtk_widget_class_bind_template_callback (widget_class, sysprof_callgraph_view_key_pressed_cb); @@ -230,6 +231,18 @@ sysprof_callgraph_view_init (SysprofCallgraphView *self) gtk_widget_init_template (GTK_WIDGET (self)); } +static int +functions_name_compare (gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + SysprofCallgraphSymbol *sym_a = (SysprofCallgraphSymbol *)a; + SysprofCallgraphSymbol *sym_b = (SysprofCallgraphSymbol *)b; + + return g_strcmp0 (sysprof_symbol_get_name (sysprof_callgraph_symbol_get_symbol (sym_a)), + sysprof_symbol_get_name (sysprof_callgraph_symbol_get_symbol (sym_b))); +} + static GListModel * sysprof_callgraph_view_create_model_func (gpointer item, gpointer user_data) @@ -297,6 +310,9 @@ sysprof_callgraph_view_reload_cb (GObject *object, gtk_column_view_set_model (self->functions_column_view, GTK_SELECTION_MODEL (functions_selection)); + gtk_custom_sorter_set_sort_func (self->functions_name_sorter, + functions_name_compare, NULL, NULL); + if (SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->load) SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->load (self, callgraph); diff --git a/src/libsysprof-gtk/sysprof-callgraph-view.ui b/src/libsysprof-gtk/sysprof-callgraph-view.ui index 653e496e..7fb41325 100644 --- a/src/libsysprof-gtk/sysprof-callgraph-view.ui +++ b/src/libsysprof-gtk/sysprof-callgraph-view.ui @@ -17,6 +17,10 @@ Functions true + + + +