Ticket #1487 (Whole words search)
thanx Daniel Borca <dborca@yahoo.com> for the patch * fix special_chars in regex.c * add whole_words into mc_search_struct * add 'Whole words' into 'Search', 'Replace' 'File find' dialogs Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
Этот коммит содержится в:
родитель
7ef283975b
Коммит
156b79609c
@ -63,6 +63,7 @@ struct WEdit {
|
||||
int replace_backwards;
|
||||
int replace_case;
|
||||
int only_in_selection;
|
||||
int whole_words;
|
||||
int all_codepages;
|
||||
|
||||
long search_start; /* First character to start searching from */
|
||||
|
@ -1439,6 +1439,7 @@ edit_replace_cmd (WEdit *edit, int again)
|
||||
edit->search->search_type = edit->search_type;
|
||||
edit->search->is_all_charsets = edit->all_codepages;
|
||||
edit->search->is_case_sentitive = edit->replace_case;
|
||||
edit->search->whole_words = edit->whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
|
||||
@ -1640,6 +1641,7 @@ void edit_search_cmd (WEdit * edit, int again)
|
||||
edit->search->search_type = edit->search_type;
|
||||
edit->search->is_all_charsets = edit->all_codepages;
|
||||
edit->search->is_case_sentitive = edit->replace_case;
|
||||
edit->search->whole_words = edit->whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,11 @@
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
#define SEARCH_DLG_WIDTH 58
|
||||
#define SEARCH_DLG_MIN_HEIGHT 12
|
||||
#define SEARCH_DLG_MIN_HEIGHT 13
|
||||
#define SEARCH_DLG_HEIGHT_SUPPLY 3
|
||||
|
||||
#define REPLACE_DLG_WIDTH 58
|
||||
#define REPLACE_DLG_MIN_HEIGHT 16
|
||||
#define REPLACE_DLG_MIN_HEIGHT 17
|
||||
#define REPLACE_DLG_HEIGHT_SUPPLY 5
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
@ -87,6 +87,7 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha
|
||||
int treplace_backwards = edit->replace_backwards;
|
||||
int tonly_in_selection = edit->only_in_selection;
|
||||
int treplace_case = edit->replace_case;
|
||||
int twhole_words = edit->whole_words;
|
||||
int tall_codepages = edit->all_codepages;
|
||||
mc_search_type_t ttype_of_search = edit->search_type;
|
||||
int dialog_result;
|
||||
@ -99,17 +100,21 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
|
||||
{quick_button, 6, 10, 12, REPLACE_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL,
|
||||
{quick_button, 6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL,
|
||||
0, 0, NULL, NULL, NULL},
|
||||
|
||||
{quick_button, 2, 10, 12, REPLACE_DLG_HEIGHT, N_("&OK"), 0, B_ENTER,
|
||||
{quick_button, 2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), 0, B_ENTER,
|
||||
0, 0, NULL, NULL, NULL},
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
{quick_checkbox, 33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&All charsets"), 0, 0,
|
||||
{quick_checkbox, 33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("&All charsets"), 0, 0,
|
||||
&tall_codepages, 0, NULL, NULL, NULL},
|
||||
#endif
|
||||
|
||||
{quick_checkbox, 33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("Whole &words"), 0, 0,
|
||||
&twhole_words, 0, NULL, NULL, NULL},
|
||||
|
||||
|
||||
{quick_checkbox, 33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"), 0, 0,
|
||||
&tonly_in_selection, 0, NULL, NULL, NULL},
|
||||
|
||||
@ -162,6 +167,7 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha
|
||||
edit->only_in_selection = tonly_in_selection;
|
||||
edit->all_codepages = tall_codepages;
|
||||
edit->replace_backwards = treplace_backwards;
|
||||
edit->whole_words = twhole_words;
|
||||
edit->replace_case = treplace_case;
|
||||
return;
|
||||
} else {
|
||||
@ -179,6 +185,7 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
|
||||
int tsearch_case = edit->replace_case;
|
||||
int tsearch_backwards = edit->replace_backwards;
|
||||
int tall_codepages = edit->all_codepages;
|
||||
int twhole_words = edit->whole_words;
|
||||
int tonly_in_selection = edit->only_in_selection;
|
||||
mc_search_type_t ttype_of_search = edit->search_type;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array();
|
||||
@ -189,15 +196,19 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
|
||||
*search_text = INPUT_LAST_TEXT;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
{quick_button, 6, 10, 10, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0,
|
||||
{quick_button, 6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0,
|
||||
0, NULL, NULL, NULL},
|
||||
{quick_button, 2, 10, 10, SEARCH_DLG_HEIGHT, N_("&OK"), 0, B_ENTER, 0,
|
||||
{quick_button, 2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), 0, B_ENTER, 0,
|
||||
0, NULL, NULL, NULL},
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
{quick_checkbox, 33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&All charsets"), 0, 0,
|
||||
{quick_checkbox, 33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("&All charsets"), 0, 0,
|
||||
&tall_codepages, 0, NULL, NULL, NULL},
|
||||
#endif
|
||||
|
||||
{quick_checkbox, 33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("Whole &words"), 0, 0,
|
||||
&twhole_words, 0, NULL, NULL, NULL},
|
||||
|
||||
{quick_checkbox, 33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), 0, 0,
|
||||
&tonly_in_selection, 0, NULL, NULL, NULL},
|
||||
|
||||
@ -229,6 +240,7 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
|
||||
edit->replace_backwards = tsearch_backwards;
|
||||
edit->only_in_selection = tonly_in_selection;
|
||||
edit->all_codepages = tall_codepages;
|
||||
edit->whole_words = twhole_words;
|
||||
edit->replace_case = tsearch_case;
|
||||
} else {
|
||||
*search_text = NULL;
|
||||
|
15
src/find.c
15
src/find.c
@ -97,6 +97,7 @@ static WCheck *skip_hidden_cbox;
|
||||
static WCheck *content_case_sens_cbox; /* "case sensitive" checkbox */
|
||||
static WCheck *content_regexp_cbox; /* "find regular expression" checkbox */
|
||||
static WCheck *content_first_hit_cbox; /* "First hit" checkbox" */
|
||||
static WCheck *content_whole_words_cbox; /* "whole words" checkbox */
|
||||
#ifdef HAVE_CHARSET
|
||||
static WCheck *file_all_charsets_cbox;
|
||||
static WCheck *content_all_charsets_cbox;
|
||||
@ -165,6 +166,7 @@ static gboolean content_regexp_flag = FALSE;
|
||||
static gboolean content_all_charsets_flag = FALSE;
|
||||
static gboolean content_case_sens_flag = TRUE;
|
||||
static gboolean content_first_hit_flag = FALSE;
|
||||
static gboolean content_whole_words = FALSE;
|
||||
|
||||
static inline char *
|
||||
add_to_list (const char *text, void *data)
|
||||
@ -285,6 +287,7 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
const char *content_case_label = N_("Case sens&itive");
|
||||
const char *content_regexp_label = N_("Re&gular expression");
|
||||
const char *content_first_hit_label = N_("Fir&st hit");
|
||||
const char *content_whole_words_label = N_("Whole &words");
|
||||
const char *content_all_charsets_label = N_("All cha&rsets");
|
||||
|
||||
const char *buts[] = { N_("&OK"), N_("&Cancel"), N_("&Tree") };
|
||||
@ -305,6 +308,7 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
content_case_label = _(content_case_label);
|
||||
content_regexp_label = _(content_regexp_label);
|
||||
content_first_hit_label = _(content_first_hit_label);
|
||||
content_whole_words_label = _(content_whole_words_label);
|
||||
content_all_charsets_label = _(content_all_charsets_label);
|
||||
}
|
||||
#endif /* ENABLE_NLS */
|
||||
@ -332,11 +336,14 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
button_new (FIND_Y - 3, FIND_X/4 - b0/2, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
content_all_charsets_cbox = check_new (10, FIND_X / 2 + 1,
|
||||
content_all_charsets_cbox = check_new (11, FIND_X / 2 + 1,
|
||||
content_all_charsets_flag, content_all_charsets_label);
|
||||
add_widget (find_dlg, content_all_charsets_cbox);
|
||||
#endif
|
||||
|
||||
content_whole_words_cbox = check_new (10, FIND_X / 2 + 1, content_whole_words, content_whole_words_label);
|
||||
add_widget (find_dlg, content_whole_words_cbox);
|
||||
|
||||
content_first_hit_cbox = check_new (9, FIND_X / 2 + 1, content_first_hit_flag, content_first_hit_label);
|
||||
add_widget (find_dlg, content_first_hit_cbox);
|
||||
|
||||
@ -398,6 +405,7 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
content_case_sens_flag = content_case_sens_cbox->state & C_BOOL;
|
||||
content_regexp_flag = content_regexp_cbox->state & C_BOOL;
|
||||
content_first_hit_flag = content_first_hit_cbox->state & C_BOOL;
|
||||
content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
||||
file_pattern_flag = file_pattern_cbox->state & C_BOOL;
|
||||
file_case_sens_flag = file_case_sens_cbox->state & C_BOOL;
|
||||
find_recurs_flag = recursively_cbox->state & C_BOOL;
|
||||
@ -432,6 +440,7 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
content_case_sens_flag = content_case_sens_cbox->state & C_BOOL;
|
||||
content_regexp_flag = content_regexp_cbox->state & C_BOOL;
|
||||
content_first_hit_flag = content_first_hit_cbox->state & C_BOOL;
|
||||
content_whole_words = content_whole_words_cbox->state & C_BOOL;
|
||||
find_recurs_flag = recursively_cbox->state & C_BOOL;
|
||||
file_pattern_flag = file_pattern_cbox->state & C_BOOL;
|
||||
file_case_sens_flag = file_case_sens_cbox->state & C_BOOL;
|
||||
@ -756,10 +765,10 @@ do_search (struct Dlg_head *h)
|
||||
}
|
||||
|
||||
search_content_handle = mc_search_new(content_pattern, -1);
|
||||
if (search_content_handle)
|
||||
{
|
||||
if (search_content_handle) {
|
||||
search_content_handle->search_type = (content_regexp_flag) ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL;
|
||||
search_content_handle->is_case_sentitive = content_case_sens_flag;
|
||||
search_content_handle->whole_words = content_whole_words;
|
||||
search_content_handle->is_all_charsets = content_all_charsets_flag;
|
||||
}
|
||||
search_file_handle = mc_search_new(find_pattern, -1);
|
||||
|
@ -92,6 +92,10 @@ mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * mc_se
|
||||
mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
|
||||
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
if (mc_search->whole_words) {
|
||||
g_string_prepend (tmp, "\\b");
|
||||
g_string_append (tmp, "\\b");
|
||||
}
|
||||
mc_search_cond->str = tmp;
|
||||
|
||||
mc_search__cond_struct_new_init_regex (charset, mc_search, mc_search_cond);
|
||||
|
@ -63,7 +63,7 @@ mc_search__regex_str_append_if_special (GString * copy_to, GString * regex_str,
|
||||
const char *special_chars[] = {
|
||||
"\\s", "\\S",
|
||||
"\\d", "\\D",
|
||||
"\\B", "\\B",
|
||||
"\\b", "\\B",
|
||||
"\\w", "\\W",
|
||||
"\\t", "\\n",
|
||||
"\\r", "\\f",
|
||||
|
@ -60,6 +60,9 @@ typedef struct mc_search_struct {
|
||||
/* search only once. Is this for replace? */
|
||||
gboolean is_once_only;
|
||||
|
||||
/* search only whole words (from begin to end). Used only with NORMAL search type */
|
||||
gboolean whole_words;
|
||||
|
||||
/* search entire string (from begin to end). Used only with GLOB search type */
|
||||
gboolean is_entire_line;
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user