mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Optimization of history saving.
Now history is not saved if it was not modified and content of input
line is equal to history top entry. Thanks Francesco Cosoleto
<cosoleto at gmail dot com> for the original patch.
Also fixed a regression introduced in cff5925598
:
after CK_HistoryNext and CK_HistoryPrev actions in input line,
the input line content is not put to the top of history.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
1a343a1a47
commit
5ffcffbeb6
@ -83,6 +83,19 @@ static char *kill_buffer = NULL;
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static size_t
|
||||
get_history_length (const GList *history)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
for (; history != NULL; history = g_list_previous (history))
|
||||
len++;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
draw_history_button (WInput * in)
|
||||
{
|
||||
@ -170,14 +183,21 @@ delete_region (WInput * in, int x_first, int x_last)
|
||||
static void
|
||||
do_show_hist (WInput * in)
|
||||
{
|
||||
size_t len;
|
||||
char *r;
|
||||
|
||||
len = get_history_length (in->history);
|
||||
|
||||
r = history_show (&in->history, &in->widget);
|
||||
if (r != NULL)
|
||||
{
|
||||
input_assign_text (in, r);
|
||||
g_free (r);
|
||||
}
|
||||
|
||||
/* Has history cleaned up or not? */
|
||||
if (len != get_history_length (in->history))
|
||||
in->history_changed = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -224,7 +244,13 @@ push_history (WInput * in, const char *text)
|
||||
strip_password (t, i >= ELEMENTS);
|
||||
}
|
||||
|
||||
if (in->history == NULL || in->history->data == NULL || strcmp (in->history->data, t) != 0 ||
|
||||
in->history_changed)
|
||||
{
|
||||
in->history = list_append_unique (in->history, t);
|
||||
in->history_changed = TRUE;
|
||||
}
|
||||
|
||||
in->need_push = FALSE;
|
||||
}
|
||||
|
||||
@ -584,6 +610,7 @@ hist_prev (WInput * in)
|
||||
if (prev != NULL)
|
||||
{
|
||||
in->history = prev;
|
||||
in->history_changed = TRUE;
|
||||
input_assign_text (in, (char *) prev->data);
|
||||
in->need_push = FALSE;
|
||||
}
|
||||
@ -612,6 +639,7 @@ hist_next (WInput * in)
|
||||
else
|
||||
{
|
||||
in->history = next;
|
||||
in->history_changed = TRUE;
|
||||
input_assign_text (in, (char *) next->data);
|
||||
in->need_push = FALSE;
|
||||
}
|
||||
@ -814,13 +842,14 @@ input_save_history (const gchar * event_group_name, const gchar * event_name,
|
||||
(void) event_group_name;
|
||||
(void) event_name;
|
||||
|
||||
if (in->history != NULL && !in->is_password && (((Widget *) in)->owner->ret_value != B_CANCEL))
|
||||
if (in->history != NULL && in->history_changed && !in->is_password &&
|
||||
(((Widget *) in)->owner->ret_value != B_CANCEL))
|
||||
{
|
||||
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
|
||||
|
||||
if (in->need_push)
|
||||
push_history (in, in->buffer);
|
||||
history_save (ev->cfg, in->history_name, in->history);
|
||||
in->history_changed = FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -942,8 +971,9 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex
|
||||
in->completion_flags = completion_flags;
|
||||
|
||||
/* prepare to history setup */
|
||||
in->history_name = NULL;
|
||||
in->history = NULL;
|
||||
in->history_changed = FALSE;
|
||||
in->history_name = NULL;
|
||||
if ((histname != NULL) && (*histname != '\0'))
|
||||
in->history_name = g_strdup (histname);
|
||||
|
||||
@ -1276,11 +1306,14 @@ input_disable_update (WInput * in)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Cleans the input line and adds the current text to the history */
|
||||
/**
|
||||
* Cleans the input line and adds the current text to the history
|
||||
*
|
||||
* @param in the input line
|
||||
*/
|
||||
void
|
||||
input_clean (WInput * in)
|
||||
{
|
||||
if (in->need_push)
|
||||
push_history (in, in->buffer);
|
||||
in->need_push = TRUE;
|
||||
in->buffer[0] = '\0';
|
||||
|
@ -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 */
|
||||
gboolean history_changed; /* the history has changed */
|
||||
gboolean need_push; /* need to push the current Input on hist? */
|
||||
char **completions; /* possible completions array */
|
||||
input_complete_t completion_flags;
|
||||
|
Loading…
Reference in New Issue
Block a user