mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
Merge branch '1572_editor_retain_search_options'
* 1572_editor_retain_search_options: Retain search options in viewer across viewing session. Ticket #1572: retain search/replace options in editor.
This commit is contained in:
commit
476ede51b9
@ -32,7 +32,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "src/dialog.h" /* cb_ret_t */
|
||||
#include "lib/search.h" /* mc_search_type_t */
|
||||
|
||||
#include "src/dialog.h" /* cb_ret_t */
|
||||
#include "src/keybind.h" /* global_keymap_t */
|
||||
|
||||
#include "src/editor/edit.h"
|
||||
@ -117,6 +119,16 @@
|
||||
#define MAX_HISTORY_MOVETO 50
|
||||
#define LINE_STATE_WIDTH 8
|
||||
|
||||
/* search/replace options */
|
||||
typedef struct edit_search_options_t {
|
||||
mc_search_type_t type;
|
||||
gboolean case_sens;
|
||||
gboolean backwards;
|
||||
gboolean only_in_selection;
|
||||
gboolean whole_words;
|
||||
gboolean all_codepages;
|
||||
} edit_search_options_t;
|
||||
|
||||
typedef struct edit_stack_type {
|
||||
long line;
|
||||
char *filename;
|
||||
@ -299,6 +311,8 @@ void edit_execute_cmd (WEdit *edit, unsigned long command, int char_for_insertio
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern edit_search_options_t edit_search_options;
|
||||
|
||||
extern int edit_stack_iterator;
|
||||
extern edit_stack_type edit_history_moveto [MAX_HISTORY_MOVETO];
|
||||
|
||||
|
@ -48,16 +48,10 @@ struct WEdit {
|
||||
/* UTF8 */
|
||||
char charbuf[4 + 1];
|
||||
int charpoint;
|
||||
/* search variables */
|
||||
mc_search_t *search;
|
||||
|
||||
unsigned int search_type;
|
||||
/* search handler */
|
||||
mc_search_t *search;
|
||||
int replace_mode;
|
||||
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 */
|
||||
int found_len; /* Length of found string or 0 if none was found */
|
||||
|
@ -1432,14 +1432,14 @@ editcmd_find (WEdit *edit, gsize *len)
|
||||
long end_mark = edit->last_byte;
|
||||
int mark_res = 0;
|
||||
|
||||
if (edit->only_in_selection) {
|
||||
if (edit_search_options.only_in_selection) {
|
||||
mark_res = eval_marks(edit, &start_mark, &end_mark);
|
||||
if (mark_res != 0) {
|
||||
edit->search->error = MC_SEARCH_E_NOTFOUND;
|
||||
edit->search->error_str = g_strdup(_(" Search string not found "));
|
||||
return FALSE;
|
||||
}
|
||||
if (edit->replace_backwards) {
|
||||
if (edit_search_options.backwards) {
|
||||
if (search_start > end_mark || search_start <= start_mark) {
|
||||
search_start = end_mark;
|
||||
}
|
||||
@ -1449,10 +1449,10 @@ editcmd_find (WEdit *edit, gsize *len)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (edit->replace_backwards)
|
||||
if (edit_search_options.backwards)
|
||||
end_mark = max(1, edit->curs1) - 1;
|
||||
}
|
||||
if (edit->replace_backwards) {
|
||||
if (edit_search_options.backwards) {
|
||||
search_end = end_mark;
|
||||
while ((int) search_start >= start_mark) {
|
||||
if (search_end > search_start + edit->search->original_len
|
||||
@ -1574,19 +1574,19 @@ edit_replace_cmd (WEdit *edit, int again)
|
||||
edit->search_start = edit->curs1;
|
||||
return;
|
||||
}
|
||||
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_type = edit_search_options.type;
|
||||
edit->search->is_all_charsets = edit_search_options.all_codepages;
|
||||
edit->search->is_case_sentitive = edit_search_options.case_sens;
|
||||
edit->search->whole_words = edit_search_options.whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start + 1
|
||||
&& edit->replace_backwards)
|
||||
&& edit_search_options.backwards)
|
||||
edit->search_start--;
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start - 1
|
||||
&& !edit->replace_backwards)
|
||||
&& !edit_search_options.backwards)
|
||||
edit->search_start++;
|
||||
|
||||
do {
|
||||
@ -1670,7 +1670,7 @@ edit_replace_cmd (WEdit *edit, int again)
|
||||
edit->found_len = i;
|
||||
}
|
||||
/* so that we don't find the same string again */
|
||||
if (edit->replace_backwards) {
|
||||
if (edit_search_options.backwards) {
|
||||
last_search = edit->search_start;
|
||||
edit->search_start--;
|
||||
} else {
|
||||
@ -1776,30 +1776,31 @@ void edit_search_cmd (WEdit * edit, int again)
|
||||
edit->search_start = edit->curs1;
|
||||
return;
|
||||
}
|
||||
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_type = edit_search_options.type;
|
||||
edit->search->is_all_charsets = edit_search_options.all_codepages;
|
||||
edit->search->is_case_sentitive = edit_search_options.case_sens;
|
||||
edit->search->whole_words = edit_search_options.whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
|
||||
if (search_create_bookmark) {
|
||||
edit_search_cmd_search_create_bookmark(edit);
|
||||
} else {
|
||||
if (edit->found_len && edit->search_start == edit->found_start + 1 && edit->replace_backwards)
|
||||
if (edit->found_len && edit->search_start == edit->found_start + 1
|
||||
&& edit_search_options.backwards)
|
||||
edit->search_start--;
|
||||
|
||||
if (edit->found_len && edit->search_start == edit->found_start - 1 && !edit->replace_backwards)
|
||||
if (edit->found_len && edit->search_start == edit->found_start - 1
|
||||
&& !edit_search_options.backwards)
|
||||
edit->search_start++;
|
||||
|
||||
|
||||
if (editcmd_find(edit, &len)) {
|
||||
edit->found_start = edit->search_start = edit->search->normal_offset;
|
||||
edit->found_len = len;
|
||||
edit->over_col = 0;
|
||||
edit_cursor_move (edit, edit->search_start - edit->curs1);
|
||||
edit_scroll_screen_over_cursor (edit);
|
||||
if (edit->replace_backwards)
|
||||
if (edit_search_options.backwards)
|
||||
edit->search_start--;
|
||||
else
|
||||
edit->search_start++;
|
||||
|
@ -47,6 +47,16 @@
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
edit_search_options_t edit_search_options =
|
||||
{
|
||||
.type = MC_SEARCH_T_NORMAL,
|
||||
.case_sens = FALSE,
|
||||
.backwards = FALSE,
|
||||
.only_in_selection = FALSE,
|
||||
.whole_words = FALSE,
|
||||
.all_codepages = FALSE
|
||||
};
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
#define SEARCH_DLG_WIDTH 58
|
||||
@ -61,7 +71,6 @@
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
|
||||
static cb_ret_t
|
||||
@ -97,14 +106,20 @@ editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const cha
|
||||
/* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
|
||||
/* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
|
||||
/* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
|
||||
/* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
|
||||
/* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
|
||||
/* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")),
|
||||
/* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
|
||||
replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text),
|
||||
@ -157,22 +172,29 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
|
||||
QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 3 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 4 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 5 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 6 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 7 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 8 */
|
||||
QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 9 */
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
*search_text, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
*search_text, SEARCH_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
/* 10 */
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
QUICK_END
|
||||
|
@ -113,12 +113,12 @@ mcview_continue_search_cmd (mcview_t * view)
|
||||
view->last_search_string = NULL;
|
||||
mcview_search (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_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = 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;
|
||||
view->search->whole_words = view->whole_words;
|
||||
|
||||
mcview_do_search (view);
|
||||
}
|
||||
|
@ -52,6 +52,15 @@
|
||||
|
||||
/*** 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 type declarations ****************************************************************/
|
||||
@ -84,16 +93,17 @@ mcview_dialog_search (mcview_t * view)
|
||||
QUICK_BUTTON (2, 10, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT,
|
||||
N_("All charsets"), &view->search_all_codepages),
|
||||
N_("All charsets"), &mcview_search_options.all_codepages),
|
||||
#endif
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT,
|
||||
N_("&Whole words"), &view->whole_words),
|
||||
N_("&Whole words"), &mcview_search_options.whole_words),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT,
|
||||
N_("&Backwards"), &view->search_backwards),
|
||||
N_("&Backwards"), &mcview_search_options.backwards),
|
||||
QUICK_CHECKBOX (SEARCH_DLG_WIDTH / 2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
N_("case &Sensitive"), &view->search_case),
|
||||
N_("case &Sensitive"), &mcview_search_options.case_sens),
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types, (int *) &view->search_type),
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &mcview_search_options.type),
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, &exp),
|
||||
QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
|
||||
@ -138,12 +148,12 @@ mcview_dialog_search (mcview_t * view)
|
||||
view->search = mc_search_new (view->last_search_string, -1);
|
||||
view->search_nroff_seq = mcview_nroff_seq_new (view);
|
||||
if (view->search != NULL) {
|
||||
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_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = 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;
|
||||
view->search->whole_words = view->whole_words;
|
||||
}
|
||||
|
||||
return (view->search != NULL);
|
||||
|
@ -180,11 +180,6 @@ typedef struct mcview_struct {
|
||||
/* handle of search engine */
|
||||
mc_search_t *search;
|
||||
gchar *last_search_string;
|
||||
mc_search_type_t search_type;
|
||||
gboolean search_all_codepages;
|
||||
gboolean whole_words;
|
||||
gboolean search_case;
|
||||
gboolean search_backwards;
|
||||
struct mcview_nroff_struct *search_nroff_seq;
|
||||
|
||||
int search_numNeedSkipChar;
|
||||
@ -199,8 +194,18 @@ typedef struct mcview_nroff_struct {
|
||||
nroff_type_t prev_type;
|
||||
} mcview_nroff_t;
|
||||
|
||||
typedef struct mcview_search_options_t {
|
||||
mc_search_type_t type;
|
||||
gboolean case_sens;
|
||||
gboolean backwards;
|
||||
gboolean whole_words;
|
||||
gboolean all_codepages;
|
||||
} mcview_search_options_t;
|
||||
|
||||
/*** global variables defined in .c file *******************************/
|
||||
|
||||
extern mcview_search_options_t mcview_search_options;
|
||||
|
||||
/*** declarations of public functions **********************************/
|
||||
|
||||
/* actions_cmd.c: */
|
||||
|
@ -78,7 +78,7 @@ mcview_find (mcview_t * view, gsize search_start, gsize * len)
|
||||
|
||||
view->search_numNeedSkipChar = 0;
|
||||
|
||||
if (view->search_backwards) {
|
||||
if (mcview_search_options.backwards) {
|
||||
search_end = mcview_get_filesize (view);
|
||||
while ((int) search_start >= 0) {
|
||||
view->search_nroff_seq->index = search_start;
|
||||
@ -220,14 +220,14 @@ mcview_do_search (mcview_t * view)
|
||||
/*for avoid infinite search loop we need to increase or decrease start offset of search */
|
||||
|
||||
if (view->search_start) {
|
||||
search_start = (view->search_backwards) ? -2 : 2;
|
||||
search_start = (mcview_search_options.backwards) ? -2 : 2;
|
||||
search_start = view->search_start + search_start +
|
||||
mcview__get_nroff_real_len (view, view->search_start, 2) * search_start;
|
||||
} else {
|
||||
search_start = view->search_start;
|
||||
}
|
||||
|
||||
if (view->search_backwards && (int) search_start < 0)
|
||||
if (mcview_search_options.backwards && (int) search_start < 0)
|
||||
search_start = 0;
|
||||
|
||||
/* Compute the percent steps */
|
||||
@ -262,7 +262,7 @@ mcview_do_search (mcview_t * view)
|
||||
break;
|
||||
} while (mcview_may_still_grow (view));
|
||||
|
||||
if (!isFound && need_search_again && !view->search_backwards) {
|
||||
if (!isFound && need_search_again && !mcview_search_options.backwards) {
|
||||
int result;
|
||||
mcview_update (view);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user