Mercurial > pidgin.yaz
changeset 13858:aa1c97f5e6eb
[gaim-migrate @ 16317]
Do the indentation in GntTree properly.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 23 Jun 2006 10:25:47 +0000 |
parents | d341b5ac1a78 |
children | 60278852c20c |
files | console/gntblist.c console/libgnt/gnttree.c console/libgnt/gntwidget.c |
diffstat | 3 files changed, 32 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/console/gntblist.c Fri Jun 23 09:38:48 2006 +0000 +++ b/console/gntblist.c Fri Jun 23 10:25:47 2006 +0000 @@ -10,8 +10,6 @@ #include "gntblist.h" -#define TAB_SIZE 3 - typedef struct { GntWidget *window; @@ -100,7 +98,6 @@ static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist) { - char *text; GaimGroup *group; GaimBlistNode *node = (GaimBlistNode *)buddy; if (node->ui_data) @@ -110,9 +107,7 @@ group = gaim_buddy_get_group(buddy); add_group(group, ggblist); - text = g_strdup_printf("%*s%s", TAB_SIZE, "", gaim_buddy_get_alias(buddy)); - gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, text, group, NULL); - g_free(text); + gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, gaim_buddy_get_alias(buddy), group, NULL); } static void
--- a/console/libgnt/gnttree.c Fri Jun 23 09:38:48 2006 +0000 +++ b/console/libgnt/gnttree.c Fri Jun 23 10:25:47 2006 +0000 @@ -5,6 +5,8 @@ SIGS = 1, }; +#define TAB_SIZE 3 + /* XXX: Make this one into a GObject? * ... Probably not */ struct _GnTreeRow @@ -202,12 +204,21 @@ return type; } +static void +free_tree_row(gpointer data) +{ + GntTreeRow *row = data; + + g_free(row->text); + g_free(row); +} + GntWidget *gnt_tree_new() { GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); GntTree *tree = GNT_TREE(widget); - tree->hash = g_hash_table_new(g_direct_hash, g_direct_equal); + tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); gnt_widget_set_take_focus(widget, TRUE); @@ -246,14 +257,24 @@ redraw_tree(tree); } +static int +find_depth(GntTreeRow *row) +{ + int dep = -1; + + while (row) + { + dep++; + row = row->parent; + } + + return dep; +} + void gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) { GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; - row->key = key; - row->text = g_strdup(text); - row->data = NULL; - g_hash_table_insert(tree->hash, key, row); if (tree->root == NULL) @@ -308,6 +329,10 @@ } } + row->key = key; + row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); + row->data = NULL; + if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) redraw_tree(tree); }
--- a/console/libgnt/gntwidget.c Fri Jun 23 09:38:48 2006 +0000 +++ b/console/libgnt/gntwidget.c Fri Jun 23 10:25:47 2006 +0000 @@ -224,6 +224,7 @@ delwin(obj->window); if(!(GNT_WIDGET_FLAGS(obj) & GNT_WIDGET_DESTROYING)) g_object_run_dispose(G_OBJECT(obj)); + /* XXX: This may be the wrong place */ gnt_screen_remove_widget(obj); DEBUG; }