[gnome-builder] libide/tweaks: change constructor for panel list



commit a83bb09dd2cef70926cc13070d94f7327ecb7626
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 2 22:59:10 2022 -0700

    libide/tweaks: change constructor for panel list

 src/libide/tweaks/ide-tweaks-panel-list-private.h |   4 +-
 src/libide/tweaks/ide-tweaks-panel-list.c         | 118 +++++++++++-----------
 src/libide/tweaks/ide-tweaks-window.c             |   4 +-
 3 files changed, 63 insertions(+), 63 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel-list-private.h 
b/src/libide/tweaks/ide-tweaks-panel-list-private.h
index efaa3e171..5a4767621 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list-private.h
+++ b/src/libide/tweaks/ide-tweaks-panel-list-private.h
@@ -30,10 +30,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeTweaksPanelList, ide_tweaks_panel_list, IDE, TWEAKS_PANEL_LIST, AdwBin)
 
-GtkWidget     *ide_tweaks_panel_list_new          (void);
+GtkWidget     *ide_tweaks_panel_list_new          (IdeTweaksItem      *item);
 IdeTweaksItem *ide_tweaks_panel_list_get_item     (IdeTweaksPanelList *self);
-void           ide_tweaks_panel_list_set_item     (IdeTweaksPanelList *self,
-                                                   IdeTweaksItem      *item);
 void           ide_tweaks_panel_list_select_first (IdeTweaksPanelList *self);
 
 G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.c b/src/libide/tweaks/ide-tweaks-panel-list.c
index a3165dfc6..26cf99e4f 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.c
+++ b/src/libide/tweaks/ide-tweaks-panel-list.c
@@ -54,6 +54,61 @@ G_DEFINE_FINAL_TYPE (IdeTweaksPanelList, ide_tweaks_panel_list, ADW_TYPE_BIN)
 static GParamSpec *properties [N_PROPS];
 static guint signals [N_SIGNALS];
 
+static IdeTweaksItemVisitResult
+panel_list_visitor (IdeTweaksItem *item,
+                    gpointer       user_data)
+{
+  static GType page_type;
+
+  if (!page_type)
+    page_type = IDE_TYPE_TWEAKS_PAGE;
+
+  if (IDE_IS_TWEAKS_SECTION (item))
+    return IDE_TWEAKS_ITEM_VISIT_RECURSE;
+
+  if (IDE_IS_TWEAKS_PAGE (item))
+    return IDE_TWEAKS_ITEM_VISIT_ACCEPT;
+
+  if (IDE_IS_TWEAKS_FACTORY (item) &&
+      _ide_tweaks_factory_is_one_of (IDE_TWEAKS_FACTORY (item), &page_type, 1))
+    return IDE_TWEAKS_ITEM_VISIT_ACCEPT;
+
+  return IDE_TWEAKS_ITEM_VISIT_SKIP;
+}
+
+static GtkWidget *
+ide_tweaks_panel_list_create_row_cb (gpointer item,
+                                     gpointer user_data)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_PANEL_LIST_ROW,
+                       "item", item,
+                       NULL);
+}
+
+static void
+ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
+                                IdeTweaksItem      *item)
+{
+  g_assert (IDE_IS_TWEAKS_PANEL_LIST (self));
+  g_assert (IDE_IS_TWEAKS_ITEM (item));
+
+  if (g_set_object (&self->item, item))
+    {
+      g_autoptr(IdeTweaksModel) model = NULL;
+
+      if (item != NULL)
+        {
+          model = ide_tweaks_model_new (item, panel_list_visitor, NULL, NULL);
+          gtk_list_box_bind_model (self->list_box,
+                                   G_LIST_MODEL (model),
+                                   ide_tweaks_panel_list_create_row_cb,
+                                   NULL, NULL);
+        }
+
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ITEM]);
+    }
+}
+
 static void
 ide_tweaks_panel_list_header_func (IdeTweaksPanelListRow *row,
                                    IdeTweaksPanelListRow *before,
@@ -188,9 +243,13 @@ ide_tweaks_panel_list_init (IdeTweaksPanelList *self)
 }
 
 GtkWidget *
-ide_tweaks_panel_list_new (void)
+ide_tweaks_panel_list_new (IdeTweaksItem *item)
 {
-  return g_object_new (IDE_TYPE_TWEAKS_PANEL_LIST, NULL);
+  g_return_val_if_fail (!item || IDE_IS_TWEAKS_ITEM (item), NULL);
+
+  return g_object_new (IDE_TYPE_TWEAKS_PANEL_LIST,
+                       "item", item,
+                       NULL);
 }
 
 /**
@@ -209,61 +268,6 @@ ide_tweaks_panel_list_get_item (IdeTweaksPanelList *self)
   return self->item;
 }
 
-static GtkWidget *
-ide_tweaks_panel_list_create_row_cb (gpointer item,
-                                     gpointer user_data)
-{
-  return g_object_new (IDE_TYPE_TWEAKS_PANEL_LIST_ROW,
-                       "item", item,
-                       NULL);
-}
-
-static IdeTweaksItemVisitResult
-panel_list_visitor (IdeTweaksItem *item,
-                    gpointer       user_data)
-{
-  static GType page_type;
-
-  if (!page_type)
-    page_type = IDE_TYPE_TWEAKS_PAGE;
-
-  if (IDE_IS_TWEAKS_SECTION (item))
-    return IDE_TWEAKS_ITEM_VISIT_RECURSE;
-
-  if (IDE_IS_TWEAKS_PAGE (item))
-    return IDE_TWEAKS_ITEM_VISIT_ACCEPT;
-
-  if (IDE_IS_TWEAKS_FACTORY (item) &&
-      _ide_tweaks_factory_is_one_of (IDE_TWEAKS_FACTORY (item), &page_type, 1))
-    return IDE_TWEAKS_ITEM_VISIT_ACCEPT;
-
-  return IDE_TWEAKS_ITEM_VISIT_SKIP;
-}
-
-void
-ide_tweaks_panel_list_set_item (IdeTweaksPanelList *self,
-                                IdeTweaksItem      *item)
-{
-  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_autoptr(IdeTweaksModel) model = NULL;
-
-      if (item != NULL)
-        {
-          model = ide_tweaks_model_new (item, panel_list_visitor, NULL, NULL);
-          gtk_list_box_bind_model (self->list_box,
-                                   G_LIST_MODEL (model),
-                                   ide_tweaks_panel_list_create_row_cb,
-                                   NULL, NULL);
-        }
-
-      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ITEM]);
-    }
-}
-
 void
 ide_tweaks_panel_list_select_first (IdeTweaksPanelList *self)
 {
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 7d4d0cabc..a71b14781 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -115,14 +115,12 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
   g_assert (IDE_IS_TWEAKS_WINDOW (self));
   g_assert (IDE_IS_TWEAKS (self->tweaks));
 
-  list = ide_tweaks_panel_list_new ();
+  list = ide_tweaks_panel_list_new (IDE_TWEAKS_ITEM (self->tweaks));
   g_signal_connect_object (list,
                            "page-activated",
                            G_CALLBACK (ide_tweaks_window_page_activated_cb),
                            self,
                            G_CONNECT_SWAPPED);
-  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)));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]