On Thu, Mar 22, Matt Hillebrand wrote:
> What's a good way to save everything in a CTree to a file so that the
> tree can be easily rebuilt using this file?
>
> It's easy to get the data in each column, but I can't think of a good way
> to represent the nodes' structure (parents, children, siblings...) in a
> file.
I'd suggest using XML, e.g. by libxml. Below is a code fragment to
draw an XML doc into a tree, two attributes are used, "text" and
"expanded", extend it for your needs. The reverse should also be
simple. Or you hold the data all the time in an xmlDoc, and only use
the GtkCTree to display the data.
Sebastian
---8<------8<------8<------8<------8<------8<------8<------8<------8<---
void draw_xml (xmlDoc *xml,
GtkCTree *tree)
{
gtk_clist_freeze (GTK_CLIST (tree));
gtk_clist_clear (GTK_CLIST (tree));
draw_xml_node (xml->root, tree, NULL);
gtk_clist_thaw (GTK_CLIST (tree));
}
static void draw_xml_node (xmlNode *xml_node,
GtkCTree *tree,
GtkCTreeNode *tree_node)
{
xmlNode *xml_it;
GtkCTreeNode *tree_it;
char *text, *expanded;
int is_expanded;
for(xml_it = xml_node->childs; xml_it; xml_it = xml_it->next) {
text = xmlGetProp(xml_it, "text");
expanded = xmlGetProp(xml_it, "expanded");
is_expanded = expanded == NULL || strcasecmp (expanded, "no") != 0;
tree_it = gtk_ctree_insert_node (tree, tree_node, NULL,
&text, 5, NULL, NULL, NULL, NULL,
FALSE, is_expanded);
draw_xml_node(xml_it, tree, tree_it);
}
}
_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list