From 9df32b5790c77de0878ca12a955347794a611f88 Mon Sep 17 00:00:00 2001 From: Pavel Tsekov Date: Mon, 24 Sep 2007 13:38:48 +0000 Subject: [PATCH] * src/widget.h: Define new mode for listbox insertion. * src/widget.c (listbox_append_item): Implement LISTBOX_APPEND_SORTED by insertsort. * src/chown.c (init_chown): Use LISTBOX_APPEND_SORTED for user and group list. * src/achown.c (do_enter_key): Likewise. --- src/ChangeLog | 9 +++++++++ src/achown.c | 4 ++-- src/chown.c | 4 ++-- src/widget.c | 16 ++++++++++++++++ src/widget.h | 3 ++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cfc583781..29637b990 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2007-09-24 David Sterba + + * src/widget.h: Define new mode for listbox insertion. + * src/widget.c (listbox_append_item): Implement LISTBOX_APPEND_SORTED + by insertsort. + * src/chown.c (init_chown): Use LISTBOX_APPEND_SORTED for user and + group list. + * src/achown.c (do_enter_key): Likewise. + 2007-09-19 Pavel Tsekov * cmd.c (menu_edit_cmd): Rename a button label from "Home" diff --git a/src/achown.c b/src/achown.c index 1c5faadb6..0c9547768 100644 --- a/src/achown.c +++ b/src/achown.c @@ -265,7 +265,7 @@ do_enter_key (Dlg_head * h, int f_pos) /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ())) { - listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, + listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL); } endpwent (); @@ -275,7 +275,7 @@ do_enter_key (Dlg_head * h, int f_pos) /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ())) { - listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, + listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL); } endgrent (); diff --git a/src/chown.c b/src/chown.c index d0fe71419..2a00b8117 100644 --- a/src/chown.c +++ b/src/chown.c @@ -180,14 +180,14 @@ init_chown (void) /* get and put user names in the listbox */ setpwent (); while ((l_pass = getpwent ())) { - listbox_add_item (l_user, 0, 0, l_pass->pw_name, NULL); + listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL); } endpwent (); /* get and put group names in the listbox */ setgrent (); while ((l_grp = getgrent ())) { - listbox_add_item (l_group, 0, 0, l_grp->gr_name, NULL); + listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL); } endgrent (); diff --git a/src/widget.c b/src/widget.c index fa83b3efc..7e46af305 100644 --- a/src/widget.c +++ b/src/widget.c @@ -2200,6 +2200,22 @@ listbox_append_item (WListbox *l, WLEntry *e, enum append_pos pos) e->next = l->current->next; l->current->next->prev = e; l->current->next = e; + } else if (pos == LISTBOX_APPEND_SORTED) { + WLEntry *w = l->list; + + while (w->next != l->list && strcmp (e->text, w->text) > 0) + w = w->next; + if (w->next == l->list) { + e->prev = w; + e->next = l->list; + w->next = e; + l->list->prev = e; + } else { + e->next = w; + e->prev = w->prev; + w->prev->next = e; + w->prev = e; + } } l->count++; } diff --git a/src/widget.h b/src/widget.h index ac70a4174..309983012 100644 --- a/src/widget.h +++ b/src/widget.h @@ -175,7 +175,8 @@ void listbox_get_current (WListbox *l, char **string, char **extra); enum append_pos { LISTBOX_APPEND_AT_END, /* append at the end */ LISTBOX_APPEND_BEFORE, /* insert before current */ - LISTBOX_APPEND_AFTER /* insert after current */ + LISTBOX_APPEND_AFTER, /* insert after current */ + LISTBOX_APPEND_SORTED /* insert alphabetically */ }; char *listbox_add_item (WListbox *l, enum append_pos pos, int