* 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.
This commit is contained in:
Pavel Tsekov 2007-09-24 13:38:48 +00:00
parent 78d356ed89
commit 9df32b5790
5 changed files with 31 additions and 5 deletions

View File

@ -1,3 +1,12 @@
2007-09-24 David Sterba <dave@jikos.cz>
* 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 <ptsekov@gmx.net>
* cmd.c (menu_edit_cmd): Rename a button label from "Home"

View File

@ -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 ();

View File

@ -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 ();

View File

@ -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++;
}

View File

@ -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