Added Find button to Replace dialog to skip a match; Change Replace button to find first & use current selection; Ask whether to wraparound when replacing and no next match is found

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@597 ea778897-0a13-0410-b9d1-a72fbfd435f5
master
Nick Treleaven 2006-07-20 21:19:18 +00:00
parent 43cae0b24a
commit 96a4a059df
6 changed files with 50 additions and 28 deletions

View File

@ -8,6 +8,13 @@
* TODO: Added 3 more items discussed on the ML.
* doc/scikeybinding.docbook: Commented out some keys not working.
* src/dialogs.c: Share find/replace common checkbox setup code.
* src/build.c, src/build.h, src/sciwrappers.h, src/dialogs.c,
src/dialogs.h: Don't include geany.h.
* src/geany.h, src/callbacks.h: Moved GEANY_RESPONSE_* to callbacks.h.
* src/callbacks.c, src/document.c, src/document.h, src/dialogs.c:
Added Find button to Replace dialog to skip a match.
Change Replace button to find first & use current selection.
Ask whether to wraparound when replacing and no next match is found.
2006-07-19 Enrico Tröger <enrico.troeger@uvena.de>

View File

@ -1984,6 +1984,11 @@ on_replace_dialog_response (GtkDialog *dialog,
search_backwards_re);
break;
}
case GEANY_RESPONSE_FIND:
{
document_find_text(idx, find, search_flags_re, search_backwards_re);
break;
}
case GEANY_RESPONSE_REPLACE_ALL:
{
document_replace_all(idx, find, replace, search_flags_re);

View File

@ -948,6 +948,10 @@ void dialogs_show_replace(void)
gtk_widget_show(button);
gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
GEANY_RESPONSE_REPLACE_ALL);
button = gtk_button_new_from_stock("gtk-find");
gtk_widget_show(button);
gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
GEANY_RESPONSE_FIND);
button = gtk_button_new_with_mnemonic(_("_Replace"));
gtk_widget_show(button);
gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
@ -993,7 +997,7 @@ void dialogs_show_replace(void)
g_signal_connect(G_OBJECT(check_regexp), "toggled",
G_CALLBACK(on_replace_checkbutton_toggled), NULL);
checkbox6 = gtk_check_button_new_with_mnemonic(_("Replace in all open files"));
checkbox6 = gtk_check_button_new_with_mnemonic(_("Replace in all _open files"));
g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_all_buffers",
gtk_widget_ref(checkbox6), (GDestroyNotify)gtk_widget_unref);
gtk_tooltips_set_tip(tooltips, checkbox6,

View File

@ -21,13 +21,9 @@
*/
#include "geany.h"
#ifndef GEANY_DIALOGS_H
#define GEANY_DIALOGS_H 1
/* This shows the file selection dialog to open a file. */
void dialogs_show_open_file(void);

View File

@ -50,7 +50,6 @@
#include "sci_cb.h"
#include "dialogs.h"
#include "msgwindow.h"
#include "callbacks.h"
#include "templates.h"
#include "treeviews.h"
#include "utils.h"
@ -730,18 +729,20 @@ void document_find_next(gint idx, const gchar *text, gint flags, gboolean find_b
}
/* general search function, used from the find dialog */
void document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards)
/* 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(gint idx, const gchar *text, gint flags, gboolean search_backwards)
{
gint selection_end, selection_start, search_pos;
g_return_if_fail(text != NULL);
if (idx == -1 || ! *text) return;
g_return_val_if_fail(text != NULL, -1);
if (idx == -1 || ! *text) return -1;
// Sci doesn't support searching backwards with a regex
if (flags & SCFIND_REGEXP) search_backwards = FALSE;
selection_start = sci_get_selection_start(doc_list[idx].sci);
selection_end = sci_get_selection_end(doc_list[idx].sci);
selection_start = sci_get_selection_start(doc_list[idx].sci);
selection_end = sci_get_selection_end(doc_list[idx].sci);
if ((selection_end - selection_start) > 0)
{ // there's a selection so go to the end
if (search_backwards)
@ -765,12 +766,14 @@ void document_find_text(gint idx, const gchar *text, gint flags, gboolean search
if (dialogs_show_not_found(text))
{
sci_goto_pos(doc_list[idx].sci, (search_backwards) ? sci_get_length(doc_list[idx].sci) : 0, TRUE);
document_find_text(idx, text, flags, search_backwards);
return document_find_text(idx, text, flags, search_backwards);
}
}
return search_pos;
}
/* Replaces the selection if it matches, otherwise just finds the next match */
void document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
gint flags, gboolean search_backwards)
{
@ -783,19 +786,22 @@ void document_replace_text(gint idx, const gchar *find_text, const gchar *replac
selection_start = sci_get_selection_start(doc_list[idx].sci);
selection_end = sci_get_selection_end(doc_list[idx].sci);
if ((selection_end - selection_start) > 0)
{ // there's a selection so go to the end
if (search_backwards)
sci_goto_pos(doc_list[idx].sci, selection_start, TRUE);
else
sci_goto_pos(doc_list[idx].sci, selection_end, TRUE);
if (selection_end == selection_start)
{
// no selection so just find the next match
document_find_text(idx, find_text, flags, search_backwards);
return;
}
sci_set_search_anchor(doc_list[idx].sci);
// there's a selection so go to the start before finding to search through it
// this ensures there is a match
if (search_backwards)
search_pos = sci_search_prev(doc_list[idx].sci, flags, find_text);
sci_goto_pos(doc_list[idx].sci, selection_end, TRUE);
else
search_pos = sci_search_next(doc_list[idx].sci, flags, find_text);
sci_goto_pos(doc_list[idx].sci, selection_start, TRUE);
search_pos = document_find_text(idx, find_text, flags, search_backwards);
// return if the original selected text did not match (at the start of the selection)
if (search_pos != selection_start) return;
if (search_pos != -1)
{
@ -803,13 +809,14 @@ void document_replace_text(gint idx, const gchar *find_text, const gchar *replac
// search next/prev will select matching text, which we use to set the replace target
sci_target_from_selection(doc_list[idx].sci);
replace_len = sci_target_replace(doc_list[idx].sci, replace_text, flags & SCFIND_REGEXP);
// select the replacement and scroll in view
// select the replacement - find text will skip past the selected text
sci_set_selection_start(doc_list[idx].sci, search_pos);
sci_set_selection_end(doc_list[idx].sci, search_pos + replace_len);
sci_scroll_caret(doc_list[idx].sci);
document_find_text(idx, find_text, flags, search_backwards);
}
else
{
// no match in the selection
utils_beep();
}
}

View File

@ -88,7 +88,12 @@ int document_reload_file(gint idx);
be UTF-8). */
void document_save_file (gint);
void document_find_text(gint, const gchar*, gint, gboolean);
/* special search function, used from the find entry in the toolbar */
void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
/* General search function, used from the find dialog.
* Returns -1 on failure or the start position of the matching text. */
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards);
void document_replace_text(gint, const gchar*, const gchar*, gint, gboolean);
@ -96,8 +101,6 @@ void document_replace_all(gint, const gchar*, const gchar*, gint);
void document_replace_sel(gint, const gchar*, const gchar*, gint);
void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
void document_set_font(gint, const gchar*, gint);
void document_update_tag_list(gint, gboolean);