diff --git a/lib/widget/history.c b/lib/widget/history.c index e01b5b2ca..737bcbe34 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -315,8 +315,9 @@ history_save (mc_config_t * cfg, const char *name, GList * h) char * history_show (GList ** history, Widget * widget, int current, int *action) { - GList *z, *hlist = NULL, *hi; - size_t maxlen, count = 0; + GList *z, *hi; + GQueue *hlist; + size_t maxlen, count; char *r = NULL; WDialog *query_dlg; WListbox *query_list; @@ -328,6 +329,8 @@ history_show (GList ** history, Widget * widget, int current, int *action) maxlen = str_term_width1 (_("History")) + 2; + hlist = g_queue_new (); + for (z = *history; z != NULL; z = g_list_previous (z)) { WLEntry *entry; @@ -335,14 +338,15 @@ history_show (GList ** history, Widget * widget, int current, int *action) i = str_term_width1 ((char *) z->data); maxlen = MAX (maxlen, i); - count++; entry = g_new0 (WLEntry, 1); /* history is being reverted here */ entry->text = g_strdup ((char *) z->data); - hlist = g_list_prepend (hlist, entry); + g_queue_push_head (hlist, entry); } + count = g_queue_get_length (hlist); + hist_data.widget = widget; hist_data.count = count; hist_data.maxlen = maxlen; @@ -379,7 +383,7 @@ history_show (GList ** history, Widget * widget, int current, int *action) { /* draw list entries from top downto bottom */ /* revert history direction */ - hlist = g_list_reverse (hlist); + g_queue_reverse (hlist); listbox_set_list (query_list, hlist); if (current > 0) listbox_select_entry (query_list, current); diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 1c5ddb5e3..f1423a9d5 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -760,22 +760,19 @@ listbox_is_empty (const WListbox * l) /* --------------------------------------------------------------------------------------------- */ +/** + * Set new listbox items list. + * + * @param l WListbox object + * @param list list of WLEntry objects + */ void -listbox_set_list (WListbox * l, GList * list) +listbox_set_list (WListbox * l, GQueue * list) { listbox_remove_list (l); if (l != NULL) - { - GList *ll; - - l->list = g_queue_new (); - - for (ll = list; ll != NULL; ll = g_list_next (ll)) - g_queue_push_tail (l->list, ll->data); - - g_list_free (list); - } + l->list = list; } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/listbox.h b/lib/widget/listbox.h index 396678736..0a46e88ab 100644 --- a/lib/widget/listbox.h +++ b/lib/widget/listbox.h @@ -73,7 +73,7 @@ WLEntry *listbox_get_nth_item (const WListbox * l, int pos); GList *listbox_get_first_link (const WListbox * l); void listbox_remove_current (WListbox * l); gboolean listbox_is_empty (const WListbox * l); -void listbox_set_list (WListbox * l, GList * list); +void listbox_set_list (WListbox * l, GQueue * list); void listbox_remove_list (WListbox * l); char *listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text, void *data, gboolean free_data);