Ticket #1460 (shared search history)

fix: history for mcview (last search string geting from history)

Signed-off-by: Ilia Maslakov <il.smind@google.com>
This commit is contained in:
Ilia Maslakov 2009-08-31 14:48:54 +00:00
parent de33d013be
commit 0ce827bb60
2 changed files with 35 additions and 11 deletions

View File

@ -78,11 +78,41 @@
static void
mcview_continue_search_cmd (mcview_t * view)
{
if (view->last_search_string != NULL) {
mcview_do_search (view);
} else {
/* if not... then ask for an expression */
mcview_search_cmd (view);
/* find last search string in history */
GList *history;
history = history_get (MC_HISTORY_SHARED_SEARCH);
if (history != NULL && history->data != NULL) {
view->last_search_string = (gchar *) g_strdup(history->data);
history = g_list_first (history);
g_list_foreach (history, (GFunc) g_free, NULL);
g_list_free (history);
view->search = mc_search_new (view->last_search_string, -1);
view->search_nroff_seq = mcview_nroff_seq_new (view);
if (!view->search) {
/* if not... then ask for an expression */
g_free(view->last_search_string);
mcview_search_cmd (view);
} else {
view->search->search_type = view->search_type;
view->search->is_all_charsets = view->search_all_codepages;
view->search->is_case_sentitive = view->search_case;
view->search->search_fn = mcview_search_cmd_callback;
view->search->update_fn = mcview_search_update_cmd_callback;
view->search->whole_words = view->whole_words;
mcview_do_search (view);
}
} else {
/* if not... then ask for an expression */
g_free(view->last_search_string);
mcview_search_cmd (view);
}
}
}

View File

@ -40,6 +40,7 @@
#include "../src/global.h"
#include "../src/wtools.h"
#include "internal.h"
#include "../src/history.h"
#include "../src/charsets.h"
/*** global variables ****************************************************************************/
@ -65,7 +66,6 @@ mcview_dialog_search (mcview_t * view)
SEARCH_DLG_WIDTH = 58
};
char *defval = g_strdup (view->last_search_string != NULL ? view->last_search_string : "");
char *exp = NULL;
#ifdef HAVE_CHARSET
GString *tmp;
@ -111,8 +111,8 @@ mcview_dialog_search (mcview_t * view)
(void *) &ttype_of_search, const_cast (char **, list_of_types), NULL, NULL, NULL},
{quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, defval, 52, 0,
0, &exp, N_("Search"), NULL, NULL},
{quick_input, 3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT, INPUT_LAST_TEXT, 52, 0,
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},
@ -125,14 +125,11 @@ mcview_dialog_search (mcview_t * view)
"[Input Line Keys]", quick_widgets, 0
};
convert_to_display (defval);
qd_result = quick_dialog (&Quick_input);
g_strfreev (list_of_types);
if (qd_result == B_CANCEL) {
g_free (exp);
g_free (defval);
return FALSE;
}
@ -145,7 +142,6 @@ mcview_dialog_search (mcview_t * view)
if (exp == NULL || exp[0] == '\0') {
g_free (exp);
g_free (defval);
return FALSE;
}
#ifdef HAVE_CHARSET
@ -171,7 +167,6 @@ mcview_dialog_search (mcview_t * view)
view->search_nroff_seq = mcview_nroff_seq_new (view);
if (!view->search) {
g_free (exp);
g_free (defval);
return FALSE;
}
@ -183,6 +178,5 @@ mcview_dialog_search (mcview_t * view)
view->search->whole_words = view->whole_words;
g_free (exp);
g_free (defval);
return TRUE;
}