Revision: 5832 http://geany.svn.sourceforge.net/geany/?rev=5832&view=rev Author: colombanw Date: 2011-06-03 13:40:42 +0000 (Fri, 03 Jun 2011)
Log Message: ----------- 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.
Patch by Eugene Arshinov, thanks.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/document.h trunk/src/editor.c trunk/src/search.c trunk/src/search.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/ChangeLog 2011-06-03 13:40:42 UTC (rev 5832) @@ -1,3 +1,11 @@ +2011-06-03 Colomban Wendling <colomban(at)geany(dot)org> + + * src/callbacks.c, src/document.c, src/document.h, src/editor.c, + src/search.c, src/search.h: + Show the actual text the user searched for in messages rather than + the internal one (patch by Eugene Arshinov, thanks). + + 2011-06-02 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/document.c, src/document.h, src/ui_utils.c, src/ui_utils.h:
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/callbacks.c 2011-06-03 13:40:42 UTC (rev 5832) @@ -538,6 +538,7 @@ 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 @@ 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 @@ { keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL); } -
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/document.c 2011-06-03 13:40:42 UTC (rev 5832) @@ -1928,9 +1928,13 @@
/* 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 @@ 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 @@ 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 @@ /* 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 @@
/* 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 @@ 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 @@ 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; @@ -2054,37 +2068,22 @@ }
-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, *escaped_replace_text, *filename; + gchar *filename;
if (count == 0) { - 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); }
@@ -2134,7 +2133,7 @@
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; @@ -2231,13 +2230,13 @@ 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); @@ -2249,7 +2248,7 @@ 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; }
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/document.h 2011-06-03 13:40:42 UTC (rev 5832) @@ -217,17 +217,17 @@ 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); + 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);
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/editor.c 2011-06-03 13:40:42 UTC (rev 5832) @@ -2791,7 +2791,7 @@ 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 @@ 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 */
Modified: trunk/src/search.c =================================================================== --- trunk/src/search.c 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/search.c 2011-06-03 13:40:42 UTC (rev 5832) @@ -266,6 +266,7 @@ void search_init(void) { search_data.text = NULL; + search_data.original_text = NULL; init_prefs(); }
@@ -279,6 +280,7 @@ 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 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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,8 @@
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 *replace, + const gchar *original_find, const gchar *original_replace) { guint n, page_count, rep_count = 0, file_count = 0;
@@ -1307,8 +1314,7 @@ 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++; @@ -1316,7 +1322,7 @@ 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 @@ 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 = NULL, *original_replace = NULL;
gtk_window_get_position(GTK_WINDOW(replace_dlg.dialog), &replace_dlg.position[0], &replace_dlg.position[1]); @@ -1363,6 +1369,9 @@ if ((response != GEANY_RESPONSE_FIND) && (search_flags_re & SCFIND_MATCHCASE) && (strcmp(find, replace) == 0)) 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) || @@ -1385,37 +1394,36 @@ { 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; } 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, 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) @@ -1428,6 +1436,8 @@ } g_free(find); g_free(replace); + g_free(original_find); + g_free(original_replace); return;
fail: @@ -1435,6 +1445,8 @@ gtk_widget_grab_focus(replace_dlg.find_entry); g_free(find); g_free(replace); + g_free(original_find); + g_free(original_replace); }
@@ -2012,7 +2024,8 @@ }
-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 +2060,17 @@
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 +2148,7 @@ 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 +2159,3 @@ toolbar_get_widget_child_by_name("SearchEntry"), (result > -1)); } } - -
Modified: trunk/src/search.h =================================================================== --- trunk/src/search.h 2011-06-02 23:02:53 UTC (rev 5831) +++ trunk/src/search.h 2011-06-03 13:40:42 UTC (rev 5832) @@ -39,6 +39,8 @@ /* 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 @@
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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.