Added option to replace escape sequences in Find and Replace dialog.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@578 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2006-07-18 10:48:51 +00:00
parent c00a9decca
commit 7bbccd884d
3 changed files with 54 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2006-07-18 Enrico Tröger <enrico.troeger@uvena.de>
* src/dialogs.c, src/callbacks.c:
Added option to replace escape sequences in Find and Replace dialog.
2006-07-17 Nick Treleaven <nick.treleaven@btinternet.com> 2006-07-17 Nick Treleaven <nick.treleaven@btinternet.com>
* doc/scikeybinding.docbook, doc/geany.docbook, doc/geany_gpl.docbook: * doc/scikeybinding.docbook, doc/geany.docbook, doc/geany_gpl.docbook:

View File

@ -80,8 +80,10 @@ static gboolean ignore_toolbar_toggle = FALSE;
// the flags given in the search dialog(stored statically for "find next" and "replace") // the flags given in the search dialog(stored statically for "find next" and "replace")
static gint search_flags; static gint search_flags;
static gboolean search_backwards; static gboolean search_backwards;
static gboolean search_replace_escape;
static gint search_flags_re; static gint search_flags_re;
static gboolean search_backwards_re; static gboolean search_backwards_re;
static gboolean search_replace_escape_re;
static gboolean search_in_all_buffers_re; static gboolean search_in_all_buffers_re;
// holds the current position where the mouse pointer is when the popup menu for the scintilla // holds the current position where the mouse pointer is when the popup menu for the scintilla
@ -1824,6 +1826,8 @@ on_find_dialog_response (GtkDialog *dialog,
lookup_widget(GTK_WIDGET(app->find_dialog), "check_regexp"))), lookup_widget(GTK_WIDGET(app->find_dialog), "check_regexp"))),
fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->find_dialog), "check_wordstart"))); lookup_widget(GTK_WIDGET(app->find_dialog), "check_wordstart")));
search_replace_escape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->find_dialog), "check_escape")));
search_backwards = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( search_backwards = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->find_dialog), "check_back"))); lookup_widget(GTK_WIDGET(app->find_dialog), "check_back")));
@ -1835,6 +1839,12 @@ on_find_dialog_response (GtkDialog *dialog,
gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->find_dialog, "entry"))->child)); gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->find_dialog, "entry"))->child));
return; return;
} }
else if (search_replace_escape)
{
app->search_text = utils_str_replace(app->search_text, "\\n", "\n");
app->search_text = utils_str_replace(app->search_text, "\\r", "\r");
app->search_text = utils_str_replace(app->search_text, "\\t", "\t");
}
gtk_widget_hide(app->find_dialog); gtk_widget_hide(app->find_dialog);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), app->search_text); gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), app->search_text);
@ -1866,7 +1876,7 @@ on_replace_dialog_response (GtkDialog *dialog,
GtkWidget *entry_find = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_find"); GtkWidget *entry_find = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_find");
GtkWidget *entry_replace = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_replace"); GtkWidget *entry_replace = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_replace");
gboolean fl1, fl2, fl3, fl4; gboolean fl1, fl2, fl3, fl4;
const gchar *find, *replace; gchar *find, *replace;
if (response == GTK_RESPONSE_CANCEL) if (response == GTK_RESPONSE_CANCEL)
{ {
@ -1884,10 +1894,12 @@ on_replace_dialog_response (GtkDialog *dialog,
lookup_widget(GTK_WIDGET(app->replace_dialog), "check_wordstart"))); lookup_widget(GTK_WIDGET(app->replace_dialog), "check_wordstart")));
search_backwards_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( search_backwards_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->replace_dialog), "check_back"))); lookup_widget(GTK_WIDGET(app->replace_dialog), "check_back")));
search_replace_escape_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->replace_dialog), "check_escape")));
search_in_all_buffers_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( search_in_all_buffers_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
lookup_widget(GTK_WIDGET(app->replace_dialog), "check_all_buffers"))); lookup_widget(GTK_WIDGET(app->replace_dialog), "check_all_buffers")));
find = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find)))); find = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find)))));
replace = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace)))); replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace)))));
if ((! fl1) && (strcasecmp(find, replace) == 0)) if ((! fl1) && (strcasecmp(find, replace) == 0))
{ {
@ -1896,9 +1908,20 @@ on_replace_dialog_response (GtkDialog *dialog,
return; return;
} }
gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_find), find); gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_find), find);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_replace), replace); gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_replace), replace);
if (search_replace_escape_re)
{
find = utils_str_replace(find, "\\n", "\n");
find = utils_str_replace(find, "\\r", "\r");
find = utils_str_replace(find, "\\t", "\t");
replace = utils_str_replace(replace, "\\n", "\n");
replace = utils_str_replace(replace, "\\r", "\r");
replace = utils_str_replace(replace, "\\t", "\t");
}
search_flags_re = (fl1 ? SCFIND_MATCHCASE : 0) | search_flags_re = (fl1 ? SCFIND_MATCHCASE : 0) |
(fl2 ? SCFIND_WHOLEWORD : 0) | (fl2 ? SCFIND_WHOLEWORD : 0) |
(fl3 ? SCFIND_REGEXP : 0) | (fl3 ? SCFIND_REGEXP : 0) |
@ -1935,6 +1958,8 @@ on_replace_dialog_response (GtkDialog *dialog,
} }
} }
} }
g_free(find);
g_free(replace);
} }

