Ticket #1460 (shared search history)

* The sample of the containing text by file search;
    * The sample of search in file mcview;
    * The sample of search in mcedit (search operation);
    * The substituting text in mceditor (replacement operation).

    Author: Alexey Korop

    Signed-off-by: Ilia Maslakov <il.smind@gmail.com>

    Editor: search will continue from last search string if SHIFT+F7 hotkey pressed
    at first time (without pressed F7 key).

    Signed-off-by: Slava Zanko <slavazanko@gmail.com>

    add const MC_HISTORY_SHARED_SEARCH into history.h

    Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Ilia Maslakov 2009-08-04 18:53:41 +00:00 committed by Ilia Maslakov
parent 69e6f3c7d6
commit 99c8f6a680
5 changed files with 50 additions and 44 deletions

View File

@ -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);

View File

@ -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},

View File

@ -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:")));

View File

@ -38,4 +38,6 @@
#define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add"
#define MC_HISTORY_SHARED_SEARCH "mc.shared.search"
#endif

View File

@ -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},