On Tue, 17 May 2011 15:38:40 +0200 Colomban Wendling <[email protected]> wrote:
> Le 15/05/2011 14:29, Eugene Arshinov a écrit : > > Hi. > > > > When "Escape sequences" checkbox is checked in Find or Replace > > dialog, before escaping the find and replace strings we should save > > the original ones, so that they can be used in messages shown to > > user and in the history of those dialogs' entries. This is what > > the patch is about. > > > > I described in the commit message (see the top of the patch) the > > changes made in the code. Just in case, here is a copy: > > > > In the code, now we pass the original text together with the one > > that is actually searched for. New `original_text' field was > > added to GeanySearchData. A bug was fixed in > > document.c:show_replace_summary(): it did not escape the "No > > matches found for ..." string. > > > > Hope that I did not touch plugin API with these changes. In header > > files I changed the following: > > - document_find_text()'s signature > > - document_replace_text()'s signature > > - search_find_usage()'s signature > > - struct GeanySearchData > > Seems none of the functions you changed were in the plugin API, so > it's fine. For the structure, since you appended to it, it's also > fine. > > However, a few comments: > > 1) why did you used an extra string everywhere but in > document.c:show_replace_summary()? OK it already do this, but it seems > not consistent since you added an "original_text". > > 2) on search.c:on_replace_dialog_response(), prefer initialize > original_find to NULL and free it in fail rather than freeing it every > time. (though anyway this function is ugly as-is with the backward > goto jump just for failure) > > Otherwise looks OK to me. Attached are the original patch updated for current trunk (r5798) and another one containing changes according to your advice. In the second patch I also applied the same "technique" to show proper replace text in messages. -- Best regards, Eugene
>From d8c2774fc3d89fe283df2d0234aed270a7fd033b Mon Sep 17 00:00:00 2001 From: Eugene Arshinov <[email protected]> Date: Sun, 15 May 2011 16:06:13 +0400 Subject: [PATCH 1/3] In messages show the actual text user entered in Find and Replace dialogs. Previously we could put into a message a string where escape sequences were already translated. In the code, now we pass the original text together with the one that is actually searched for. New `original_text' field was added to GeanySearchData. A bug was fixed in document.c:show_replace_summary(): it did not escape the "No matches found for ..." string. --- src/callbacks.c | 4 +- src/document.c | 50 ++++++++++++++++++++++++++++++++------------- src/document.h | 8 +++--- src/editor.c | 4 +- src/search.c | 60 +++++++++++++++++++++++++++++++++--------------------- src/search.h | 4 ++- 6 files changed, 83 insertions(+), 47 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index 9fbe2cd..da64a7f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -538,6 +538,7 @@ on_toolbutton_save_clicked (GtkAction *action, static void setup_find(const gchar *text, gboolean backwards) { setptr(search_data.text, g_strdup(text)); + setptr(search_data.original_text, g_strdup(text)); search_data.flags = 0; search_data.backwards = backwards; search_data.search_bar = TRUE; @@ -1037,7 +1038,7 @@ static void find_usage(gboolean in_session) flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD; } - search_find_usage(search_text, flags, in_session); + search_find_usage(search_text, search_text, flags, in_session); g_free(search_text); } @@ -2414,4 +2415,3 @@ on_mark_all1_activate (GtkMenuItem *menuitem, { keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL); } - diff --git a/src/document.c b/src/document.c index 971936b..3e47d1c 100644 --- a/src/document.c +++ b/src/document.c @@ -1928,9 +1928,13 @@ gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint fl /* General search function, used from the find dialog. * Returns -1 on failure or the start position of the matching text. - * Will skip past any selection, ignoring it. */ -gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gboolean search_backwards, - gboolean scroll, GtkWidget *parent) + * Will skip past any selection, ignoring it. + * + * @param text Text to find. + * @param original_text Text as it was entered by user, or @c NULL to use @c text + */ +gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *original_text, + gint flags, gboolean search_backwards, gboolean scroll, GtkWidget *parent) { gint selection_end, selection_start, search_pos; @@ -1942,6 +1946,9 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gbool if (flags & SCFIND_REGEXP) search_backwards = FALSE; + if (!original_text) + original_text = text; + selection_start = sci_get_selection_start(doc->editor->sci); selection_end = sci_get_selection_end(doc->editor->sci); if ((selection_end - selection_start) > 0) @@ -1974,7 +1981,7 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gbool if ((selection_end == 0 && ! search_backwards) || (selection_end == sci_len && search_backwards)) { - ui_set_statusbar(FALSE, _("\"%s\" was not found."), text); + ui_set_statusbar(FALSE, _("\"%s\" was not found."), original_text); utils_beep(); return -1; } @@ -1982,12 +1989,12 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gbool /* we searched only part of the document, so ask whether to wraparound. */ if (search_prefs.suppress_dialogs || dialogs_show_question_full(parent, GTK_STOCK_FIND, GTK_STOCK_CANCEL, - _("Wrap search and find again?"), _("\"%s\" was not found."), text)) + _("Wrap search and find again?"), _("\"%s\" was not found."), original_text)) { gint ret; sci_set_current_position(doc->editor->sci, (search_backwards) ? sci_len : 0, FALSE); - ret = document_find_text(doc, text, flags, search_backwards, scroll, parent); + ret = document_find_text(doc, text, original_text, flags, search_backwards, scroll, parent); if (ret == -1) { /* return to original cursor position if not found */ sci_set_current_position(doc->editor->sci, selection_start, FALSE); @@ -2000,9 +2007,13 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gbool /* Replaces the selection if it matches, otherwise just finds the next match. - * Returns: start of replaced text, or -1 if no replacement was made */ -gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, - gint flags, gboolean search_backwards) + * Returns: start of replaced text, or -1 if no replacement was made + * + * @param find_text Text to find. + * @param original_find_text Text to find as it was entered by user, or @c NULL to use @c find_text + */ +gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *original_find_text, + const gchar *replace_text, gint flags, gboolean search_backwards) { gint selection_end, selection_start, search_pos; @@ -2015,12 +2026,15 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch if (flags & SCFIND_REGEXP) search_backwards = FALSE; + if (!original_find_text) + original_find_text = find_text; + selection_start = sci_get_selection_start(doc->editor->sci); selection_end = sci_get_selection_end(doc->editor->sci); if (selection_end == selection_start) { /* no selection so just find the next match */ - document_find_text(doc, find_text, flags, search_backwards, TRUE, NULL); + document_find_text(doc, find_text, original_find_text, flags, search_backwards, TRUE, NULL); return -1; } /* there's a selection so go to the start before finding to search through it @@ -2030,7 +2044,7 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch else sci_goto_pos(doc->editor->sci, selection_start, TRUE); - search_pos = document_find_text(doc, find_text, flags, search_backwards, TRUE, NULL); + search_pos = document_find_text(doc, find_text, original_find_text, flags, search_backwards, TRUE, NULL); /* return if the original selected text did not match (at the start of the selection) */ if (search_pos != selection_start) return -1; @@ -2057,11 +2071,19 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch static void show_replace_summary(GeanyDocument *doc, gint count, const gchar *find_text, const gchar *replace_text, gboolean escaped_chars) { - gchar *escaped_find_text, *escaped_replace_text, *filename; + gchar *escaped_find_text = NULL, *escaped_replace_text, *filename; if (count == 0) { - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), find_text); + if (escaped_chars) + { + /* escape special characters for showing */ + escaped_find_text = g_strescape(find_text, NULL); + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), escaped_find_text); + g_free(escaped_find_text); + } + else + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), find_text); return; } @@ -3127,5 +3149,3 @@ gint document_compare_by_tab_order_reverse(gconstpointer a, gconstpointer b) /* equality */ return 0; } - - diff --git a/src/document.h b/src/document.h index 39d90f2..6de5d31 100644 --- a/src/document.h +++ b/src/document.h @@ -217,11 +217,11 @@ void document_open_files(const GSList *filenames, gboolean readonly, GeanyFilety gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint flags, gboolean inc, gboolean backwards); -gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gboolean search_backwards, - gboolean scroll, GtkWidget *parent); +gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *original_text, + gint flags, gboolean search_backwards, gboolean scroll, GtkWidget *parent); -gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, - gint flags, gboolean search_backwards); +gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *original_find_text, + const gchar *replace_text, gint flags, gboolean search_backwards); gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, gint flags, gboolean escaped_chars); diff --git a/src/editor.c b/src/editor.c index 3dfd29b..74f9bb0 100644 --- a/src/editor.c +++ b/src/editor.c @@ -2791,7 +2791,7 @@ static void real_uncomment_multiline(GeanyEditor *editor) doc = editor->document; /* remove comment open chars */ - pos = document_find_text(doc, doc->file_type->comment_open, 0, TRUE, FALSE, NULL); + pos = document_find_text(doc, doc->file_type->comment_open, NULL, 0, TRUE, FALSE, NULL); SSM(editor->sci, SCI_DELETEBACK, 0, 0); /* check whether the line is empty and can be deleted */ @@ -2804,7 +2804,7 @@ static void real_uncomment_multiline(GeanyEditor *editor) g_free(linebuf); /* remove comment close chars */ - pos = document_find_text(doc, doc->file_type->comment_close, 0, FALSE, FALSE, NULL); + pos = document_find_text(doc, doc->file_type->comment_close, NULL, 0, FALSE, FALSE, NULL); SSM(editor->sci, SCI_DELETEBACK, 0, 0); /* check whether the line is empty and can be deleted */ diff --git a/src/search.c b/src/search.c index 2fc820f..9f26d00 100644 --- a/src/search.c +++ b/src/search.c @@ -266,6 +266,7 @@ static void init_prefs(void) void search_init(void) { search_data.text = NULL; + search_data.original_text = NULL; init_prefs(); } @@ -279,6 +280,7 @@ void search_finalize(void) FREE_WIDGET(replace_dlg.dialog); FREE_WIDGET(fif_dlg.dialog); g_free(search_data.text); + g_free(search_data.original_text); } @@ -358,7 +360,9 @@ static void send_find_dialog_response(GtkButton *button, gpointer user_data) static void setup_find_next(const gchar *text) { g_free(search_data.text); + g_free(search_data.original_text); search_data.text = g_strdup(text); + search_data.original_text = g_strdup(text); search_data.flags = 0; search_data.backwards = FALSE; search_data.search_bar = FALSE; @@ -405,7 +409,7 @@ void search_find_selection(GeanyDocument *doc, gboolean search_backwards) { setup_find_next(s); /* allow find next/prev */ - if (document_find_text(doc, s, 0, search_backwards, FALSE, NULL) > -1) + if (document_find_text(doc, s, NULL, 0, search_backwards, FALSE, NULL) > -1) editor_display_current_line(doc->editor, 0.3F); g_free(s); } @@ -1228,7 +1232,9 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) search_data.search_bar = FALSE; g_free(search_data.text); + g_free(search_data.original_text); search_data.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data))))); + search_data.original_text = g_strdup(search_data.text); search_data.flags = int_search_flags(settings.find_case_sensitive, settings.find_match_whole_word, settings.find_regexp, settings.find_match_word_start); @@ -1244,14 +1250,14 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) if (! utils_str_replace_escape(search_data.text, search_data.flags & SCFIND_REGEXP)) goto fail; } - ui_combo_box_add_to_history(GTK_COMBO_BOX_ENTRY(user_data), search_data.text, 0); + ui_combo_box_add_to_history(GTK_COMBO_BOX_ENTRY(user_data), search_data.original_text, 0); switch (response) { case GEANY_RESPONSE_FIND: case GEANY_RESPONSE_FIND_PREVIOUS: { - gint result = document_find_text(doc, search_data.text, search_data.flags, + gint result = document_find_text(doc, search_data.text, search_data.original_text, search_data.flags, (response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE, GTK_WIDGET(find_dlg.dialog)); ui_set_search_entry_background(find_dlg.entry, (result > -1)); check_close = FALSE; @@ -1260,11 +1266,11 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) break; } case GEANY_RESPONSE_FIND_IN_FILE: - search_find_usage(search_data.text, search_data.flags, FALSE); + search_find_usage(search_data.text, search_data.original_text, search_data.flags, FALSE); break; case GEANY_RESPONSE_FIND_IN_SESSION: - search_find_usage(search_data.text, search_data.flags, TRUE); + search_find_usage(search_data.text, search_data.original_text, search_data.flags, TRUE); break; case GEANY_RESPONSE_MARK: @@ -1272,12 +1278,12 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) gint count = search_mark_all(doc, search_data.text, search_data.flags); if (count == 0) - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), search_data.text); + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), search_data.original_text); else ui_set_statusbar(FALSE, ngettext("Found %d match for \"%s\".", "Found %d matches for \"%s\".", count), - count, search_data.text); + count, search_data.original_text); } break; } @@ -1296,7 +1302,7 @@ on_replace_entry_activate(GtkEntry *entry, gpointer user_data) static void replace_in_session(GeanyDocument *doc, gint search_flags_re, gboolean search_replace_escape_re, - const gchar *find, const gchar *replace) + const gchar *find, const gchar *original_find, const gchar *replace) { guint n, page_count, rep_count = 0, file_count = 0; @@ -1316,7 +1322,7 @@ static void replace_in_session(GeanyDocument *doc, if (file_count == 0) { utils_beep(); - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), find); + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), original_find); return; } /* if only one file was changed, don't override that document's status message @@ -1338,7 +1344,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) GeanyDocument *doc = document_get_current(); gint search_flags_re; gboolean search_backwards_re, search_replace_escape_re; - gchar *find, *replace; + gchar *find, *replace, *original_find; gtk_window_get_position(GTK_WINDOW(replace_dlg.dialog), &replace_dlg.position[0], &replace_dlg.position[1]); @@ -1363,17 +1369,25 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) if ((response != GEANY_RESPONSE_FIND) && (search_flags_re & SCFIND_MATCHCASE) && (strcmp(find, replace) == 0)) goto fail; + + original_find = g_strdup(find); if (search_flags_re & SCFIND_REGEXP) { if (! utils_str_replace_escape(find, TRUE) || ! utils_str_replace_escape(replace, TRUE)) + { + g_free(original_find); goto fail; + } } else if (search_replace_escape_re) { if (! utils_str_replace_escape(find, FALSE) || ! utils_str_replace_escape(replace, FALSE)) + { + g_free(original_find); goto fail; + } } ui_combo_box_add_to_history(GTK_COMBO_BOX_ENTRY( @@ -1385,21 +1399,21 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) { case GEANY_RESPONSE_REPLACE_AND_FIND: { - gint rep = document_replace_text(doc, find, replace, search_flags_re, + gint rep = document_replace_text(doc, find, original_find, replace, search_flags_re, search_backwards_re); if (rep != -1) - document_find_text(doc, find, search_flags_re, search_backwards_re, + document_find_text(doc, find, original_find, search_flags_re, search_backwards_re, TRUE, NULL); break; } case GEANY_RESPONSE_REPLACE: - document_replace_text(doc, find, replace, search_flags_re, + document_replace_text(doc, find, original_find, replace, search_flags_re, search_backwards_re); break; case GEANY_RESPONSE_FIND: { - gint result = document_find_text(doc, find, search_flags_re, + gint result = document_find_text(doc, find, original_find, search_flags_re, search_backwards_re, TRUE, GTK_WIDGET(dialog)); ui_set_search_entry_background(replace_dlg.find_entry, (result > -1)); break; @@ -1411,7 +1425,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) break; case GEANY_RESPONSE_REPLACE_IN_SESSION: - replace_in_session(doc, search_flags_re, search_replace_escape_re, find, replace); + replace_in_session(doc, search_flags_re, search_replace_escape_re, find, original_find, replace); break; case GEANY_RESPONSE_REPLACE_IN_SEL: @@ -1428,6 +1442,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) } g_free(find); g_free(replace); + g_free(original_find); return; fail: @@ -2012,7 +2027,8 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, gi } -void search_find_usage(const gchar *search_text, gint flags, gboolean in_session) +void search_find_usage(const gchar *search_text, const gchar *original_search_text, + gint flags, gboolean in_session) { GeanyDocument *doc; gint count = 0; @@ -2047,17 +2063,17 @@ void search_find_usage(const gchar *search_text, gint flags, gboolean in_session if (count == 0) /* no matches were found */ { - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), search_text); - msgwin_msg_add(COLOR_BLUE, -1, NULL, _("No matches found for \"%s\"."), search_text); + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), original_search_text); + msgwin_msg_add(COLOR_BLUE, -1, NULL, _("No matches found for \"%s\"."), original_search_text); } else { ui_set_statusbar(FALSE, ngettext( "Found %d match for \"%s\".", "Found %d matches for \"%s\".", count), - count, search_text); + count, original_search_text); msgwin_msg_add(COLOR_BLUE, -1, NULL, ngettext( "Found %d match for \"%s\".", "Found %d matches for \"%s\".", count), - count, search_text); + count, original_search_text); } } @@ -2135,7 +2151,7 @@ void search_find_again(gboolean change_direction) if (search_data.text) { gboolean forward = ! search_data.backwards; - gint result = document_find_text(doc, search_data.text, search_data.flags, + gint result = document_find_text(doc, search_data.text, search_data.original_text, search_data.flags, change_direction ? forward : !forward, FALSE, NULL); if (result > -1) @@ -2146,5 +2162,3 @@ void search_find_again(gboolean change_direction) toolbar_get_widget_child_by_name("SearchEntry"), (result > -1)); } } - - diff --git a/src/search.h b/src/search.h index 0bfd596..a100b09 100644 --- a/src/search.h +++ b/src/search.h @@ -39,6 +39,8 @@ typedef struct GeanySearchData /* set to TRUE when text was set by a search bar callback to keep track of * search bar background colour */ gboolean search_bar; + /* text as it was entered by user */ + gchar *original_text; } GeanySearchData; @@ -85,7 +87,7 @@ gint search_find_text(struct _ScintillaObject *sci, gint flags, struct Sci_TextT void search_find_again(gboolean change_direction); -void search_find_usage(const gchar *search_text, gint flags, gboolean in_session); +void search_find_usage(const gchar *search_text, const gchar *original_search_text, gint flags, gboolean in_session); void search_find_selection(GeanyDocument *doc, gboolean search_backwards); -- 1.7.5.1
>From 44f8b73a757ae42527d5766ae77d4b3515c52c55 Mon Sep 17 00:00:00 2001 From: Eugene Arshinov <[email protected]> Date: Sat, 21 May 2011 11:32:19 +0400 Subject: [PATCH 2/3] Follow Colomban's advice. Two more publicly visible signatures changed: - document_replace_all() - document_replace_sel() Additionally, apply the same technique to show proper (with escape sequences not yet processed) replace text in messages. --- src/document.c | 47 ++++++++++++----------------------------------- src/document.h | 6 +++--- src/search.c | 25 +++++++++++-------------- 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/src/document.c b/src/document.c index 3e47d1c..2346202 100644 --- a/src/document.c +++ b/src/document.c @@ -2068,45 +2068,22 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch } -static void show_replace_summary(GeanyDocument *doc, gint count, const gchar *find_text, - const gchar *replace_text, gboolean escaped_chars) +static void show_replace_summary(GeanyDocument *doc, gint count, const gchar *original_find_text, + const gchar *original_replace_text) { - gchar *escaped_find_text = NULL, *escaped_replace_text, *filename; + gchar *filename; if (count == 0) { - if (escaped_chars) - { - /* escape special characters for showing */ - escaped_find_text = g_strescape(find_text, NULL); - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), escaped_find_text); - g_free(escaped_find_text); - } - else - ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), find_text); + ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), original_find_text); return; } filename = g_path_get_basename(DOC_FILENAME(doc)); - - if (escaped_chars) - { /* escape special characters for showing */ - escaped_find_text = g_strescape(find_text, NULL); - escaped_replace_text = g_strescape(replace_text, NULL); - ui_set_statusbar(TRUE, ngettext( - "%s: replaced %d occurrence of \"%s\" with \"%s\".", - "%s: replaced %d occurrences of \"%s\" with \"%s\".", - count), filename, count, escaped_find_text, escaped_replace_text); - g_free(escaped_find_text); - g_free(escaped_replace_text); - } - else - { - ui_set_statusbar(TRUE, ngettext( - "%s: replaced %d occurrence of \"%s\" with \"%s\".", - "%s: replaced %d occurrences of \"%s\" with \"%s\".", - count), filename, count, find_text, replace_text); - } + ui_set_statusbar(TRUE, ngettext( + "%s: replaced %d occurrence of \"%s\" with \"%s\".", + "%s: replaced %d occurrences of \"%s\" with \"%s\".", + count), filename, count, original_find_text, original_replace_text); g_free(filename); } @@ -2156,7 +2133,7 @@ document_replace_range(GeanyDocument *doc, const gchar *find_text, const gchar * void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, - gint flags, gboolean escaped_chars) + const gchar *original_find_text, const gchar *original_replace_text, gint flags) { gint selection_end, selection_start, selection_mode, selected_lines, last_line = 0; gint max_column = 0, count = 0; @@ -2253,13 +2230,13 @@ void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gcha else /* no replacements */ utils_beep(); - show_replace_summary(doc, count, find_text, replace_text, escaped_chars); + show_replace_summary(doc, count, original_find_text, original_replace_text); } /* returns number of replacements made. */ gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, - gint flags, gboolean escaped_chars) + const gchar *original_find_text, const gchar *original_replace_text, gint flags) { gint len, count; g_return_val_if_fail(doc != NULL && find_text != NULL && replace_text != NULL, FALSE); @@ -2271,7 +2248,7 @@ gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gcha count = document_replace_range( doc, find_text, replace_text, flags, 0, len, TRUE, NULL); - show_replace_summary(doc, count, find_text, replace_text, escaped_chars); + show_replace_summary(doc, count, original_find_text, original_replace_text); return count; } diff --git a/src/document.h b/src/document.h index 6de5d31..0b0b0f0 100644 --- a/src/document.h +++ b/src/document.h @@ -224,10 +224,10 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch const gchar *replace_text, gint flags, gboolean search_backwards); gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, - gint flags, gboolean escaped_chars); + const gchar *original_find_text, const gchar *original_replace_text, gint flags); -void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, gint flags, - gboolean escaped_chars); +void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, + const gchar *original_find_text, const gchar *original_replace_text, gint flags); void document_update_tag_list(GeanyDocument *doc, gboolean update); diff --git a/src/search.c b/src/search.c index 9f26d00..3d29c9e 100644 --- a/src/search.c +++ b/src/search.c @@ -1302,7 +1302,8 @@ on_replace_entry_activate(GtkEntry *entry, gpointer user_data) static void replace_in_session(GeanyDocument *doc, gint search_flags_re, gboolean search_replace_escape_re, - const gchar *find, const gchar *original_find, const gchar *replace) + const gchar *find, const gchar *replace, + const gchar *original_find, const gchar *original_replace) { guint n, page_count, rep_count = 0, file_count = 0; @@ -1313,8 +1314,7 @@ static void replace_in_session(GeanyDocument *doc, GeanyDocument *tmp_doc = document_get_from_page(n); gint reps = 0; - reps = document_replace_all(tmp_doc, find, replace, search_flags_re, - search_replace_escape_re); + reps = document_replace_all(tmp_doc, find, replace, original_find, original_replace, search_flags_re); rep_count += reps; if (reps) file_count++; @@ -1344,7 +1344,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) GeanyDocument *doc = document_get_current(); gint search_flags_re; gboolean search_backwards_re, search_replace_escape_re; - gchar *find, *replace, *original_find; + gchar *find, *replace, *original_find = NULL, *original_replace = NULL; gtk_window_get_position(GTK_WINDOW(replace_dlg.dialog), &replace_dlg.position[0], &replace_dlg.position[1]); @@ -1371,23 +1371,18 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) goto fail; original_find = g_strdup(find); + original_replace = g_strdup(replace); if (search_flags_re & SCFIND_REGEXP) { if (! utils_str_replace_escape(find, TRUE) || ! utils_str_replace_escape(replace, TRUE)) - { - g_free(original_find); goto fail; - } } else if (search_replace_escape_re) { if (! utils_str_replace_escape(find, FALSE) || ! utils_str_replace_escape(replace, FALSE)) - { - g_free(original_find); goto fail; - } } ui_combo_box_add_to_history(GTK_COMBO_BOX_ENTRY( @@ -1419,17 +1414,16 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) break; } case GEANY_RESPONSE_REPLACE_IN_FILE: - if (! document_replace_all(doc, find, replace, search_flags_re, - search_replace_escape_re)) + if (! document_replace_all(doc, find, replace, original_find, original_replace, search_flags_re)) utils_beep(); break; case GEANY_RESPONSE_REPLACE_IN_SESSION: - replace_in_session(doc, search_flags_re, search_replace_escape_re, find, original_find, replace); + replace_in_session(doc, search_flags_re, search_replace_escape_re, find, replace, original_find, original_replace); break; case GEANY_RESPONSE_REPLACE_IN_SEL: - document_replace_sel(doc, find, replace, search_flags_re, search_replace_escape_re); + document_replace_sel(doc, find, replace, original_find, original_replace, search_flags_re); break; } switch (response) @@ -1443,6 +1437,7 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) g_free(find); g_free(replace); g_free(original_find); + g_free(original_replace); return; fail: @@ -1450,6 +1445,8 @@ fail: gtk_widget_grab_focus(replace_dlg.find_entry); g_free(find); g_free(replace); + g_free(original_find); + g_free(original_replace); } -- 1.7.5.1
_______________________________________________ Geany-devel mailing list [email protected] https://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