View File

@ -811,7 +811,8 @@ void dialogs_show_find(void)
if (app->find_dialog == NULL) if (app->find_dialog == NULL)
{ {
GtkWidget *label, *entry, *checkbox1, *checkbox2, *checkbox3, *checkbox4, *checkbox5; GtkWidget *label, *entry, *checkbox1, *checkbox2, *checkbox3, *checkbox4, *checkbox5,
*checkbox6;
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
app->find_dialog = gtk_dialog_new_with_buttons(_("Find"), GTK_WINDOW(app->window), app->find_dialog = gtk_dialog_new_with_buttons(_("Find"), GTK_WINDOW(app->window),
@ -857,6 +858,13 @@ void dialogs_show_find(void)
gtk_tooltips_set_tip(tooltips, checkbox3, gtk_tooltips_set_tip(tooltips, checkbox3,
_("For detailed information about using regular expressions, please read the documentation."), NULL); _("For detailed information about using regular expressions, please read the documentation."), NULL);
checkbox6 = gtk_check_button_new_with_mnemonic(_("_Replace control characters"));
g_object_set_data_full(G_OBJECT(app->find_dialog), "check_escape",
gtk_widget_ref(checkbox6), (GDestroyNotify)gtk_widget_unref);
gtk_button_set_focus_on_click(GTK_BUTTON(checkbox6), FALSE);
gtk_tooltips_set_tip(tooltips, checkbox6,
_("Replace \\t, \\n and \\r with the corresponding control characters."), NULL);
checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards")); checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards"));
g_object_set_data_full(G_OBJECT(app->find_dialog), "check_back", g_object_set_data_full(G_OBJECT(app->find_dialog), "check_back",
gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref); gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref);
@ -871,6 +879,7 @@ void dialogs_show_find(void)
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox2); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox2);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox5); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox5);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox3); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox3);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox6);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox4); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), checkbox4);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), gtk_label_new("")); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), gtk_label_new(""));
@ -905,7 +914,8 @@ void dialogs_show_replace(void)
if (app->replace_dialog == NULL) if (app->replace_dialog == NULL)
{ {
GtkWidget *label_find, *label_replace, *entry_find, *entry_replace; GtkWidget *label_find, *label_replace, *entry_find, *entry_replace;
GtkWidget *checkbox1, *checkbox2, *checkbox3, *checkbox4, *checkbox5, *checkbox6; GtkWidget *checkbox1, *checkbox2, *checkbox3, *checkbox4, *checkbox5, *checkbox6,
*checkbox7;
GtkWidget *button; GtkWidget *button;
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
@ -977,6 +987,13 @@ void dialogs_show_replace(void)
gtk_tooltips_set_tip(tooltips, checkbox3, gtk_tooltips_set_tip(tooltips, checkbox3,
_("For detailed information about using regular expressions, please read the documentation."), NULL); _("For detailed information about using regular expressions, please read the documentation."), NULL);
checkbox7 = gtk_check_button_new_with_mnemonic(_("_Replace control characters"));
g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_escape",
gtk_widget_ref(checkbox7), (GDestroyNotify)gtk_widget_unref);
gtk_button_set_focus_on_click(GTK_BUTTON(checkbox7), FALSE);
gtk_tooltips_set_tip(tooltips, checkbox7,
_("Replace \\t, \\n and \\r with the corresponding control characters."), NULL);
checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards")); checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards"));
g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_back", g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_back",
gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref); gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref);
@ -998,6 +1015,7 @@ void dialogs_show_replace(void)
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox2); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox2);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox5); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox5);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox3); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox3);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox7);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox4); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox4);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox6); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), checkbox6);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), gtk_label_new("")); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), gtk_label_new(""));