summaryrefslogtreecommitdiff
path: root/gtk/gtkbuilder.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-11-25 08:15:31 +0100
committerMatthias Clasen <mclasen@redhat.com>2020-05-30 19:26:44 -0400
commit934bfc8887bc62e3f8131b691d889236ca32e6f6 (patch)
tree2096151c0f7ae66380e744cb2db2f22066ac2987 /gtk/gtkbuilder.c
parent713a6676ff3789235b7e5ab0d15f9e3376af0972 (diff)
downloadgtk+-934bfc8887bc62e3f8131b691d889236ca32e6f6.tar.gz
builder: Add <binding> tag
The tag contains an expression that it then gtk_expression_bind()s to the object it is contained in.
Diffstat (limited to 'gtk/gtkbuilder.c')
-rw-r--r--gtk/gtkbuilder.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 244f8e8a9a..5b5a66eb90 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -219,6 +219,7 @@
#include "gtkbuildable.h"
#include "gtkbuilderscopeprivate.h"
#include "gtkdebug.h"
+#include "gtkexpression.h"
#include "gtkmain.h"
#include "gtkicontheme.h"
#include "gtkintl.h"
@@ -685,8 +686,22 @@ gtk_builder_take_bindings (GtkBuilder *builder,
for (l = bindings; l; l = l->next)
{
- BindingInfo *info = l->data;
- info->target = target;
+ CommonInfo *common_info = l->data;
+
+ if (common_info->tag_type == TAG_BINDING)
+ {
+ BindingInfo *info = l->data;
+ info->target = target;
+ }
+ else if (common_info->tag_type == TAG_BINDING_EXPRESSION)
+ {
+ BindingExpressionInfo *info = l->data;
+ info->target = target;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
}
priv->bindings = g_slist_concat (priv->bindings, bindings);
@@ -1013,17 +1028,6 @@ gtk_builder_apply_delayed_properties (GtkBuilder *builder,
return result;
}
-static inline void
-free_binding_info (gpointer data,
- gpointer user)
-{
- BindingInfo *info = data;
-
- g_free (info->source);
- g_free (info->source_property);
- g_slice_free (BindingInfo, data);
-}
-
static inline gboolean
gtk_builder_create_bindings (GtkBuilder *builder,
GError **error)
@@ -1034,26 +1038,44 @@ gtk_builder_create_bindings (GtkBuilder *builder,
for (l = priv->bindings; l; l = l->next)
{
- BindingInfo *info = l->data;
- GObject *source;
+ CommonInfo *common_info = l->data;
- if (result)
+ if (common_info->tag_type == TAG_BINDING)
{
- source = gtk_builder_lookup_object (builder, info->source, info->line, info->col, error);
+ BindingInfo *info = l->data;
+ GObject *source;
+
+ source = _gtk_builder_lookup_object (builder, info->source, info->line, info->col);
if (source)
g_object_bind_property (source, info->source_property,
info->target, info->target_pspec->name,
info->flags);
- else
- result = FALSE;
+
+ _free_binding_info (info, NULL);
}
+ else if (common_info->tag_type == TAG_BINDING_EXPRESSION)
+ {
+ BindingExpressionInfo *info = l->data;
+ GtkExpression *expression;
- free_binding_info (info, NULL);
+ expression = expression_info_construct (builder, info->expr, error);
+ if (expression == NULL)
+ {
+ g_prefix_error (error, "%s:%d:%d: ", priv->filename, info->line, info->col);
+ error = NULL;
+ result = FALSE;
+ }
+ else
+ {
+ gtk_expression_bind (expression, info->target, info->target_pspec->name);
+ }
+
+ free_binding_expression_info (info);
+ }
}
g_slist_free (priv->bindings);
priv->bindings = NULL;
-
return result;
}