comparison console/libgnt/gnttree.c @ 14712:b15c2eaeb67f

[gaim-migrate @ 17466] Patch #1573404 from Richard Nelson (wabz): "This patch keeps the blist sorted (sorts rows at the current depth when the text for a given row changes). Adds a menu "Options" to the blist and adds the options to sort by status, alphabetically and toggle offline buddies." I changed some of the stuff from the patch. Hopefully I didn't break anything. I also added a "Sort by log size" option. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 12 Oct 2006 03:26:33 +0000
parents f1f1dcb26d89
children 811464ba52de
comparison
equal deleted inserted replaced
14711:556a112ab6ca 14712:b15c2eaeb67f
42 int span; /* How many columns does it span? */ 42 int span; /* How many columns does it span? */
43 }; 43 };
44 44
45 static GntWidgetClass *parent_class = NULL; 45 static GntWidgetClass *parent_class = NULL;
46 static guint signals[SIGS] = { 0 }; 46 static guint signals[SIGS] = { 0 };
47
48 /* Move the item at position old to position new */
49 static GList *
50 g_list_reposition_child(GList *list, int old, int new)
51 {
52 gpointer item = g_list_nth_data(list, old);
53 list = g_list_remove(list, item);
54 if (old < new)
55 new--; /* because the positions would have shifted after removing the item */
56 list = g_list_insert(list, item, new);
57 return list;
58 }
47 59
48 static GntTreeRow * 60 static GntTreeRow *
49 _get_next(GntTreeRow *row, gboolean godeep) 61 _get_next(GntTreeRow *row, gboolean godeep)
50 { 62 {
51 if (row == NULL) 63 if (row == NULL)
835 return row->key; 847 return row->key;
836 } 848 }
837 return NULL; 849 return NULL;
838 } 850 }
839 851
852 void gnt_tree_sort_row(GntTree *tree, gpointer key)
853 {
854 GntTreeRow *row, *q, *s;
855 int current, newp;
856
857 if (!tree->compare)
858 return;
859
860 row = g_hash_table_lookup(tree->hash, key);
861 g_return_if_fail(row != NULL);
862
863 current = g_list_index(tree->list, key);
864
865 if (row->parent)
866 s = row->parent->child;
867 else
868 s = tree->root;
869
870 q = NULL;
871 while (s) {
872 if (tree->compare(row->key, s->key) < 0)
873 break;
874 q = s;
875 s = s->next;
876 }
877
878 /* Move row between q and s */
879 if (row == q || row == s)
880 return;
881
882 if (q == NULL) {
883 /* row becomes the first child of its parent */
884 row->prev->next = row->next; /* row->prev cannot be NULL at this point */
885 if (row->next)
886 row->next->prev = row->prev;
887 if (row->parent)
888 row->parent->child = row;
889 else
890 tree->root = row;
891 row->next = s;
892 s->prev = row; /* s cannot be NULL */
893 row->prev = NULL;
894 newp = g_list_index(tree->list, s) - 1;
895 } else {
896 if (row->prev) {
897 row->prev->next = row->next;
898 } else {
899 /* row was the first child of its parent */
900 if (row->parent)
901 row->parent->child = row->next;
902 else
903 tree->top = row->next;
904 }
905
906 if (row->next)
907 row->next->prev = row->prev;
908
909 q->next = row;
910 row->prev = q;
911 if (s)
912 s->prev = row;
913 row->next = s;
914 newp = g_list_index(tree->list, q) + 1;
915 }
916 tree->list = g_list_reposition_child(tree->list, current, newp);
917
918 redraw_tree(tree);
919 }
920
840 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) 921 GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro)
841 { 922 {
842 GntTreeRow *pr = NULL; 923 GntTreeRow *pr = NULL;
843 924
844 g_hash_table_replace(tree->hash, key, row); 925 g_hash_table_replace(tree->hash, key, row);