mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
* 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:
parent
78d356ed89
commit
9df32b5790
@ -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"
|
||||
|
@ -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 ();
|
||||
|
@ -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 ();
|
||||
|
||||
|
16
src/widget.c
16
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++;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user