From 35de934437c8aefc1edea09a6f5ab0d963a894f4 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 11 Nov 2009 11:06:26 +0300 Subject: [PATCH] Ticket #1814: allow save empty value in history. Problem: 'Find File' dialog doesn't save an empty "content" filed on exit. Proposed solution: allow each history (not in content in 'Find File' dialog only) save an empty value. Signed-off-by: Andrew Borodin --- src/cmd.c | 1 - src/find.c | 17 +++--------- src/widget.c | 86 +++++++++++++++++++++--------------------------------------- src/widget.h | 1 - 4 files changed, 33 insertions(+), 72 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index dcfa5ee8..220f781b 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -66,7 +66,6 @@ #include "cons.saver.h" /* console_flag */ #include "dialog.h" /* Widget */ #include "wtools.h" /* message() */ -#include "widget.h" /* push_history() */ #include "main.h" /* change_panel() */ #include "panel.h" /* current_panel */ #include "help.h" /* interactive_display() */ diff --git a/src/find.c b/src/find.c index bfb08d99..a8df52ee 100644 --- a/src/find.c +++ b/src/find.c @@ -150,7 +150,6 @@ static struct { { N_("&Edit - F4"), 13, 38 } }; -static const char *in_contents = NULL; static char *in_start_dir = INPUT_LAST_TEXT; static mc_search_t *search_file_handle = NULL; @@ -324,9 +323,6 @@ find_parameters (char **start_dir, char **pattern, char **content) b2 = str_term_width1 (buts[2]) + 4; find_par_start: - if (in_contents == NULL) - in_contents = INPUT_LAST_TEXT; - if (in_start_dir == NULL) in_start_dir = g_strdup ("."); @@ -376,7 +372,7 @@ find_parameters (char **start_dir, char **pattern, char **content) file_case_sens_cbox = check_new (7, 3, file_case_sens_flag, file_case_label); add_widget (find_dlg, file_case_sens_cbox); - in_with = input_new (6, FIND_X / 2 + 1, INPUT_COLOR, FIND_X / 2 - 4, in_contents, + in_with = input_new (6, FIND_X / 2 + 1, INPUT_COLOR, FIND_X / 2 - 4, INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_with); add_widget (find_dlg, label_new (5, FIND_X / 2 + 1, _("Content:"))); @@ -414,6 +410,7 @@ find_parameters (char **start_dir, char **pattern, char **content) file_case_sens_flag = file_case_sens_cbox->state & C_BOOL; find_recurs_flag = recursively_cbox->state & C_BOOL; skip_hidden_flag = skip_hidden_cbox->state & C_BOOL; + destroy_dlg (find_dlg); if (in_start_dir != INPUT_LAST_TEXT) g_free (in_start_dir); @@ -445,15 +442,7 @@ find_parameters (char **start_dir, char **pattern, char **content) file_case_sens_flag = file_case_sens_cbox->state & C_BOOL; skip_hidden_flag = skip_hidden_cbox->state & C_BOOL; - /* keep empty Content field */ - /* if not empty, fill from history */ - *content = NULL; - in_contents = ""; - if (in_with->buffer[0] != '\0') { - *content = g_strdup (in_with->buffer); - in_contents = INPUT_LAST_TEXT; - } - + *content = (in_with->buffer[0] != '\0') ? g_strdup (in_with->buffer) : NULL; *start_dir = g_strdup ((in_start->buffer[0] != '\0') ? in_start->buffer : "."); *pattern = g_strdup (in_name->buffer); if (in_start_dir != INPUT_LAST_TEXT) diff --git a/src/widget.c b/src/widget.c index 19c7eb2f..0f255e70 100644 --- a/src/widget.c +++ b/src/widget.c @@ -1021,7 +1021,7 @@ history_get (const char *input_name) g_snprintf (key_name, sizeof (key_name), "%lu", (unsigned long)i); this_entry = mc_config_get_string (cfg, input_name, key_name, ""); - if (this_entry && *this_entry) + if (this_entry != NULL) hist = list_append_unique (hist, this_entry); } @@ -1076,12 +1076,10 @@ history_put (const char *input_name, GList *h) /* dump histories into profile */ for (i = 0; h; h = g_list_next (h)) { - char *text; - - text = (char *) h->data; + char *text = (char *) h->data; /* We shouldn't have null entries, but let's be sure */ - if (text && *text) { + if (text != NULL) { char key_name[BUF_TINY]; g_snprintf (key_name, sizeof (key_name), "%d", i++); mc_config_set_string(cfg,input_name, key_name, text); @@ -1296,67 +1294,56 @@ input_enable_update (WInput *in) update_input (in, 0); } -#define ELEMENTS(a) (sizeof(a)/sizeof(a[0])) -int +static void push_history (WInput *in, const char *text) { - static int i18n; /* input widget where urls with passwords are entered without any vfs prefix */ - static const char *password_input_fields[] = { + const char *password_input_fields[] = { N_(" Link to a remote machine "), N_(" FTP to machine "), N_(" SMB link to machine ") }; + const size_t ELEMENTS = (sizeof (password_input_fields) / + sizeof (password_input_fields[0])); + char *t; - const char *p; size_t i; + gboolean empty; - if (!i18n) { - i18n = 1; - for (i = 0; i < ELEMENTS (password_input_fields); i++) - password_input_fields[i] = _(password_input_fields[i]); - } + if (text == NULL) + return; - for (p = text; *p == ' ' || *p == '\t'; p++); - if (!*p) - return 0; +#ifdef ENABLE_NLS + for (i = 0; i < ELEMENTS; i++) + password_input_fields[i] = _(password_input_fields[i]); +#endif - if (in->history) { - /* Avoid duplicated entries */ - in->history = g_list_last (in->history); - if (!strcmp ((char *) in->history->data, text)) - return 1; - } + t = g_strstrip (g_strdup (text)); + empty = *t == '\0'; + g_free (t); + t = g_strdup (empty ? "" : text); - t = g_strdup (text); + if (in->history_name != NULL) { + const char *p = in->history_name + 3; - if (in->history_name) { - p = in->history_name + 3; - for (i = 0; i < ELEMENTS (password_input_fields); i++) + for (i = 0; i < ELEMENTS; i++) if (strcmp (p, password_input_fields[i]) == 0) break; - if (i < ELEMENTS (password_input_fields)) - strip_password (t, 0); - else - strip_password (t, 1); + + strip_password (t, i >= ELEMENTS); } in->history = list_append_unique (in->history, t); in->need_push = 0; - - return 2; } -#undef ELEMENTS - /* Cleans the input line and adds the current text to the history */ void new_input (WInput *in) { - if (in->buffer) - push_history (in, in->buffer); + push_history (in, in->buffer); in->need_push = 1; in->buffer[0] = '\0'; in->point = 0; @@ -1717,17 +1704,8 @@ hist_prev (WInput *in) return; if (in->need_push) { - switch (push_history (in, in->buffer)) { - case 2: - in->history = g_list_previous (in->history); - break; - case 1: - if (in->history->prev) - in->history = g_list_previous (in->history); - break; - case 0: - break; - } + push_history (in, in->buffer); + in->history = g_list_previous (in->history); } else if (in->history->prev) in->history = g_list_previous (in->history); else @@ -1740,13 +1718,9 @@ static void hist_next (WInput *in) { if (in->need_push) { - switch (push_history (in, in->buffer)) { - case 2: - assign_text (in, ""); - return; - case 0: - return; - } + push_history (in, in->buffer); + assign_text (in, ""); + return; } if (!in->history) diff --git a/src/widget.h b/src/widget.h index 2760c84c..82535273 100644 --- a/src/widget.h +++ b/src/widget.h @@ -200,7 +200,6 @@ cb_ret_t handle_char (WInput *in, int c_code); int is_in_input_map (WInput *in, int c_code); void update_input (WInput *in, int clear_first); void new_input (WInput *in); -int push_history (WInput *in, const char *text); void stuff (WInput *in, const char *text, int insert_extra_space); void input_disable_update (WInput *in); void input_set_prompt (WInput *in, int field_len, const char *prompt); -- 2.11.4.GIT