[gtk/wip/otte/listview: 90/158] builderlistitemfactory: Add scope argument
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 90/158] builderlistitemfactory: Add scope argument
- Date: Tue, 4 Feb 2020 22:28:02 +0000 (UTC)
commit 8ef8a2da2e828b26f37412fa502a4a07553af7a3
Author: Benjamin Otte <otte redhat com>
Date: Tue Dec 3 07:03:10 2019 +0100
builderlistitemfactory: Add scope argument
This way, the scope used when creating builder instances can be
influenced. This way, callbacks can be passed into the factory.
gtk/gtkbuilderlistitemfactory.c | 53 ++++++++++++++++++++++++++++++++++++++---
gtk/gtkbuilderlistitemfactory.h | 8 +++++--
2 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkbuilderlistitemfactory.c b/gtk/gtkbuilderlistitemfactory.c
index 387f8c998b..226d3a7ea1 100644
--- a/gtk/gtkbuilderlistitemfactory.c
+++ b/gtk/gtkbuilderlistitemfactory.c
@@ -59,6 +59,7 @@ struct _GtkBuilderListItemFactory
{
GtkListItemFactory parent_instance;
+ GtkBuilderScope *scope;
GBytes *bytes;
char *resource;
};
@@ -72,6 +73,7 @@ enum {
PROP_0,
PROP_BYTES,
PROP_RESOURCE,
+ PROP_SCOPE,
N_PROPS
};
@@ -93,6 +95,8 @@ gtk_builder_list_item_factory_setup (GtkListItemFactory *factory,
builder = gtk_builder_new ();
gtk_builder_set_current_object (builder, G_OBJECT (list_item));
+ if (self->scope)
+ gtk_builder_set_scope (builder, self->scope);
if (!gtk_builder_extend_with_template (builder, GTK_WIDGET (list_item), G_OBJECT_TYPE (list_item),
(const gchar *)g_bytes_get_data (self->bytes, NULL),
@@ -130,6 +134,10 @@ gtk_builder_list_item_factory_get_property (GObject *object,
g_value_set_string (value, self->resource);
break;
+ case PROP_SCOPE:
+ g_value_set_object (value, self->scope);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -192,6 +200,10 @@ gtk_builder_list_item_factory_set_property (GObject *object,
}
break;
+ case PROP_SCOPE:
+ self->scope = g_value_dup_object (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -203,6 +215,7 @@ gtk_builder_list_item_factory_finalize (GObject *object)
{
GtkBuilderListItemFactory *self = GTK_BUILDER_LIST_ITEM_FACTORY (object);
+ g_clear_object (&self->scope);
g_bytes_unref (self->bytes);
g_free (self->resource);
@@ -245,8 +258,19 @@ gtk_builder_list_item_factory_class_init (GtkBuilderListItemFactoryClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (gobject_class, N_PROPS, properties);
+ /**
+ * GtkBuilderListItemFactory:scope:
+ *
+ * scope to use when instantiating listitems
+ */
+ properties[PROP_SCOPE] =
+ g_param_spec_object ("scope",
+ P_("Scope"),
+ P_("scope to use when instantiating listitems"),
+ GTK_TYPE_BUILDER_SCOPE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
@@ -256,6 +280,7 @@ gtk_builder_list_item_factory_init (GtkBuilderListItemFactory *self)
/**
* gtk_builder_list_item_factory_new_from_bytes:
+ * @scope: (nullable) (transfer none): A scope to use when instantiating
* @bytes: the bytes containing the ui file to instantiate
*
* Creates s new #GtkBuilderListItemFactory that instantiates widgets
@@ -264,17 +289,20 @@ gtk_builder_list_item_factory_init (GtkBuilderListItemFactory *self)
* Returns: a new #GtkBuilderListItemFactory
**/
GtkListItemFactory *
-gtk_builder_list_item_factory_new_from_bytes (GBytes *bytes)
+gtk_builder_list_item_factory_new_from_bytes (GtkBuilderScope *scope,
+ GBytes *bytes)
{
g_return_val_if_fail (bytes != NULL, NULL);
return g_object_new (GTK_TYPE_BUILDER_LIST_ITEM_FACTORY,
"bytes", bytes,
+ "scope", scope,
NULL);
}
/**
* gtk_builder_list_item_factory_new_from_resource:
+ * @scope: (nullable) (transfer none): A scope to use when instantiating
* @resource_path: valid path to a resource that contains the data
*
* Creates s new #GtkBuilderListItemFactory that instantiates widgets
@@ -283,12 +311,15 @@ gtk_builder_list_item_factory_new_from_bytes (GBytes *bytes)
* Returns: a new #GtkBuilderListItemFactory
**/
GtkListItemFactory *
-gtk_builder_list_item_factory_new_from_resource (const char *resource_path)
+gtk_builder_list_item_factory_new_from_resource (GtkBuilderScope *scope,
+ const char *resource_path)
{
+ g_return_val_if_fail (scope == NULL || GTK_IS_BUILDER_SCOPE (scope), NULL);
g_return_val_if_fail (resource_path != NULL, NULL);
return g_object_new (GTK_TYPE_BUILDER_LIST_ITEM_FACTORY,
"resource", resource_path,
+ "scope", scope,
NULL);
}
@@ -327,3 +358,19 @@ gtk_builder_list_item_factory_get_resource (GtkBuilderListItemFactory *self)
return self->resource;
}
+/**
+ * gtk_builder_list_item_factory_get_scope:
+ * @self: a #GtkBuilderListItemFactory
+ *
+ * Gets the scope used when constructing listitems.
+ *
+ * Returns: (transfer none) (nullable): The scope used when constructing listitems
+ **/
+GtkBuilderScope *
+gtk_builder_list_item_factory_get_scope (GtkBuilderListItemFactory *self)
+{
+ g_return_val_if_fail (GTK_IS_BUILDER_LIST_ITEM_FACTORY (self), NULL);
+
+ return self->scope;
+}
+
diff --git a/gtk/gtkbuilderlistitemfactory.h b/gtk/gtkbuilderlistitemfactory.h
index c10dacb7aa..cf2a7add44 100644
--- a/gtk/gtkbuilderlistitemfactory.h
+++ b/gtk/gtkbuilderlistitemfactory.h
@@ -42,14 +42,18 @@ GDK_AVAILABLE_IN_ALL
GType gtk_builder_list_item_factory_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
-GtkListItemFactory * gtk_builder_list_item_factory_new_from_bytes (GBytes
*bytes);
+GtkListItemFactory * gtk_builder_list_item_factory_new_from_bytes (GtkBuilderScope
*scope,
+ GBytes
*bytes);
GDK_AVAILABLE_IN_ALL
-GtkListItemFactory * gtk_builder_list_item_factory_new_from_resource (const char
*resource_path);
+GtkListItemFactory * gtk_builder_list_item_factory_new_from_resource (GtkBuilderScope
*scope,
+ const char
*resource_path);
GDK_AVAILABLE_IN_ALL
GBytes * gtk_builder_list_item_factory_get_bytes (GtkBuilderListItemFactory
*self) G_GNUC_PURE;
GDK_AVAILABLE_IN_ALL
const char * gtk_builder_list_item_factory_get_resource (GtkBuilderListItemFactory
*self) G_GNUC_PURE;
+GDK_AVAILABLE_IN_ALL
+GtkBuilderScope * gtk_builder_list_item_factory_get_scope (GtkBuilderListItemFactory
*self) G_GNUC_PURE;
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]