diff --git a/edit/editcmd.c b/edit/editcmd.c index ea41c9cfe..e421ac3f0 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -1389,18 +1389,15 @@ edit_replace_cmd (WEdit *edit, int again) g_free (saved1), saved1 = g_strdup (input1); g_free (saved2), saved2 = g_strdup (input2); - if (edit->search) - { + if (edit->search) { mc_search_free(edit->search); edit->search = NULL; } } - if (!edit->search) - { + if (!edit->search) { edit->search = mc_search_new(input1, -1); - if (edit->search == NULL) - { + if (edit->search == NULL) { edit->search_start = edit->curs1; return; } @@ -1422,10 +1419,9 @@ edit_replace_cmd (WEdit *edit, int again) gsize len = 0; long new_start; - if (! editcmd_find(edit, &len)) - { - if (!(edit->search->error == MC_SEARCH_E_OK || (once_found && edit->search->error == MC_SEARCH_E_NOTFOUND))) - { + if (! editcmd_find(edit, &len)) { + if (!(edit->search->error == MC_SEARCH_E_OK || + (once_found && edit->search->error == MC_SEARCH_E_NOTFOUND))) { edit_error_dialog (_ ("Search"), edit->search->error_str); } break; @@ -1543,15 +1539,25 @@ void edit_search_cmd (WEdit * edit, int again) if (!edit) return; - if (edit->search != NULL) - search_string_dup = search_string = g_strndup(edit->search->original, edit->search->original_len); + if (edit->search != NULL) { + search_string = g_strndup(edit->search->original, edit->search->original_len); + search_string_dup = search_string; + } else { + GList *history; + history = history_get (MC_HISTORY_SHARED_SEARCH); + if (history != NULL && history->data != NULL) { + search_string_dup = search_string = (char *) g_strdup(history->data); + history = g_list_first (history); + g_list_foreach (history, (GFunc) g_free, NULL); + g_list_free (history); + } + edit->search_start = edit->curs1; + } - if (!again) - { + if (!again) { #ifdef HAVE_CHARSET GString *tmp; - if (search_string && *search_string) - { + if (search_string && *search_string) { tmp = str_convert_to_display (search_string); g_free(search_string_dup); @@ -1564,8 +1570,7 @@ void edit_search_cmd (WEdit * edit, int again) #endif /* HAVE_CHARSET */ editcmd_dialog_search_show (edit, &search_string); #ifdef HAVE_CHARSET - if (search_string && *search_string) - { + if (search_string && *search_string) { tmp = str_convert_to_input (search_string); if (tmp && tmp->len) search_string = tmp->str; @@ -1579,25 +1584,21 @@ void edit_search_cmd (WEdit * edit, int again) edit_push_action (edit, KEY_PRESS + edit->start_display); - if (!search_string) - { + if (!search_string) { edit->force |= REDRAW_COMPLETELY; edit_scroll_screen_over_cursor (edit); return; } - if (edit->search) - { + if (edit->search) { mc_search_free(edit->search); edit->search = NULL; } } - if (!edit->search) - { + if (!edit->search) { edit->search = mc_search_new(search_string, -1); - if (edit->search == NULL) - { + if (edit->search == NULL) { edit->search_start = edit->curs1; return; } @@ -1607,12 +1608,9 @@ void edit_search_cmd (WEdit * edit, int again) edit->search->search_fn = edit_search_cmd_callback; } - if (search_create_bookmark) - { + if (search_create_bookmark) { edit_search_cmd_search_create_bookmark(edit); - } - else - { + } else { if (edit->found_len && edit->search_start == edit->found_start + 1 && edit->replace_backwards) edit->search_start--; @@ -1620,8 +1618,7 @@ void edit_search_cmd (WEdit * edit, int again) edit->search_start++; - if (editcmd_find(edit, &len)) - { + if (editcmd_find(edit, &len)) { edit->found_start = edit->search_start = edit->search->normal_offset; edit->found_len = len; @@ -1631,9 +1628,7 @@ void edit_search_cmd (WEdit * edit, int again) edit->search_start--; else edit->search_start++; - } - else - { + } else { edit->search_start = edit->curs1; if (edit->search->error_str) edit_error_dialog (_ ("Search"), edit->search->error_str); diff --git a/edit/editcmd_dialogs.c b/edit/editcmd_dialogs.c index fdef0cd82..70caf2e50 100644 --- a/edit/editcmd_dialogs.c +++ b/edit/editcmd_dialogs.c @@ -39,6 +39,7 @@ #include "../src/key.h" #include "../src/main.h" #include "../src/search/search.h" +#include "../src/history.h" #include "../edit/etags.h" #include "editcmd_dialogs.h" @@ -91,6 +92,8 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + g_strv_length (list_of_types) - REPLACE_DLG_HEIGHT_SUPPLY; + if (!*search_default) + search_default = INPUT_LAST_TEXT; QuickWidget quick_widgets[] = { @@ -119,14 +122,14 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha 0, 0, 0, 0, 0, NULL, NULL}, {quick_input, 3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT, replace_default, 52, 0, - 0, replace_text, "edit-replace", NULL, NULL}, + 0, replace_text, "replace", NULL, NULL}, {quick_label, 2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 0, 0, 0, NULL, NULL}, {quick_input, 3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT, search_default, 52, 0, - 0, search_text, "edit-search", NULL, NULL}, + 0, search_text, MC_HISTORY_SHARED_SEARCH, NULL, NULL}, NULL_QuickWidget @@ -173,6 +176,8 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text) gchar **list_of_types = mc_search_get_types_strings_array(); int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + g_strv_length (list_of_types) - SEARCH_DLG_HEIGHT_SUPPLY; + if (!*search_text) + *search_text = INPUT_LAST_TEXT; QuickWidget quick_widgets[] = { {quick_button, 6, 10, 9, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0, @@ -195,7 +200,7 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text) (void *) &ttype_of_search, const_cast (char **, list_of_types), NULL, NULL, NULL}, {quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, *search_text, 52, 0, 0, - search_text, "edit-search", NULL, NULL}, + search_text, MC_HISTORY_SHARED_SEARCH, NULL, NULL}, {quick_label, 2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 0, 0, 0, NULL, NULL}, diff --git a/src/find.c b/src/find.c index db64193ef..451599a60 100644 --- a/src/find.c +++ b/src/find.c @@ -49,6 +49,7 @@ #include "boxes.h" #include "key.h" #include "../src/search/search.h" +#include "history.h" /* MC_HISTORY_SHARED_SEARCH */ /* Size of the find parameters window */ #if HAVE_CHARSET @@ -359,18 +360,21 @@ 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, "content", INPUT_COMPLETE_DEFAULT); + in_with = input_new (6, FIND_X / 2 + 1, INPUT_COLOR, FIND_X / 2 - 4, in_contents, + 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:"))); - in_name = input_new (6, 3, INPUT_COLOR, FIND_X / 2 - 4, in_start_name, "name", INPUT_COMPLETE_DEFAULT); + in_name = input_new (6, 3, INPUT_COLOR, FIND_X / 2 - 4, in_start_name, "name", + INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_name); add_widget (find_dlg, label_new (5, 3, _("File name:"))); add_widget (find_dlg, button_new (3, FIND_X - b2 - 2, B_TREE, NORMAL_BUTTON, buts[2], 0)); - in_start = input_new (3, 3, INPUT_COLOR, FIND_X - b2 - 6, in_start_dir, "start", INPUT_COMPLETE_DEFAULT); + in_start = input_new (3, 3, INPUT_COLOR, FIND_X - b2 - 6, in_start_dir, "start", + INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_start); add_widget (find_dlg, label_new (2, 3, _("Start at:"))); diff --git a/src/history.h b/src/history.h index 96b31fa03..85cfcc9d1 100644 --- a/src/history.h +++ b/src/history.h @@ -38,4 +38,6 @@ #define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add" +#define MC_HISTORY_SHARED_SEARCH "mc.shared.search" + #endif diff --git a/src/view.c b/src/view.c index b9aa24780..8a6e8c208 100644 --- a/src/view.c +++ b/src/view.c @@ -65,7 +65,7 @@ #include "execute.h" #include "main.h" /* slow_terminal */ #include "view.h" -#include "history.h" +#include "history.h" /* MC_HISTORY_SHARED_SEARCH */ #include "charsets.h" #include "selcodepage.h" #include "strutil.h" @@ -3297,7 +3297,7 @@ view_search_cmd (WView *view) {quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, defval, 52, 0, - 0, &exp, N_("Search"), NULL, NULL}, + 0, &exp, MC_HISTORY_SHARED_SEARCH, NULL, NULL}, {quick_label, 2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:"), 0, 0, 0, 0, 0, NULL, NULL},