[glade/gbinding] Remove g_object_set_data() usage for binding resolution
- From: Denis Washington <denisw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/gbinding] Remove g_object_set_data() usage for binding resolution
- Date: Fri, 19 Aug 2011 17:13:59 +0000 (UTC)
commit cfed3c7e9858061827b4b0becd466d250fb04d73
Author: Denis Washington <denisw src gnome org>
Date: Thu Aug 18 21:57:44 2011 +0200
Remove g_object_set_data() usage for binding resolution
For Juan. :)
gladeui/glade-project.c | 23 ++--------------
gladeui/glade-property.c | 65 ++++++++++++++++++++++++++++++++++++++++-----
gladeui/glade-property.h | 1 +
3 files changed, 61 insertions(+), 28 deletions(-)
---
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 874ef8d..9068a2d 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -1021,13 +1021,13 @@ glade_project_new (void)
* properties
*/
static void
-glade_project_fix_props (GladeProject *project)
+glade_project_fix_object_props (GladeProject *project)
{
GList *l, *ll, *objects;
GValue *value;
GladeWidget *gwidget;
GladeProperty *property;
- gchar *txt, *txt2;
+ gchar *txt;
objects = g_list_copy (project->priv->objects);
for (l = objects; l; l = l->next)
@@ -1059,24 +1059,7 @@ glade_project_fix_props (GladeProject *project)
"glade-loaded-object", NULL);
}
- if ((txt = g_object_get_data (G_OBJECT (property),
- "glade-source-object")) != NULL &&
- (txt2 = g_object_get_data (G_OBJECT (property),
- "glade-source-property")) != NULL)
- {
- GladeWidget *source_obj;
- GladeProperty *source_prop;
-
- source_obj = glade_project_get_widget_by_name (project, txt);
- if (!source_obj)
- continue;
-
- source_prop = glade_widget_get_property (source_obj, txt2);
- if (!source_prop)
- continue;
-
- glade_property_set_binding_source (property, source_prop);
- }
+ glade_property_resolve_binding (property);
}
}
g_list_free (objects);
diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c
index 402a7d5..df2916b 100644
--- a/gladeui/glade-property.c
+++ b/gladeui/glade-property.c
@@ -115,6 +115,10 @@ struct _GladePropertyPrivate {
* the property's binding
*/
+ /* For resolving a binding source read from a project file */
+ gchar *binding_source_object_name;
+ gchar *binding_source_property_name;
+
/* Used only for translatable strings. */
guint i18n_translatable : 1;
gchar *i18n_context;
@@ -600,6 +604,10 @@ glade_property_finalize (GObject * object)
g_value_unset (property->priv->value);
g_free (property->priv->value);
}
+ if (property->priv->binding_source_object_name)
+ g_free (property->priv->binding_source_object_name);
+ if (property->priv->binding_source_property_name)
+ g_free (property->priv->binding_source_property_name);
if (property->priv->binding_targets)
g_list_free (property->priv->binding_targets);
if (property->priv->binding_transform_func)
@@ -626,6 +634,8 @@ glade_property_init (GladeProperty * property)
property->priv->enabled = TRUE;
property->priv->sensitive = TRUE;
property->priv->binding_source = NULL;
+ property->priv->binding_source_object_name = NULL;
+ property->priv->binding_source_property_name = NULL;
property->priv->binding_targets = NULL;
property->priv->binding_transform_func = NULL;
property->priv->i18n_translatable = TRUE;
@@ -1290,8 +1300,9 @@ glade_property_write (GladeProperty * property,
* Read the binding information from @node and save it in
* the target #GladeProperty of @widget.
*
- * Note that the actual binding source property will only be
- * resolved after the project is completely loaded.
+ * Note that the actual binding source property will be
+ * resolved by glade_property_resolve_binding() after the
+ * project is completely loaded.
*/
void
glade_property_binding_read (GladeXmlNode *node,
@@ -1329,12 +1340,8 @@ glade_property_binding_read (GladeXmlNode *node,
g_free (transform_func);
}
- g_object_set_data_full (G_OBJECT (target),
- "glade-source-property",
- g_strdup (from), g_free);
- g_object_set_data_full (G_OBJECT (target),
- "glade-source-object",
- g_strdup (source), g_free);
+ target->priv->binding_source_object_name = g_strdup (source);
+ target->priv->binding_source_property_name = g_strdup (from);
}
g_free (from);
@@ -1397,6 +1404,48 @@ glade_property_binding_write (GladeProperty *property,
}
/**
+ * glade_property_resolve_binding:
+ * @property: a #GladeProperty
+ *
+ * Resolves the binding source of @property if a binding with
+ * @property as target was read by glade_property_binding_read()
+ * during project loading.
+ */
+void
+glade_property_resolve_binding (GladeProperty *property)
+{
+ gchar *source_obj_name, *source_prop_name;
+ GladeWidget *widget;
+ GladeProject *project;
+ GladeWidget *source_obj;
+ GladeProperty *source_prop;
+
+ source_obj_name = property->priv->binding_source_object_name;
+ source_prop_name = property->priv->binding_source_property_name;
+
+ if (!source_obj_name || !source_prop_name)
+ return;
+
+ widget = glade_property_get_widget (property);
+ project = glade_widget_get_project (widget);
+
+ source_obj = glade_project_get_widget_by_name (project, source_obj_name);
+ if (!source_obj)
+ return;
+
+ source_prop = glade_widget_get_property (source_obj, source_prop_name);
+ if (!source_prop)
+ return;
+
+ glade_property_set_binding_source (property, source_prop);
+
+ property->priv->binding_source_object_name = NULL;
+ property->priv->binding_source_property_name = NULL;
+ g_free (source_obj_name);
+ g_free (source_prop_name);
+}
+
+/**
* glade_property_add_object:
* @property: a #GladeProperty
* @object: The #GObject to add
diff --git a/gladeui/glade-property.h b/gladeui/glade-property.h
index d07df44..744771c 100644
--- a/gladeui/glade-property.h
+++ b/gladeui/glade-property.h
@@ -128,6 +128,7 @@ void glade_property_binding_write (GladeProperty
GladeXmlContext *context,
GladeXmlNode *node);
+void glade_property_resolve_binding (GladeProperty *property);
GladePropertyClass *glade_property_get_class (GladeProperty *property);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]