From 1dcd7af7e78f856f60bd6a06081aa90c5f639782 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 9 Jul 2023 14:38:17 -0700 Subject: [PATCH] sysprof: allow switching sections with sidebar --- src/sysprof/sysprof-sidebar.c | 32 ++++++++++++++++++++++++++++---- src/sysprof/sysprof-sidebar.ui | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/sysprof/sysprof-sidebar.c b/src/sysprof/sysprof-sidebar.c index a3f93b0b..50ca2d6f 100644 --- a/src/sysprof/sysprof-sidebar.c +++ b/src/sysprof/sysprof-sidebar.c @@ -47,16 +47,21 @@ sysprof_sidebar_create_row (gpointer item, GtkStackPage *page = item; SysprofSidebar *sidebar = user_data; SysprofSection *section; + GtkListBoxRow *row; g_assert (GTK_IS_STACK_PAGE (page)); g_assert (SYSPROF_IS_SIDEBAR (sidebar)); section = SYSPROF_SECTION (gtk_stack_page_get_child (page)); + row = g_object_new (GTK_TYPE_LIST_BOX_ROW, + "child", g_object_new (GTK_TYPE_LABEL, + "xalign", .0f, + "label", sysprof_section_get_title (section), + NULL), + NULL); + g_object_set_data_full (G_OBJECT (row), "SECTION", g_object_ref (section), g_object_unref); - return g_object_new (GTK_TYPE_LABEL, - "xalign", .0f, - "label", sysprof_section_get_title (section), - NULL); + return GTK_WIDGET (row); } static void @@ -89,6 +94,24 @@ sysprof_sidebar_unbind_cb (SysprofSidebar *self, gtk_list_box_bind_model (self->list_box, NULL, NULL, NULL, NULL); } +static void +list_box_row_activated_cb (SysprofSidebar *self, + GtkListBoxRow *row, + GtkListBox *list_box) +{ + SysprofSection *section; + g_autoptr(GtkStack) stack = NULL; + + g_assert (SYSPROF_IS_SIDEBAR (self)); + g_assert (GTK_IS_LIST_BOX_ROW (row)); + g_assert (GTK_IS_LIST_BOX (list_box)); + + if ((section = g_object_get_data (G_OBJECT (row), "SECTION")) && + SYSPROF_IS_SECTION (section) && + (stack = g_signal_group_dup_target (self->stack_signals))) + gtk_stack_set_visible_child (stack, GTK_WIDGET (section)); +} + static void sysprof_sidebar_dispose (GObject *object) { @@ -161,6 +184,7 @@ sysprof_sidebar_class_init (SysprofSidebarClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-sidebar.ui"); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_bind_template_child (widget_class, SysprofSidebar, list_box); + gtk_widget_class_bind_template_callback (widget_class, list_box_row_activated_cb); } static void diff --git a/src/sysprof/sysprof-sidebar.ui b/src/sysprof/sysprof-sidebar.ui index eaad6f77..d0ac9a68 100644 --- a/src/sysprof/sysprof-sidebar.ui +++ b/src/sysprof/sysprof-sidebar.ui @@ -6,6 +6,7 @@ never +