mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
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 <aborodin@vmail.ru>
This commit is contained in:
parent
a1552e9f06
commit
35de934437
@ -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() */
|
||||
|
17
src/find.c
17
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)
|
||||
|
86
src/widget.c
86
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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user