[gnome-builder] libide/tweaks: move IdeTweaksPanelList towards single use
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: move IdeTweaksPanelList towards single use
- Date: Tue, 2 Aug 2022 20:05:04 +0000 (UTC)
commit c04d5c28e136aeb443865850237e3778868eff57
Author: Christian Hergert <chergert redhat com>
Date: Tue Aug 2 13:04:56 2022 -0700
libide/tweaks: move IdeTweaksPanelList towards single use
Instead of having the list be usable for many items, I'd rather manage it
similar to managing the IdeTweaksPanel from the window, where we make
one for each level and just add/remove as necessary.
src/libide/tweaks/ide-tweaks-panel-list-private.h | 7 +--
src/libide/tweaks/ide-tweaks-panel-list.c | 45 ++++++++++++++--
src/libide/tweaks/ide-tweaks-panel-list.ui | 18 +++----
src/libide/tweaks/ide-tweaks-window.c | 63 ++++++++++++++++++++---
src/libide/tweaks/ide-tweaks-window.ui | 16 ++----
5 files changed, 113 insertions(+), 36 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel-list-private.h
b/src/libide/tweaks/ide-tweaks-panel-list-private.h
index c21cc26ef..75840b815 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list-private.h
+++ b/src/libide/tweaks/ide-tweaks-panel-list-private.h
@@ -30,8 +30,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeTweaksPanelList, ide_tweaks_panel_list, IDE, TWEAKS_PANEL_LIST, AdwBin)
-GtkWidget *ide_tweaks_panel_list_new (void);
-void ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
- IdeTweaksItem *item);
+GtkWidget *ide_tweaks_panel_list_new (void);
+IdeTweaksItem *ide_tweaks_panel_list_get_item (IdeTweaksPanelList *self);
+void ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
+ IdeTweaksItem *item);
G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.c b/src/libide/tweaks/ide-tweaks-panel-list.c
index 99452e745..427a5853d 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.c
+++ b/src/libide/tweaks/ide-tweaks-panel-list.c
@@ -26,12 +26,16 @@
struct _IdeTweaksPanelList
{
- AdwBin parent_instance;
- GtkStack *stack;
+ AdwBin parent_instance;
+
+ IdeTweaksItem *item;
+
+ GtkListBox *list_box;
};
enum {
PROP_0,
+ PROP_ITEM,
N_PROPS
};
@@ -44,6 +48,8 @@ ide_tweaks_panel_list_dispose (GObject *object)
{
IdeTweaksPanelList *self = (IdeTweaksPanelList *)object;
+ g_clear_object (&self->item);
+
G_OBJECT_CLASS (ide_tweaks_panel_list_parent_class)->dispose (object);
}
@@ -57,6 +63,10 @@ ide_tweaks_panel_list_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_ITEM:
+ g_value_set_object (value, ide_tweaks_panel_list_get_item (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -72,6 +82,10 @@ ide_tweaks_panel_list_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_ITEM:
+ ide_tweaks_panel_list_set_item (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -87,8 +101,13 @@ ide_tweaks_panel_list_class_init (IdeTweaksPanelListClass *klass)
object_class->get_property = ide_tweaks_panel_list_get_property;
object_class->set_property = ide_tweaks_panel_list_set_property;
+ properties [PROP_ITEM] =
+ g_param_spec_object ("item", NULL, NULL,
+ IDE_TYPE_TWEAKS_ITEM,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/libide-tweaks/ide-tweaks-panel-list.ui");
- gtk_widget_class_bind_template_child (widget_class, IdeTweaksPanelList, stack);
+ gtk_widget_class_bind_template_child (widget_class, IdeTweaksPanelList, list_box);
}
static void
@@ -103,6 +122,22 @@ ide_tweaks_panel_list_new (void)
return g_object_new (IDE_TYPE_TWEAKS_PANEL_LIST, NULL);
}
+/**
+ * ide_tweaks_panel_list_get_item:
+ *
+ * Gets the parent item of the panel list. Children of this
+ * item are what are displayed in the panel list.
+ *
+ * Returns: (transfer none) (nullable): an #IdeTweaksItem or %NULL
+ */
+IdeTweaksItem *
+ide_tweaks_panel_list_get_item (IdeTweaksPanelList *self)
+{
+ g_return_val_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self), NULL);
+
+ return self->item;
+}
+
void
ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
IdeTweaksItem *item)
@@ -110,4 +145,8 @@ ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
g_return_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self));
g_return_if_fail (IDE_IS_TWEAKS_ITEM (item));
+ if (g_set_object (&self->item, item))
+ {
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ITEM]);
+ }
}
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.ui b/src/libide/tweaks/ide-tweaks-panel-list.ui
index 67eb9d7be..48b59b133 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.ui
+++ b/src/libide/tweaks/ide-tweaks-panel-list.ui
@@ -2,19 +2,13 @@
<interface>
<template class="IdeTweaksPanelList" parent="AdwBin">
<child>
- <object class="GtkStack" id="stack">
- <property name="vhomogeneous">False</property>
- <property name="hhomogeneous">True</property>
- <property name="transition-type">slide-left-right</property>
+ <object class="GtkScrolledWindow">
+ <property name="hscrollbar-policy">never</property>
<child>
- <object class="GtkStackPage">
- <property name="child">
- <object class="GtkListBox" id="main_list">
- <style>
- <class name="navigation-sidebar"/>
- </style>
- </object>
- </property>
+ <object class="GtkListBox" id="list_box">
+ <style>
+ <class name="navigation-sidebar"/>
+ </style>
</object>
</child>
</object>
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 6c4ee615d..10aa8e09e 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -29,8 +29,11 @@
struct _IdeTweaksWindow
{
AdwWindow parent_instance;
+
IdeTweaks *tweaks;
- IdeTweaksPanelList *list;
+
+ GtkStack *panel_stack;
+ GtkStack *panel_list_stack;
};
enum {
@@ -43,12 +46,47 @@ G_DEFINE_FINAL_TYPE (IdeTweaksWindow, ide_tweaks_window, ADW_TYPE_WINDOW)
static GParamSpec *properties [N_PROPS];
+static void
+ide_tweaks_window_clear (IdeTweaksWindow *self)
+{
+ GtkWidget *child;
+
+ g_assert (IDE_IS_TWEAKS_WINDOW (self));
+ g_assert (IDE_IS_TWEAKS (self->tweaks));
+
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->panel_list_stack))))
+ gtk_stack_remove (self->panel_list_stack, child);
+
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->panel_stack))))
+ gtk_stack_remove (self->panel_stack, child);
+}
+
+static void
+ide_tweaks_window_rebuild (IdeTweaksWindow *self)
+{
+ GtkWidget *list;
+
+ g_assert (IDE_IS_TWEAKS_WINDOW (self));
+ g_assert (IDE_IS_TWEAKS (self->tweaks));
+
+ list = ide_tweaks_panel_list_new ();
+ ide_tweaks_panel_list_set_item (IDE_TWEAKS_PANEL_LIST (list),
+ IDE_TWEAKS_ITEM (self->tweaks));
+ gtk_stack_add_named (self->panel_list_stack,
+ list,
+ ide_tweaks_item_get_id (IDE_TWEAKS_ITEM (self->tweaks)));
+}
+
static void
ide_tweaks_window_dispose (GObject *object)
{
IdeTweaksWindow *self = (IdeTweaksWindow *)object;
- g_clear_object (&self->tweaks);
+ if (self->tweaks)
+ {
+ ide_tweaks_window_clear (self);
+ g_clear_object (&self->tweaks);
+ }
G_OBJECT_CLASS (ide_tweaks_window_parent_class)->dispose (object);
}
@@ -109,7 +147,8 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/libide-tweaks/ide-tweaks-window.ui");
- gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, list);
+ gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_stack);
+ gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_list_stack);
g_type_ensure (IDE_TYPE_TWEAKS_PANEL);
g_type_ensure (IDE_TYPE_TWEAKS_PANEL_LIST);
@@ -157,11 +196,22 @@ ide_tweaks_window_set_tweaks (IdeTweaksWindow *self,
g_return_if_fail (IDE_IS_TWEAKS_WINDOW (self));
g_return_if_fail (!tweaks || IDE_IS_TWEAKS (tweaks));
- if (g_set_object (&self->tweaks, tweaks))
+ if (self->tweaks == tweaks)
+ return;
+
+ if (self->tweaks != NULL)
{
- ide_tweaks_window_navigate_to (self, IDE_TWEAKS_ITEM (tweaks));
- g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TWEAKS]);
+ ide_tweaks_window_clear (self);
+ g_clear_object (&self->tweaks);
}
+
+ if (tweaks != NULL)
+ {
+ g_set_object (&self->tweaks, tweaks);
+ ide_tweaks_window_rebuild (self);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TWEAKS]);
}
/**
@@ -187,5 +237,4 @@ ide_tweaks_window_navigate_to (IdeTweaksWindow *self,
if (item == NULL)
return;
- ide_tweaks_panel_list_set_item (self->list, item);
}
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index c676807db..9a8ef9136 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -74,18 +74,12 @@
</object>
</child>
<child>
- <object class="GtkScrolledWindow">
+ <object class="GtkStack" id="panel_list_stack">
+ <property name="hhomogeneous">true</property>
+ <property name="transition-type">slide-left-right</property>
<property name="vexpand">true</property>
+ <property name="vhomogeneous">false</property>
<property name="width-request">200</property>
- <property name="hscrollbar-policy">never</property>
- <child>
- <object class="GtkViewport">
- <property name="scroll-to-focus">true</property>
- <child>
- <object class="IdeTweaksPanelList" id="list"/>
- </child>
- </object>
- </child>
</object>
</child>
</object>
@@ -109,7 +103,7 @@
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<child>
- <object class="GtkStack" id="stack">
+ <object class="GtkStack" id="panel_stack">
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<property name="transition-type">crossfade</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]