sysprof: categorize sidebar sections

This commit is contained in:
Christian Hergert
2023-07-10 14:04:20 -07:00
parent e6a769b386
commit 6f2a3ac74e
4 changed files with 75 additions and 6 deletions

View File

@ -25,6 +25,7 @@
typedef struct
{
char *category;
char *title;
SysprofSession *session;
} SysprofSectionPrivate;
@ -34,6 +35,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SysprofSection, sysprof_section, GTK_TYPE_W
enum {
PROP_0,
PROP_SESSION,
PROP_CATEGORY,
PROP_TITLE,
N_PROPS
};
@ -52,6 +54,7 @@ sysprof_section_dispose (GObject *object)
g_clear_object (&priv->session);
g_clear_pointer (&priv->title, g_free);
g_clear_pointer (&priv->category, g_free);
G_OBJECT_CLASS (sysprof_section_parent_class)->dispose (object);
}
@ -70,6 +73,10 @@ sysprof_section_get_property (GObject *object,
g_value_set_object (value, sysprof_section_get_session (self));
break;
case PROP_CATEGORY:
g_value_set_string (value, sysprof_section_get_category (self));
break;
case PROP_TITLE:
g_value_set_string (value, sysprof_section_get_title (self));
break;
@ -93,6 +100,10 @@ sysprof_section_set_property (GObject *object,
sysprof_section_set_session (self, g_value_get_object (value));
break;
case PROP_CATEGORY:
sysprof_section_set_category (self, g_value_get_string (value));
break;
case PROP_TITLE:
sysprof_section_set_title (self, g_value_get_string (value));
break;
@ -122,6 +133,11 @@ sysprof_section_class_init (SysprofSectionClass *klass)
NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties[PROP_CATEGORY] =
g_param_spec_string ("category", NULL, NULL,
NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
@ -176,3 +192,25 @@ sysprof_section_set_title (SysprofSection *self,
if (g_set_str (&priv->title, title))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
}
const char *
sysprof_section_get_category (SysprofSection *self)
{
SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self);
g_return_val_if_fail (SYSPROF_IS_SECTION (self), NULL);
return priv->category;
}
void
sysprof_section_set_category (SysprofSection *self,
const char *category)
{
SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self);
g_return_if_fail (SYSPROF_IS_SECTION (self));
if (g_set_str (&priv->category, category))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CATEGORY]);
}

View File

@ -35,11 +35,14 @@ struct _SysprofSectionClass
GtkWidgetClass parent_class;
};
SysprofSession *sysprof_section_get_session (SysprofSection *self);
void sysprof_section_set_session (SysprofSection *self,
SysprofSession *session);
const char *sysprof_section_get_title (SysprofSection *self);
void sysprof_section_set_title (SysprofSection *self,
const char *title);
SysprofSession *sysprof_section_get_session (SysprofSection *self);
void sysprof_section_set_session (SysprofSection *self,
SysprofSession *session);
const char *sysprof_section_get_category (SysprofSection *self);
void sysprof_section_set_category (SysprofSection *self,
const char *category);
const char *sysprof_section_get_title (SysprofSection *self);
void sysprof_section_set_title (SysprofSection *self,
const char *title);
G_END_DECLS

View File

@ -112,6 +112,24 @@ list_box_row_activated_cb (SysprofSidebar *self,
gtk_stack_set_visible_child (stack, GTK_WIDGET (section));
}
static void
sysprof_sidebar_header_func (GtkListBoxRow *row,
GtkListBoxRow *before_row,
gpointer user_data)
{
SysprofSection *section;
SysprofSection *before_section;
if (before_row == NULL)
return;
if ((section = g_object_get_data (G_OBJECT (row), "SECTION")) &&
(before_section = g_object_get_data (G_OBJECT (before_row), "SECTION")) &&
g_strcmp0 (sysprof_section_get_category (section),
sysprof_section_get_category (before_section)) != 0)
gtk_list_box_row_set_header (row, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
}
static void
sysprof_sidebar_dispose (GObject *object)
{
@ -203,4 +221,8 @@ sysprof_sidebar_init (SysprofSidebar *self)
G_CONNECT_SWAPPED);
gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (self->list_box,
sysprof_sidebar_header_func,
NULL, NULL);
}

View File

@ -99,6 +99,7 @@
<property name="vexpand">true</property>
<child>
<object class="SysprofSamplesSection">
<property name="category">callgraph</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
@ -106,6 +107,7 @@
</child>
<child>
<object class="SysprofLogsSection">
<property name="category">processes</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
@ -113,6 +115,7 @@
</child>
<child>
<object class="SysprofMarksSection">
<property name="category">processes</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
@ -120,6 +123,7 @@
</child>
<child>
<object class="SysprofProcessesSection">
<property name="category">processes</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
@ -127,6 +131,7 @@
</child>
<child>
<object class="SysprofFilesSection">
<property name="category">auxiliary</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
@ -134,6 +139,7 @@
</child>
<child>
<object class="SysprofMetadataSection">
<property name="category">auxiliary</property>
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>