Commit 14cc6063 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Now recurse through the plugin to read and write widget children,


	* gladeui/glade-widget.[ch], glade-widget-adaptor.c:
	  Now recurse through the plugin to read and write widget
	  children, allowiong you to do stuff before or after children
	  are written/read from the xml file.


svn path=/trunk/; revision=1768
parent cd91636a
2008-04-05 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-widget.[ch], glade-widget-adaptor.c:
Now recurse through the plugin to read and write widget
children, allowiong you to do stuff before or after children
are written/read from the xml file.
2008-04-04 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-project.c: Resurected <requires> code and
......
......@@ -759,7 +759,7 @@ glade_widget_adaptor_object_read_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlNode *node)
{
GladeXmlNode *sig_node;
GladeXmlNode *sig_node, *child_node;
GList *props;
GladeSignal *signal;
......@@ -784,6 +784,14 @@ glade_widget_adaptor_object_read_widget (GladeWidgetAdaptor *adaptor,
glade_widget_add_signal_handler (widget, signal);
}
/* Read in children */
for (child_node = glade_xml_node_get_children (node);
child_node; child_node = glade_xml_node_next (child_node))
{
if (glade_xml_node_verify_silent (child_node, GLADE_XML_TAG_CHILD))
glade_widget_read_child (widget, child_node);
}
}
typedef struct {
......@@ -818,7 +826,7 @@ glade_widget_adaptor_object_write_widget (GladeWidgetAdaptor *adaptor,
GladeXmlContext *context,
GladeXmlNode *node)
{
GList *props;
GList *props, *l, *list;
WriteSignalsInfo info = { context, node };
/* Write the properties */
......@@ -830,6 +838,24 @@ glade_widget_adaptor_object_write_widget (GladeWidgetAdaptor *adaptor,
g_hash_table_foreach (widget->signals,
glade_widget_adaptor_write_signals,
&info);
/* Write the children */
if ((list =
glade_widget_adaptor_get_children (adaptor, widget->object)) != NULL)
{
for (l = list; l; l = l->next)
{
GladeWidget *child = glade_widget_get_from_gobject (l->data);
if (child)
glade_widget_write_child (child, context, node);
else if (GLADE_IS_PLACEHOLDER (l->data))
glade_widget_write_placeholder (widget,
G_OBJECT (l->data),
context, node);
}
g_list_free (list);
}
}
static GType
......
......@@ -3340,83 +3340,82 @@ glade_widget_set_child_type_from_node (GladeWidgetAdaptor *parent_adaptor,
g_free (special_child_type);
}
static void
glade_widget_read_children (GladeWidget *widget,
GladeXmlNode *node)
/**
* glade_widget_read_child:
* @widget: A #GladeWidget
* @node: a #GladeXmlNode
*
* Reads in a child widget from the xml (handles <child> tag)
*/
void
glade_widget_read_child (GladeWidget *widget,
GladeXmlNode *node)
{
GladeXmlNode *child, *widget_node, *packing_node;
GladeXmlNode *widget_node, *packing_node;
GladeWidget *child_widget;
GList *packing;
/*
* Deal with children...
*/
for (child = glade_xml_node_get_children (node);
child; child = glade_xml_node_next (child))
{
const gchar *node_name = glade_xml_node_get_name (child);
gchar *internal_name;
if (strcmp (node_name, GLADE_XML_TAG_CHILD) != 0)
continue;
gchar *internal_name;
internal_name =
glade_xml_get_property_string
(child, GLADE_XML_TAG_INTERNAL_CHILD);
if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD))
return;
if ((widget_node =
glade_xml_search_child
(child, GLADE_XML_TAG_WIDGET)) != NULL)
internal_name =
glade_xml_get_property_string
(node, GLADE_XML_TAG_INTERNAL_CHILD);
if ((widget_node =
glade_xml_search_child
(node, GLADE_XML_TAG_WIDGET)) != NULL)
{
child_widget =
glade_widget_read (widget->project,
widget,
widget_node,
internal_name);
if (child_widget)
{
child_widget =
glade_widget_read (widget->project,
widget,
widget_node,
internal_name);
if (child_widget)
if (!internal_name) {
glade_widget_set_child_type_from_node
(widget->adaptor,
child_widget->object, node);
glade_widget_add_child (widget, child_widget, FALSE);
}
if ((packing_node =
glade_xml_search_child
(node, GLADE_XML_TAG_PACKING)) != NULL)
{
if (!internal_name) {
glade_widget_set_child_type_from_node
(widget->adaptor,
child_widget->object, child);
glade_widget_add_child (widget, child_widget, FALSE);
}
if ((packing_node =
glade_xml_search_child
(child, GLADE_XML_TAG_PACKING)) != NULL)
/* Get the packing properties */
for (packing = child_widget->packing_properties;
packing; packing = packing->next)
{
/* Get the packing properties */
for (packing = child_widget->packing_properties;
packing; packing = packing->next)
{
GladeProperty *property = packing->data;
glade_property_read (property,
child_widget->project,
packing_node);
}
GladeProperty *property = packing->data;
glade_property_read (property,
child_widget->project,
packing_node);
}
}
} else {
GObject *palaceholder =
G_OBJECT (glade_placeholder_new ());
glade_widget_set_child_type_from_node (widget->adaptor,
palaceholder,
child);
glade_widget_adaptor_add (widget->adaptor,
widget->object,
palaceholder);
}
g_free (internal_name);
} else {
GObject *palaceholder =
G_OBJECT (glade_placeholder_new ());
glade_widget_set_child_type_from_node (widget->adaptor,
palaceholder,
node);
glade_widget_adaptor_add (widget->adaptor,
widget->object,
palaceholder);
}
g_free (internal_name);
}
/**
* glade_widget_read:
* @project: a #GladeProject
......@@ -3492,8 +3491,6 @@ glade_widget_read (GladeProject *project,
widget,
node);
glade_widget_read_children (widget, node);
}
g_free (id);
}
......@@ -3533,7 +3530,18 @@ glade_widget_write_special_child_prop (GladeWidget *parent,
g_free (special_child_type);
}
static void
/**
* glade_widget_write_child:
* @widget: The #GladeWidget
* @context: A #GladeXmlContext
* @node: A #GladeXmlNode
*
* Writes out a widget to the xml, takes care
* of packing properties and special child types.
*/
void
glade_widget_write_child (GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node)
......@@ -3565,7 +3573,6 @@ glade_widget_write_child (GladeWidget *widget,
glade_widget_write_special_child_prop (widget->parent,
widget->object,
context, packing_node);
/* Default packing properties and such are not saved,
* so lets check afterwords if there was anything saved
......@@ -3578,7 +3585,17 @@ glade_widget_write_child (GladeWidget *widget,
}
}
static void
/**
* glade_widget_write_placeholder:
* @parent: The parent #GladeWidget
* @object: A #GladePlaceHolder
* @context: A #GladeXmlContext
* @node: A #GladeXmlNode
*
* Writes out a placeholder to the xml
*/
void
glade_widget_write_placeholder (GladeWidget *parent,
GObject *object,
GladeXmlContext *context,
......@@ -3621,7 +3638,6 @@ glade_widget_write (GladeWidget *widget,
GladeXmlNode *node)
{
GladeXmlNode *widget_node;
GList *list, *l;
widget_node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET);
glade_xml_node_append_child (node, widget_node);
......@@ -3636,26 +3652,6 @@ glade_widget_write (GladeWidget *widget,
/* Write out widget content (properties and signals) */
glade_widget_adaptor_write_widget (widget->adaptor, widget, context, widget_node);
/* Write out children */
if ((list =
glade_widget_adaptor_get_children (widget->adaptor,
widget->object)) != NULL)
{
for (l = list; l; l = l->next)
{
GladeWidget *child = glade_widget_get_from_gobject (l->data);
if (child)
glade_widget_write_child (child, context, widget_node);
else if (GLADE_IS_PLACEHOLDER (l->data))
glade_widget_write_placeholder (widget,
G_OBJECT (l->data),
context, widget_node);
}
g_list_free (list);
}
}
......
......@@ -216,11 +216,23 @@ void glade_widget_write (GladeWidget *wi
GladeXmlContext *context,
GladeXmlNode *node);
void glade_widget_write_child (GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node);
void glade_widget_write_placeholder (GladeWidget *parent,
GObject *object,
GladeXmlContext *context,
GladeXmlNode *node);
GladeWidget *glade_widget_read (GladeProject *project,
GladeWidget *parent,
GladeXmlNode *node,
const gchar *internal);
void glade_widget_read_child (GladeWidget *widget,
GladeXmlNode *node);
GladeEditorProperty *glade_widget_create_editor_property (GladeWidget *widget,
const gchar *property,
gboolean packing,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment