mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
mcviewer: refactoring of search.
(mcview_search_init): new function: initialization of search handler. (mcview_search_deinit): new function: deinitialization of search handler. (mcview_dialog_search): use mcview_search_init() and mcview_search_deinit(). (mcview_continue_search_cmd): use mcview_search_init(). (mcview_dialog_search): use mcview_search_deinit(). (mcview_search_options) move definition from dialogs.c to search.c. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
37b86b2781
commit
65ca3da3b2
@ -147,33 +147,15 @@ mcview_continue_search_cmd (WView * view)
|
|||||||
history = g_list_first (history);
|
history = g_list_first (history);
|
||||||
g_list_free_full (history, g_free);
|
g_list_free_full (history, g_free);
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
if (!mcview_search_init (view))
|
||||||
view->search = mc_search_new (view->last_search_string, cp_source);
|
|
||||||
#else
|
|
||||||
view->search = mc_search_new (view->last_search_string, NULL);
|
|
||||||
#endif
|
|
||||||
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
|
||||||
|
|
||||||
if (view->search == NULL)
|
|
||||||
{
|
{
|
||||||
/* if not... then ask for an expression */
|
/* if not... then ask for an expression */
|
||||||
MC_PTR_FREE (view->last_search_string);
|
MC_PTR_FREE (view->last_search_string);
|
||||||
mcview_search (view, TRUE);
|
mcview_search (view, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
view->search->search_type = mcview_search_options.type;
|
|
||||||
#ifdef HAVE_CHARSET
|
|
||||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
|
||||||
#endif
|
|
||||||
view->search->is_case_sensitive = mcview_search_options.case_sens;
|
|
||||||
view->search->whole_words = mcview_search_options.whole_words;
|
|
||||||
view->search->search_fn = mcview_search_cmd_callback;
|
|
||||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
|
||||||
|
|
||||||
mcview_search (view, FALSE);
|
mcview_search (view, FALSE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* if not... then ask for an expression */
|
/* if not... then ask for an expression */
|
||||||
|
@ -52,14 +52,6 @@
|
|||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
mcview_search_options_t mcview_search_options = {
|
|
||||||
.type = MC_SEARCH_T_NORMAL,
|
|
||||||
.case_sens = FALSE,
|
|
||||||
.backwards = FALSE,
|
|
||||||
.whole_words = FALSE,
|
|
||||||
.all_codepages = FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** file scope macro definitions ****************************************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
@ -133,30 +125,10 @@ mcview_dialog_search (WView * view)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_free (view->last_search_string);
|
mcview_search_deinit (view);
|
||||||
view->last_search_string = exp;
|
view->last_search_string = exp;
|
||||||
mcview_nroff_seq_free (&view->search_nroff_seq);
|
|
||||||
mc_search_free (view->search);
|
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
return mcview_search_init (view);
|
||||||
view->search = mc_search_new (view->last_search_string, cp_source);
|
|
||||||
#else
|
|
||||||
view->search = mc_search_new (view->last_search_string, NULL);
|
|
||||||
#endif
|
|
||||||
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
|
||||||
if (view->search != NULL)
|
|
||||||
{
|
|
||||||
view->search->search_type = mcview_search_options.type;
|
|
||||||
#ifdef HAVE_CHARSET
|
|
||||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
|
||||||
#endif
|
|
||||||
view->search->is_case_sensitive = mcview_search_options.case_sens;
|
|
||||||
view->search->whole_words = mcview_search_options.whole_words;
|
|
||||||
view->search->search_fn = mcview_search_cmd_callback;
|
|
||||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (view->search != NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -342,6 +342,8 @@ int mcview_nroff_seq_next (mcview_nroff_t * nroff);
|
|||||||
int mcview_nroff_seq_prev (mcview_nroff_t * nroff);
|
int mcview_nroff_seq_prev (mcview_nroff_t * nroff);
|
||||||
|
|
||||||
/* search.c: */
|
/* search.c: */
|
||||||
|
gboolean mcview_search_init (WView * view);
|
||||||
|
void mcview_search_deinit (WView * view);
|
||||||
mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
|
mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
|
||||||
int *current_char);
|
int *current_char);
|
||||||
mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);
|
mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);
|
||||||
|
@ -238,10 +238,9 @@ mcview_done (WView * view)
|
|||||||
view->converter = str_cnv_from_term;
|
view->converter = str_cnv_from_term;
|
||||||
}
|
}
|
||||||
|
|
||||||
mc_search_free (view->search);
|
mcview_search_deinit (view);
|
||||||
view->search = NULL;
|
view->search = NULL;
|
||||||
MC_PTR_FREE (view->last_search_string);
|
view->last_search_string = NULL;
|
||||||
mcview_nroff_seq_free (&view->search_nroff_seq);
|
|
||||||
mcview_hexedit_free_change_list (view);
|
mcview_hexedit_free_change_list (view);
|
||||||
|
|
||||||
if (mc_global.mc_run_mode == MC_RUN_VIEWER && view->dir != NULL)
|
if (mc_global.mc_run_mode == MC_RUN_VIEWER && view->dir != NULL)
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/strutil.h"
|
#include "lib/strutil.h"
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
|
#include "lib/charsets.h" /* cp_source */
|
||||||
|
#endif
|
||||||
#include "lib/widget.h"
|
#include "lib/widget.h"
|
||||||
|
|
||||||
#include "src/setup.h"
|
#include "src/setup.h"
|
||||||
@ -45,6 +48,14 @@
|
|||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
mcview_search_options_t mcview_search_options = {
|
||||||
|
.type = MC_SEARCH_T_NORMAL,
|
||||||
|
.case_sens = FALSE,
|
||||||
|
.backwards = FALSE,
|
||||||
|
.whole_words = FALSE,
|
||||||
|
.all_codepages = FALSE
|
||||||
|
};
|
||||||
|
|
||||||
/*** file scope macro definitions ****************************************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
@ -198,6 +209,44 @@ mcview_search_show_result (WView * view, size_t match_len)
|
|||||||
/*** public functions ****************************************************************************/
|
/*** public functions ****************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mcview_search_init (WView * view)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
|
view->search = mc_search_new (view->last_search_string, cp_source);
|
||||||
|
#else
|
||||||
|
view->search = mc_search_new (view->last_search_string, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
||||||
|
|
||||||
|
if (view->search == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
view->search->search_type = mcview_search_options.type;
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
|
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||||
|
#endif
|
||||||
|
view->search->is_case_sensitive = mcview_search_options.case_sens;
|
||||||
|
view->search->whole_words = mcview_search_options.whole_words;
|
||||||
|
view->search->search_fn = mcview_search_cmd_callback;
|
||||||
|
view->search->update_fn = mcview_search_update_cmd_callback;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
mcview_search_deinit (WView * view)
|
||||||
|
{
|
||||||
|
mc_search_free (view->search);
|
||||||
|
g_free (view->last_search_string);
|
||||||
|
mcview_nroff_seq_free (&view->search_nroff_seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
mc_search_cbret_t
|
mc_search_cbret_t
|
||||||
mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
|
mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user