[epiphany/wip/exalm/gtk4: 10/14] data-view: Implement GtkBuildable instead of GtkContainer.add()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/gtk4: 10/14] data-view: Implement GtkBuildable instead of GtkContainer.add()
- Date: Mon, 21 Feb 2022 12:16:38 +0000 (UTC)
commit 63d12540d4cb3f015c5607bb1e0457478f56974a
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Feb 21 13:39:06 2022 +0500
data-view: Implement GtkBuildable instead of GtkContainer.add()
The latter will go away in GTK4, and we only use this from ui files anyway.
src/preferences/ephy-data-view.c | 61 ++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 24 deletions(-)
---
diff --git a/src/preferences/ephy-data-view.c b/src/preferences/ephy-data-view.c
index c9652222d..751418a78 100644
--- a/src/preferences/ephy-data-view.c
+++ b/src/preferences/ephy-data-view.c
@@ -44,7 +44,14 @@ typedef struct {
char *search_text;
} EphyDataViewPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE (EphyDataView, ephy_data_view, GTK_TYPE_BIN)
+static void ephy_data_view_buildable_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (EphyDataView, ephy_data_view, GTK_TYPE_BIN,
+ G_ADD_PRIVATE (EphyDataView)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ ephy_data_view_buildable_init))
+
+static GtkBuildableIface *parent_buildable_iface;
enum {
PROP_0,
@@ -290,39 +297,16 @@ ephy_data_view_finalize (GObject *object)
G_OBJECT_CLASS (ephy_data_view_parent_class)->finalize (object);
}
-static void
-ephy_data_view_add (GtkContainer *container,
- GtkWidget *child)
-{
- EphyDataView *self = EPHY_DATA_VIEW (container);
- EphyDataViewPrivate *priv = ephy_data_view_get_instance_private (self);
-
- if (!priv->box) {
- GTK_CONTAINER_CLASS (ephy_data_view_parent_class)->add (container, child);
- return;
- }
-
- g_assert (!priv->child);
-
- priv->child = child;
- gtk_container_add (GTK_CONTAINER (priv->stack), child);
-
- update (self);
-}
-
static void
ephy_data_view_class_init (EphyDataViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
object_class->set_property = ephy_data_view_set_property;
object_class->get_property = ephy_data_view_get_property;
object_class->finalize = ephy_data_view_finalize;
- container_class->add = ephy_data_view_add;
-
obj_properties[PROP_TITLE] =
g_param_spec_string ("title",
"Title",
@@ -473,6 +457,35 @@ ephy_data_view_init (EphyDataView *self)
update (self);
}
+static void
+ephy_data_view_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const char *type)
+{
+ EphyDataView *self = EPHY_DATA_VIEW (buildable);
+ EphyDataViewPrivate *priv = ephy_data_view_get_instance_private (self);
+
+ if (!priv->box || !GTK_IS_WIDGET (child)) {
+ parent_buildable_iface->add_child (buildable, builder, child, type);
+ return;
+ }
+
+ g_assert (!priv->child);
+
+ priv->child = GTK_WIDGET (child);
+ gtk_container_add (GTK_CONTAINER (priv->stack), priv->child);
+
+ update (self);
+}
+
+static void
+ephy_data_view_buildable_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+ iface->add_child = ephy_data_view_add_child;
+}
+
const gchar *
ephy_data_view_get_clear_button_label (EphyDataView *self)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]