Now all native properties (obtained through

* src/glade-property-class.[ch]: Now all native properties (obtained through
	  g_object_class_list_properties) have "orig_def" fields (which can still
	  be overridden by the "default" tag in the catalog), custom properties have
	  no original defaults.

	* src/glade-property.c: Adjusted glade_property_write accordingly.
This commit is contained in:
Tristan Van Berkom 2005-08-29 17:35:41 +00:00
parent 1b742350bc
commit 79cea47007
4 changed files with 45 additions and 32 deletions

View File

@ -1,3 +1,12 @@
2005-08-29 Tristan Van Berkom <tvb@gnome.org>
* src/glade-property-class.[ch]: Now all native properties (obtained through
g_object_class_list_properties) have "orig_def" fields (which can still
be overridden by the "default" tag in the catalog), custom properties have
no original defaults.
* src/glade-property.c: Adjusted glade_property_write accordingly.
2005-08-24 Tristan Van Berkom <tvb@gnome.org>
* src/glade-gtk.c: Fixed g_return_if_fail which should be

View File

@ -571,8 +571,9 @@ glade_property_class_new_from_spec (GParamSpec *spec)
goto lblError;
}
property_class->tooltip = g_strdup (g_param_spec_get_blurb (spec));
property_class->def = glade_property_class_get_default_from_spec (spec);
property_class->tooltip = g_strdup (g_param_spec_get_blurb (spec));
property_class->orig_def = glade_property_class_get_default_from_spec (spec);
property_class->def = glade_property_class_get_default_from_spec (spec);
return property_class;
@ -809,8 +810,10 @@ glade_property_class_update_from_node (GladeXmlNode *node,
if (class->pspec->flags & G_PARAM_CONSTRUCT_ONLY)
class->construct_only = TRUE;
else if (class->def)
class->orig_def = class->def;
if (class->def) {
g_value_unset (class->def);
g_free (class->def);
}
class->def = glade_property_class_get_default_from_spec (class->pspec);
}
@ -832,8 +835,10 @@ glade_property_class_update_from_node (GladeXmlNode *node,
buff = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
if (buff)
{
if (class->def)
class->orig_def = class->def;
if (class->def) {
g_value_unset (class->def);
g_free (class->def);
}
class->def = glade_property_class_make_gvalue_from_string (class, buff);
g_free (buff);
}

View File

@ -102,10 +102,12 @@ struct _GladePropertyClass
*/
gchar *tooltip; /* The default tooltip for the property editor rows.
*/
GValue *def; /* The default value for this property */
GValue *def; /* The default value for this property */
GValue *orig_def; /* If def is overridden by a xml file,
it is the original value, otherwise NULL. */
GValue *orig_def; /* The real default value obtained through introspection.
* (used to decide whether we should write to the
* glade file or not).
*/
GList *parameters; /* list of GladeParameter objects. This list
* provides with an extra set of key-value

View File

@ -285,33 +285,30 @@ glade_property_write_impl (GladeProperty *property,
* the opening and the closing of the property tag */
tmp = glade_property_class_make_string_from_gvalue (property->class,
property->value);
if (!tmp)
if (!tmp || !tmp[0])
return FALSE;
if (property->class->def)
if (property->class->orig_def == NULL)
{
if (property->class->orig_def == NULL)
{
default_str =
glade_property_class_make_string_from_gvalue (property->class,
property->class->def);
skip = default_str && !strcmp (tmp, default_str);
g_free (default_str);
}
else
{
skip = G_IS_PARAM_SPEC_STRING (property->class->pspec) &&
tmp[0] == '\0' &&
!g_value_get_string (property->class->orig_def);
}
if (skip)
{
g_free (tmp);
return FALSE;
}
/* Skip custom properties that are NULL string types. */
skip = G_IS_PARAM_SPEC_STRING (property->class->pspec) &&
!g_value_get_string (property->class->orig_def);
}
else
{
default_str =
glade_property_class_make_string_from_gvalue
(property->class, property->class->orig_def);
skip = default_str && !strcmp (tmp, default_str);
g_free (default_str);
}
if (skip)
{
g_free (tmp);
return FALSE;
}
if (property->class->translatable)
{
/* FIXME: implement writing the i18n metadata. */