mirror of https://github.com/MidnightCommander/mc
Handle history of input line.
Added pointer to the current history item and use to walk in history. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
f899f62a86
commit
c813d1baad
|
@ -2,7 +2,7 @@
|
|||
Widgets for the Midnight Commander
|
||||
|
||||
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
2004, 2005, 2006, 2007, 2009, 2010, 2011
|
||||
2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Authors:
|
||||
|
@ -11,7 +11,7 @@
|
|||
Jakub Jelinek, 1995
|
||||
Andrej Borsenkow, 1996
|
||||
Norbert Warmuth, 1997
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2011, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
|
@ -287,7 +287,7 @@ history_save (struct mc_config_t *cfg, const char *name, GList * h)
|
|||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
history_show (GList ** history, Widget * widget)
|
||||
history_show (GList ** history, Widget * widget, int current)
|
||||
{
|
||||
GList *z, *hlist = NULL, *hi;
|
||||
size_t maxlen, i, count = 0;
|
||||
|
@ -342,7 +342,10 @@ history_show (GList ** history, Widget * widget)
|
|||
{
|
||||
/* draw list entries from bottom upto top */
|
||||
listbox_set_list (query_list, hlist);
|
||||
listbox_select_last (query_list);
|
||||
if (current < 0 || (size_t) current >= count)
|
||||
listbox_select_last (query_list);
|
||||
else
|
||||
listbox_select_entry (query_list, count - 1 - (size_t) current);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -350,6 +353,8 @@ history_show (GList ** history, Widget * widget)
|
|||
/* revert history direction */
|
||||
hlist = g_list_reverse (hlist);
|
||||
listbox_set_list (query_list, hlist);
|
||||
if (current > 0)
|
||||
listbox_select_entry (query_list, current);
|
||||
}
|
||||
|
||||
if (run_dlg (query_dlg) != B_CANCEL)
|
||||
|
|
|
@ -29,7 +29,7 @@ GList *history_load (struct mc_config_t * cfg, const char *name);
|
|||
void history_save (struct mc_config_t * cfg, const char *name, GList * h);
|
||||
/* for repositioning of history dialog we should pass widget to this
|
||||
* function, as position of history dialog depends on widget's position */
|
||||
char *history_show (GList ** history, Widget * widget);
|
||||
char *history_show (GList ** history, Widget * widget, int current);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
|
|
@ -105,7 +105,13 @@ draw_history_button (WInput * in)
|
|||
char c;
|
||||
gboolean disabled = (((Widget *) in)->options & W_DISABLED) != 0;
|
||||
|
||||
c = in->history->next ? (in->history->prev ? '|' : 'v') : '^';
|
||||
if (g_list_next (in->history_current) == NULL)
|
||||
c = '^';
|
||||
else if (g_list_previous (in->history_current) == NULL)
|
||||
c = 'v';
|
||||
else
|
||||
c = '|';
|
||||
|
||||
widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH);
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]);
|
||||
#ifdef LARGE_HISTORY_BUTTON
|
||||
|
@ -191,7 +197,7 @@ do_show_hist (WInput * in)
|
|||
|
||||
len = get_history_length (in->history);
|
||||
|
||||
r = history_show (&in->history, &in->widget);
|
||||
r = history_show (&in->history, &in->widget, g_list_position (in->history_current, in->history));
|
||||
if (r != NULL)
|
||||
{
|
||||
input_assign_text (in, r);
|
||||
|
@ -268,6 +274,7 @@ push_history (WInput * in, const char *text)
|
|||
in->history_changed)
|
||||
{
|
||||
in->history = list_append_unique (in->history, t);
|
||||
in->history_current = in->history;
|
||||
in->history_changed = TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -628,12 +635,12 @@ hist_prev (WInput * in)
|
|||
if (in->need_push)
|
||||
push_history (in, in->buffer);
|
||||
|
||||
prev = g_list_previous (in->history);
|
||||
prev = g_list_previous (in->history_current);
|
||||
if (prev != NULL)
|
||||
{
|
||||
in->history = prev;
|
||||
in->history_changed = TRUE;
|
||||
input_assign_text (in, (char *) prev->data);
|
||||
in->history_current = prev;
|
||||
in->history_changed = TRUE;
|
||||
in->need_push = FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -655,14 +662,17 @@ hist_next (WInput * in)
|
|||
if (in->history == NULL)
|
||||
return;
|
||||
|
||||
next = g_list_next (in->history);
|
||||
next = g_list_next (in->history_current);
|
||||
if (next == NULL)
|
||||
{
|
||||
input_assign_text (in, "");
|
||||
in->history_current = in->history;
|
||||
}
|
||||
else
|
||||
{
|
||||
in->history = next;
|
||||
in->history_changed = TRUE;
|
||||
input_assign_text (in, (char *) next->data);
|
||||
in->history_current = next;
|
||||
in->history_changed = TRUE;
|
||||
in->need_push = FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -826,6 +836,7 @@ input_load_history (const gchar * event_group_name, const gchar * event_name,
|
|||
(void) event_name;
|
||||
|
||||
in->history = history_load (ev->cfg, in->history_name);
|
||||
in->history_current = in->history;
|
||||
|
||||
if (in->init_text == NULL)
|
||||
def_text = "";
|
||||
|
@ -1005,6 +1016,7 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex
|
|||
|
||||
/* prepare to history setup */
|
||||
in->history = NULL;
|
||||
in->history_current = NULL;
|
||||
in->history_changed = FALSE;
|
||||
in->history_name = NULL;
|
||||
if ((histname != NULL) && (*histname != '\0'))
|
||||
|
@ -1182,12 +1194,13 @@ input_assign_text (WInput * in, const char *text)
|
|||
{
|
||||
input_free_completions (in);
|
||||
g_free (in->buffer);
|
||||
in->buffer = g_strdup (text); /* was in->buffer->text */
|
||||
in->current_max_size = strlen (in->buffer) + 1;
|
||||
in->current_max_size = strlen (text) + 1;
|
||||
in->buffer = g_strndup (text, in->current_max_size); /* was in->buffer->text */
|
||||
in->point = str_length (in->buffer);
|
||||
in->mark = 0;
|
||||
in->need_push = TRUE;
|
||||
in->charpoint = 0;
|
||||
input_update (in, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef struct
|
|||
char *buffer; /* pointer to editing buffer */
|
||||
char *history_name; /* name of history for loading and saving */
|
||||
GList *history; /* the history */
|
||||
GList *history_current; /* current history item */
|
||||
gboolean history_changed; /* the history has changed */
|
||||
gboolean need_push; /* need to push the current Input on hist? */
|
||||
gboolean strip_password; /* need to strip password before placing string to history */
|
||||
|
|
|
@ -3122,7 +3122,7 @@ directory_history_list (WPanel * panel)
|
|||
{
|
||||
char *s;
|
||||
|
||||
s = history_show (&panel->dir_history, &panel->widget);
|
||||
s = history_show (&panel->dir_history, &panel->widget, -1);
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue