[sysprof/wip/gtk4-port] notebook: fix adding children from ui files



commit 863fee6a3227547ac823c7c053c7422d1429339e
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 1 13:57:11 2021 -0700

    notebook: fix adding children from ui files

 src/libsysprof-ui/sysprof-notebook.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/src/libsysprof-ui/sysprof-notebook.c b/src/libsysprof-ui/sysprof-notebook.c
index ae7145f5..0a096110 100644
--- a/src/libsysprof-ui/sysprof-notebook.c
+++ b/src/libsysprof-ui/sysprof-notebook.c
@@ -33,7 +33,11 @@ typedef struct
   guint always_show_tabs : 1;
 } SysprofNotebookPrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (SysprofNotebook, sysprof_notebook, GTK_TYPE_WIDGET)
+static void buildable_iface_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (SysprofNotebook, sysprof_notebook, GTK_TYPE_WIDGET,
+                         G_ADD_PRIVATE (SysprofNotebook)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
 
 enum {
   PROP_0,
@@ -499,3 +503,28 @@ sysprof_notebook_set_always_show_tabs (SysprofNotebook *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ALWAYS_SHOW_TABS]);
     }
 }
+
+static void
+sysprof_notebook_add_child (GtkBuildable *buildable,
+                            GtkBuilder   *builder,
+                            GObject      *child,
+                            const char   *type)
+{
+  SysprofNotebook *self = (SysprofNotebook *)buildable;
+  SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self);
+
+  g_assert (SYSPROF_IS_NOTEBOOK (self));
+
+  if (SYSPROF_IS_DISPLAY (child))
+    gtk_notebook_append_page (priv->notebook, GTK_WIDGET (child), NULL);
+  else
+    g_warning ("Cannot add child of type %s to %s",
+               G_OBJECT_TYPE_NAME (child),
+               G_OBJECT_TYPE_NAME (self));
+}
+
+static void
+buildable_iface_init (GtkBuildableIface *iface)
+{
+  iface->add_child = sysprof_notebook_add_child;
+}


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