diff options
author | Denis Washington <denisw@src.gnome.org> | 2011-08-18 21:57:44 +0200 |
---|---|---|
committer | Denis Washington <denisw@src.gnome.org> | 2011-12-13 07:57:47 +0100 |
commit | 478a5006dbb17b50aa88bdc634c3296f8565bca9 (patch) | |
tree | f2a3bebf6972921999b0558df20c59531f06b9a9 | |
parent | a775f6ca3eb66d7df7f97e5662f361306ba2b0d5 (diff) | |
download | glade-478a5006dbb17b50aa88bdc634c3296f8565bca9.tar.gz |
Remove g_object_set_data() usage for binding resolution
For Juan. :)
-rw-r--r-- | gladeui/glade-project.c | 23 | ||||
-rw-r--r-- | gladeui/glade-property.c | 65 | ||||
-rw-r--r-- | 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 1538aaea..d7f9e266 100644 --- a/gladeui/glade-project.c +++ b/gladeui/glade-project.c @@ -1042,13 +1042,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) @@ -1080,24 +1080,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 890c1cc7..40594b78 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; @@ -606,6 +610,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) @@ -632,6 +640,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; @@ -1289,8 +1299,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, @@ -1328,12 +1339,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); @@ -1396,6 +1403,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 d07df44e..744771cc 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); |