[gtk/wip/chergert/builder-expose-object-fix: 1/3] gtkbuilder: check for existing object before extending template
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/builder-expose-object-fix: 1/3] gtkbuilder: check for existing object before extending template
- Date: Mon, 1 Aug 2022 04:21:26 +0000 (UTC)
commit 8fc618a154665ad5390e1d89fff67879bd253dba
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 31 21:15:08 2022 -0700
gtkbuilder: check for existing object before extending template
If gtk_builder_expose_object() is called twice with the same name, it will
result in a g_critical(). This improves that situation by checking for the
object before exposing additional times.
This turns out to be handy in situations where templates are expanded
multiple times, such as application-side implementations of UI merging.
gtk/gtkbuilder.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index ab28ccc5d9..17561f9b49 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -1367,6 +1367,7 @@ gtk_builder_extend_with_template (GtkBuilder *builder,
GError **error)
{
GtkBuilderPrivate *priv = gtk_builder_get_instance_private (builder);
+ const char *name;
GError *tmp_error;
char *filename;
@@ -1384,8 +1385,11 @@ gtk_builder_extend_with_template (GtkBuilder *builder,
priv->resource_prefix = NULL;
priv->template_type = template_type;
- filename = g_strconcat ("<", g_type_name (template_type), " template>", NULL);
- gtk_builder_expose_object (builder, g_type_name (template_type), object);
+ name = g_type_name (template_type);
+ if (gtk_builder_get_object (builder, name) != object)
+ gtk_builder_expose_object (builder, name, object);
+
+ filename = g_strconcat ("<", name, " template>", NULL);
_gtk_builder_parser_parse_buffer (builder, filename,
buffer, length,
NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]