Revision: 698 Author: ntrel Date: 2006-08-11 14:12:49 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=698&view=rev
Log Message: ----------- Group search related code
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/callbacks.h trunk/src/dialogs.c trunk/src/dialogs.h trunk/src/geany.h trunk/src/keybindings.c trunk/src/main.c trunk/src/search.c trunk/src/search.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/ChangeLog 2006-08-11 21:12:49 UTC (rev 698) @@ -1,3 +1,10 @@ +2006-08-11 Nick Treleaven nick.treleaven@btinternet.com + + * src/keybindings.c, src/geany.h, src/callbacks.c, src/callbacks.h, + src/search.c, src/search.h, src/dialogs.c, src/main.c, + src/dialogs.h: Group search related code. + + 2006-08-11 Enrico Tröger enrico.troeger@uvena.de
* src/document.c:
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/callbacks.c 2006-08-11 21:12:49 UTC (rev 698) @@ -74,10 +74,6 @@ // the selection-changed signal from tv.tree_openfiles //static gboolean switch_tv_notebook_page = FALSE;
-// the flags given in the search dialog(stored statically for "find next" and "replace") -static gint search_flags; -static gboolean search_backwards; - // holds the current position where the mouse pointer is when the popup menu for the scintilla // scintilla widget is shown static gint clickpos; @@ -121,7 +117,7 @@ g_free(app->configdir); g_free(app->datadir); g_free(app->docdir); - g_free(app->search_text); + g_free(search_data.text); g_free(app->editor_font); g_free(app->tagbar_font); g_free(app->msgwin_font); @@ -141,8 +137,6 @@ g_queue_free(app->recent_queue);
if (app->prefs_dialog && GTK_IS_WIDGET(app->prefs_dialog)) gtk_widget_destroy(app->prefs_dialog); - if (app->find_dialog && GTK_IS_WIDGET(app->find_dialog)) gtk_widget_destroy(app->find_dialog); - if (app->replace_dialog && GTK_IS_WIDGET(app->replace_dialog)) gtk_widget_destroy(app->replace_dialog); if (app->save_filesel && GTK_IS_WIDGET(app->save_filesel)) gtk_widget_destroy(app->save_filesel); if (app->open_filesel && GTK_IS_WIDGET(app->open_filesel)) gtk_widget_destroy(app->open_filesel); if (app->open_fontsel && GTK_IS_WIDGET(app->open_fontsel)) gtk_widget_destroy(app->open_fontsel); @@ -152,6 +146,7 @@ g_object_unref(app->default_tag_tree); gtk_widget_destroy(app->default_tag_tree); } + search_finalise(); scintilla_release_resources(); #ifdef HAVE_VTE if (app->have_vte) vte_close(); @@ -589,11 +584,11 @@
static void setup_find_next(GtkEditable *editable) { - g_free(app->search_text); - app->search_text = g_strdup(gtk_editable_get_chars(editable, 0, -1)); + g_free(search_data.text); + search_data.text = g_strdup(gtk_editable_get_chars(editable, 0, -1)); // clear search flags so can later use Search->Find Next/Previous - search_flags = 0; - search_backwards = FALSE; + search_data.flags = 0; + search_data.backwards = FALSE; }
@@ -605,7 +600,7 @@ gint idx = document_get_cur_idx();
setup_find_next(GTK_EDITABLE(entry)); - document_find_next(idx, app->search_text, 0, FALSE, FALSE); + document_find_next(idx, search_data.text, 0, FALSE, FALSE); }
@@ -617,7 +612,7 @@ gint idx = document_get_cur_idx();
setup_find_next(editable); - document_find_next(idx, app->search_text, 0, FALSE, TRUE); + document_find_next(idx, search_data.text, 0, FALSE, TRUE); }
@@ -631,7 +626,7 @@ GtkWidget *entry = lookup_widget(GTK_WIDGET(app->window), "entry1");
setup_find_next(GTK_EDITABLE(entry)); - document_find_next(idx, app->search_text, 0, TRUE, FALSE); + document_find_next(idx, search_data.text, 0, TRUE, FALSE); }
@@ -1796,27 +1791,19 @@ on_find1_activate (GtkMenuItem *menuitem, gpointer user_data) { - dialogs_show_find(); + search_show_find_dialog(); }
void -on_replace1_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ - dialogs_show_replace(); -} - - -void on_find_next1_activate (GtkMenuItem *menuitem, gpointer user_data) { gint idx = document_get_cur_idx();
- if (app->search_text) + if (search_data.text) { - document_find_text(idx, app->search_text, search_flags, search_backwards); + document_find_text(idx, search_data.text, search_data.flags, search_data.backwards); } }
@@ -1827,258 +1814,34 @@ { gint idx = document_get_cur_idx();
- if (app->search_text == NULL) return; + if (search_data.text == NULL) return;
- if (search_flags & SCFIND_REGEXP) + if (search_data.flags & SCFIND_REGEXP) utils_beep(); //Can't reverse search order for a regex (find next ignores search backwards) else { - document_find_text(idx, app->search_text, search_flags, - !search_backwards); + document_find_text(idx, search_data.text, search_data.flags, !search_data.backwards); } }
-void on_find_replace_checkbutton_toggled (GtkToggleButton *togglebutton, - gpointer user_data) -{ - GtkWidget *dialog = GTK_WIDGET(user_data); - GtkToggleButton *chk_regexp = GTK_TOGGLE_BUTTON( - lookup_widget(dialog, "check_regexp")); - - if (togglebutton == chk_regexp) - { - gboolean regex_set = gtk_toggle_button_get_active(chk_regexp); - GtkWidget *check_back = lookup_widget(dialog, "check_back"); - GtkWidget *check_word = lookup_widget(dialog, "check_word"); - GtkWidget *check_wordstart = lookup_widget(dialog, "check_wordstart"); - - gtk_widget_set_sensitive(check_back, ! regex_set); - gtk_widget_set_sensitive(check_word, ! regex_set); - gtk_widget_set_sensitive(check_wordstart, ! regex_set); - } -} - - void -on_find_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - gint idx = document_get_cur_idx(); - gboolean search_replace_escape; - gboolean - fl1 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->find_dialog), "check_case"))), - fl2 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->find_dialog), "check_word"))), - fl3 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->find_dialog), "check_regexp"))), - fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - 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( - lookup_widget(GTK_WIDGET(app->find_dialog), "check_back"))); - - g_free(app->search_text); - app->search_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data))))); - if (strlen(app->search_text) == 0 || - (search_replace_escape && ! utils_str_replace_escape(app->search_text))) - { - utils_beep(); - gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->find_dialog, "entry"))->child)); - return; - } - - gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), app->search_text); - search_flags = (fl1 ? SCFIND_MATCHCASE : 0) | - (fl2 ? SCFIND_WHOLEWORD : 0) | - (fl3 ? SCFIND_REGEXP | SCFIND_POSIX: 0) | - (fl4 ? SCFIND_WORDSTART : 0); - document_find_text(idx, app->search_text, search_flags, search_backwards); - } - else gtk_widget_hide(app->find_dialog); -} - - -void -on_find_entry_activate (GtkEntry *entry, +on_replace1_activate (GtkMenuItem *menuitem, gpointer user_data) { - on_find_dialog_response(NULL, GTK_RESPONSE_ACCEPT, - lookup_widget(GTK_WIDGET(entry), "entry")); + search_show_replace_dialog(); }
void -on_replace_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data) -{ - gint idx = document_get_cur_idx(); - GtkWidget *entry_find = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_find"); - GtkWidget *entry_replace = lookup_widget(GTK_WIDGET(app->replace_dialog), "entry_replace"); - gint search_flags_re; - gboolean search_backwards_re, search_replace_escape_re, search_in_all_buffers_re; - gboolean fl1, fl2, fl3, fl4; - gchar *find, *replace; - - if (response == GTK_RESPONSE_CANCEL) - { - gtk_widget_hide(app->replace_dialog); - return; - } - - fl1 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->replace_dialog), "check_case"))); - fl2 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->replace_dialog), "check_word"))); - fl3 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->replace_dialog), "check_regexp"))); - fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(GTK_WIDGET(app->replace_dialog), "check_wordstart"))); - search_backwards_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - 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( - lookup_widget(GTK_WIDGET(app->replace_dialog), "check_all_buffers"))); - find = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))))); - replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))))); - - if ((response != GEANY_RESPONSE_FIND) && (! fl1) && (strcasecmp(find, replace) == 0)) - { - utils_beep(); - gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->replace_dialog, "entry_find"))->child)); - return; - } - - gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_find), find); - gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_replace), replace); - - if (search_replace_escape_re && - (! utils_str_replace_escape(find) || ! utils_str_replace_escape(replace))) - { - utils_beep(); - gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->replace_dialog, "entry_find"))->child)); - return; - } - - search_flags_re = (fl1 ? SCFIND_MATCHCASE : 0) | - (fl2 ? SCFIND_WHOLEWORD : 0) | - (fl3 ? SCFIND_REGEXP | SCFIND_POSIX : 0) | - (fl4 ? SCFIND_WORDSTART : 0); - - if (search_in_all_buffers_re && response == GEANY_RESPONSE_REPLACE_ALL) - { - gint i; - for (i = 0; i < GEANY_MAX_OPEN_FILES; i++) - { - if (! doc_list[i].is_valid) continue; - - document_replace_all(i, find, replace, search_flags_re); - } - gtk_widget_hide(app->replace_dialog); - } - else - { - switch (response) - { - case GEANY_RESPONSE_REPLACE: - { - document_replace_text(idx, find, replace, search_flags_re, - 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); - gtk_widget_hide(app->replace_dialog); - break; - } - case GEANY_RESPONSE_REPLACE_SEL: - { - document_replace_sel(idx, find, replace, search_flags_re); - gtk_widget_hide(app->replace_dialog); - break; - } - } - } - g_free(find); - g_free(replace); -} - - -void -on_replace_entry_activate (GtkEntry *entry, - gpointer user_data) -{ - on_replace_dialog_response(NULL, GEANY_RESPONSE_REPLACE, NULL); -} - - -void on_find_in_files1_activate (GtkMenuItem *menuitem, gpointer user_data) { - dialogs_show_find_in_files(); + search_show_find_in_files_dialog(); }
void -on_find_in_files_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - const gchar *search_text = - gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))); - const gchar *utf8_dir = - gtk_entry_get_text(GTK_ENTRY(lookup_widget(app->find_in_files_dialog, "entry_dir"))); - - if (utf8_dir == NULL || utils_strcmp(utf8_dir, "")) - msgwin_status_add(_("Invalid directory for find in files.")); - else if (search_text && *search_text) - { - gchar *locale_dir; - gboolean eregexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(app->find_in_files_dialog, "check_eregexp"))); - gboolean invert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(app->find_in_files_dialog, "check_invert"))); - gboolean case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - lookup_widget(app->find_in_files_dialog, "check_case"))); - gint opts = (eregexp ? FIF_USE_EREGEXP : 0) | - (invert ? FIF_INVERT_MATCH : 0) | - (case_sens ? FIF_CASE_SENSITIVE : 0); - - locale_dir = g_locale_from_utf8(utf8_dir, -1, NULL, NULL, NULL); - if (locale_dir == NULL) locale_dir = g_strdup(utf8_dir); - - if (search_find_in_files(search_text, locale_dir, opts)) - { - gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), search_text); - gtk_widget_hide(app->find_in_files_dialog); - } - g_free(locale_dir); - } - else - msgwin_status_add(_("No text to find.")); - } - else - gtk_widget_hide(app->find_in_files_dialog); -} - - -void on_toolbutton_new_clicked (GtkToolButton *toolbutton, gpointer user_data) {
Modified: trunk/src/callbacks.h =================================================================== --- trunk/src/callbacks.h 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/callbacks.h 2006-08-11 21:12:49 UTC (rev 698) @@ -20,14 +20,6 @@ * $Id$ */
-enum { - GEANY_RESPONSE_REPLACE = 1, - GEANY_RESPONSE_REPLACE_ALL, - GEANY_RESPONSE_REPLACE_SEL, - GEANY_RESPONSE_FIND -}; - - extern gchar current_word[]; //needed for popup menu keybindings access
void @@ -386,37 +378,15 @@ on_find_previous1_activate (GtkMenuItem *menuitem, gpointer user_data);
-void on_find_replace_checkbutton_toggled (GtkToggleButton *togglebutton, - gpointer user_data); - void -on_find_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data); - -void -on_find_entry_activate (GtkEntry *entry, +on_replace1_activate (GtkMenuItem *menuitem, gpointer user_data);
void -on_replace_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data); - -void -on_replace_entry_activate (GtkEntry *entry, - gpointer user_data); - -void on_find_in_files1_activate (GtkMenuItem *menuitem, gpointer user_data);
void -on_find_in_files_dialog_response (GtkDialog *dialog, - gint response, - gpointer user_data); - -void on_new_with_template (GtkMenuItem *menuitem, gpointer user_data);
@@ -522,10 +492,6 @@ gpointer user_data);
void -on_replace1_activate (GtkMenuItem *menuitem, - gpointer user_data); - -void on_tv_notebook_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num,
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/dialogs.c 2006-08-11 21:12:49 UTC (rev 698) @@ -46,9 +46,6 @@ #include "keybindings.h"
-static void dialogs_add_find_checkboxes(GtkDialog *dialog); - - /* This shows the file selection dialog to open a file. */ void dialogs_show_open_file () { @@ -761,354 +758,6 @@ }
-static void dialogs_add_find_checkboxes(GtkDialog *dialog) -{ - GtkWidget *checkbox1, *checkbox2, *check_regexp, *checkbox4, *checkbox5, - *checkbox7, *hbox, *lbox, *rbox; - GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); - - checkbox1 = gtk_check_button_new_with_mnemonic(_("_Case sensitive")); - g_object_set_data_full(G_OBJECT(dialog), "check_case", - gtk_widget_ref(checkbox1), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox1), FALSE); - - checkbox2 = gtk_check_button_new_with_mnemonic(_("Match only a _whole word")); - g_object_set_data_full(G_OBJECT(dialog), "check_word", - gtk_widget_ref(checkbox2), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox2), FALSE); - - checkbox5 = gtk_check_button_new_with_mnemonic(_("Match only word s_tart")); - g_object_set_data_full(G_OBJECT(dialog), "check_wordstart", - gtk_widget_ref(checkbox5), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox5), FALSE); - - lbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(lbox), checkbox1); - gtk_container_add(GTK_CONTAINER(lbox), checkbox2); - gtk_container_add(GTK_CONTAINER(lbox), checkbox5); - - check_regexp = gtk_check_button_new_with_mnemonic(_("_Use regular expressions")); - g_object_set_data_full(G_OBJECT(dialog), "check_regexp", - gtk_widget_ref(check_regexp), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(check_regexp), FALSE); - gtk_tooltips_set_tip(tooltips, check_regexp, _("Use POSIX-like regular expressions. " - "For detailed information about using regular expressions, please read the documentation."), NULL); - g_signal_connect(G_OBJECT(check_regexp), "toggled", - G_CALLBACK(on_find_replace_checkbutton_toggled), GTK_WIDGET(dialog)); - - checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards")); - g_object_set_data_full(G_OBJECT(dialog), "check_back", - gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox4), FALSE); - - checkbox7 = gtk_check_button_new_with_mnemonic(_("_Replace control characters")); - g_object_set_data_full(G_OBJECT(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, \r and \uXXXX (Unicode chararacters) with the " - "corresponding control characters."), NULL); - - rbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(rbox), check_regexp); - gtk_container_add(GTK_CONTAINER(rbox), checkbox7); - gtk_container_add(GTK_CONTAINER(rbox), checkbox4); - - hbox = gtk_hbox_new(FALSE, 6); - gtk_container_add(GTK_CONTAINER(hbox), lbox); - gtk_container_add(GTK_CONTAINER(hbox), rbox); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 6); -} - - -void dialogs_show_find(void) -{ - gint idx = document_get_cur_idx(); - gchar *sel = NULL; - - if (idx == -1 || ! doc_list[idx].is_valid) return; - - if (sci_get_lines_selected(doc_list[idx].sci) == 1) - { - sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); - sci_get_selected_text(doc_list[idx].sci, sel); - } - - if (app->find_dialog == NULL) - { - GtkWidget *label, *entry, *vbox; - - app->find_dialog = gtk_dialog_new_with_buttons(_("Find"), - GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, - GTK_STOCK_FIND, GTK_RESPONSE_ACCEPT, NULL); - - label = gtk_label_new(_("Enter the search text here:")); - gtk_misc_set_padding(GTK_MISC(label), 0, 6); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - - entry = gtk_combo_box_entry_new_text(); - gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry))), 248); - gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry))), 50); - if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(entry)->child), sel); - g_object_set_data_full(G_OBJECT(app->find_dialog), "entry", - gtk_widget_ref(entry), (GDestroyNotify)gtk_widget_unref); - - g_signal_connect((gpointer) gtk_bin_get_child(GTK_BIN(entry)), "activate", - G_CALLBACK(on_find_entry_activate), NULL); - g_signal_connect((gpointer) app->find_dialog, "response", - G_CALLBACK(on_find_dialog_response), entry); - g_signal_connect((gpointer) app->find_dialog, "delete_event", - G_CALLBACK(gtk_widget_hide), NULL); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(vbox), label); - gtk_container_add(GTK_CONTAINER(vbox), entry); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->find_dialog)->vbox), vbox); - - dialogs_add_find_checkboxes(GTK_DIALOG(app->find_dialog)); - - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(app->find_dialog)->vbox), 3); - - gtk_widget_show_all(app->find_dialog); - } - else - { - if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN( - lookup_widget(app->find_dialog, "entry"))->child), sel); - gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->find_dialog, "entry"))->child)); - gtk_widget_show(app->find_dialog); - } - g_free(sel); -} - - -void dialogs_show_replace(void) -{ - gint idx = document_get_cur_idx(); - gchar *sel = NULL; - - if (idx == -1 || ! doc_list[idx].is_valid) return; - - if (sci_get_lines_selected(doc_list[idx].sci) == 1) - { - sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); - sci_get_selected_text(doc_list[idx].sci, sel); - } - - if (app->replace_dialog == NULL) - { - GtkWidget *label_find, *label_replace, *entry_find, *entry_replace, - *checkbox6, *button, *align, *rbox, *fbox; - GtkSizeGroup *size_group; - GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); - - app->replace_dialog = gtk_dialog_new_with_buttons(_("Replace"), - GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL); - - button = gtk_button_new_with_mnemonic(_("_In Selection")); - gtk_tooltips_set_tip(tooltips, button, - _("Replace all matches found in the currently selected text"), NULL); - gtk_widget_show(button); - gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button, - GEANY_RESPONSE_REPLACE_SEL); - button = gtk_button_new_with_mnemonic(_("Replace _All")); - 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_STOCK_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, - GEANY_RESPONSE_REPLACE); - - label_find = gtk_label_new(_("Enter the search text here:")); - gtk_misc_set_alignment(GTK_MISC(label_find), 0, 0.5); - - label_replace = gtk_label_new(_("Enter the replace text here:")); - gtk_misc_set_alignment(GTK_MISC(label_replace), 0, 0.5); - - entry_find = gtk_combo_box_entry_new_text(); - gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))), 248); - gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))), 50); - if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(entry_find)->child), sel); - g_object_set_data_full(G_OBJECT(app->replace_dialog), "entry_find", - gtk_widget_ref(entry_find), (GDestroyNotify)gtk_widget_unref); - - entry_replace = gtk_combo_box_entry_new_text(); - gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))), 248); - gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))), 50); - g_object_set_data_full(G_OBJECT(app->replace_dialog), "entry_replace", - gtk_widget_ref(entry_replace), (GDestroyNotify)gtk_widget_unref); - - g_signal_connect((gpointer) gtk_bin_get_child(GTK_BIN(entry_replace)), "activate", - G_CALLBACK(on_replace_entry_activate), NULL); - g_signal_connect((gpointer) app->replace_dialog, "response", - G_CALLBACK(on_replace_dialog_response), entry_replace); - g_signal_connect((gpointer) app->replace_dialog, "delete_event", - G_CALLBACK(gtk_widget_hide), NULL); - - fbox = gtk_hbox_new(FALSE, 6); - gtk_container_add(GTK_CONTAINER(fbox), label_find); - gtk_container_add(GTK_CONTAINER(fbox), entry_find); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->replace_dialog)->vbox), fbox, - FALSE, FALSE, 6); - - rbox = gtk_hbox_new(FALSE, 6); - gtk_container_add(GTK_CONTAINER(rbox), label_replace); - gtk_container_add(GTK_CONTAINER(rbox), entry_replace); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->replace_dialog)->vbox), rbox, - FALSE, FALSE, 3); - - size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget(size_group, label_find); - gtk_size_group_add_widget(size_group, label_replace); - - dialogs_add_find_checkboxes(GTK_DIALOG(app->replace_dialog)); - - 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, - _("Replaces the search text in all opened files. This option is only useful(and used) if you click on "Replace All"."), NULL); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox6), FALSE); - - align = gtk_alignment_new(0, 0, 1, 1); - gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 9, 0, 0); - gtk_container_add(GTK_CONTAINER(align), checkbox6); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(app->replace_dialog)->vbox), align); - - gtk_widget_show_all(app->replace_dialog); - } - else - { - if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN( - lookup_widget(app->replace_dialog, "entry_find"))->child), sel); - gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->replace_dialog, "entry_find"))->child)); - gtk_widget_show(app->replace_dialog); - } - g_free(sel); -} - - -void dialogs_show_find_in_files(void) -{ - static GtkWidget *combo = NULL; - static GtkWidget *entry1; - GtkWidget *entry2; // the child GtkEntry of combo - gint idx = document_get_cur_idx(); - gchar *sel = NULL; - gchar *cur_dir; - - if (idx == -1 || ! doc_list[idx].is_valid) return; - - cur_dir = utils_get_current_file_dir(); - - if (app->find_in_files_dialog == NULL) - { - GtkWidget *label, *label1, *checkbox1, *checkbox2, *checkbox3, *vbox2, *vbox1; - GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); - - app->find_in_files_dialog = gtk_dialog_new_with_buttons( - _("Find in files"), GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - - gtk_dialog_add_button(GTK_DIALOG(app->find_in_files_dialog), "gtk-find", GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response(GTK_DIALOG(app->find_in_files_dialog), - GTK_RESPONSE_ACCEPT); - - label1 = gtk_label_new("Directory to be searched:"); - gtk_misc_set_alignment(GTK_MISC(label1), 0, 0); - - entry1 = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(entry1), 248); - gtk_entry_set_width_chars(GTK_ENTRY(entry1), 50); - g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "entry_dir", - gtk_widget_ref(entry1), (GDestroyNotify)gtk_widget_unref); - - vbox1 = gtk_vbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox1), label1, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox1), entry1, FALSE, FALSE, 0); - - label = gtk_label_new(_("Enter the search text here:")); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - - combo = gtk_combo_box_entry_new_text(); - entry2 = gtk_bin_get_child(GTK_BIN(combo)); - gtk_entry_set_max_length(GTK_ENTRY(entry2), 248); - gtk_entry_set_width_chars(GTK_ENTRY(entry2), 50); - gtk_entry_set_activates_default(GTK_ENTRY(entry2), TRUE); - - checkbox1 = gtk_check_button_new_with_mnemonic(_("_Case sensitive")); - g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_case", - gtk_widget_ref(checkbox1), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox1), FALSE); - - checkbox2 = gtk_check_button_new_with_mnemonic(_("Invert search results")); - g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_invert", - gtk_widget_ref(checkbox2), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox2), FALSE); - gtk_tooltips_set_tip(tooltips, checkbox2, - _("Invert the sense of matching, to select non-matching lines."), NULL); - - checkbox3 = gtk_check_button_new_with_mnemonic(_("_Use extended regular expressions")); - g_object_set_data_full(G_OBJECT(app->find_in_files_dialog), "check_eregexp", - gtk_widget_ref(checkbox3), (GDestroyNotify)gtk_widget_unref); - gtk_button_set_focus_on_click(GTK_BUTTON(checkbox3), FALSE); - gtk_tooltips_set_tip(tooltips, checkbox3, - _("See grep's manual page for more information."), NULL); - - vbox2 = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(vbox2), checkbox1); - gtk_container_add(GTK_CONTAINER(vbox2), checkbox2); - gtk_container_add(GTK_CONTAINER(vbox2), checkbox3); - - g_signal_connect((gpointer) app->find_in_files_dialog, "response", - G_CALLBACK(on_find_in_files_dialog_response), combo); - g_signal_connect((gpointer) app->find_in_files_dialog, "delete_event", - G_CALLBACK(gtk_widget_hide), NULL); - - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), - vbox1, TRUE, TRUE, 6); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), - label, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), - combo, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), - vbox2, TRUE, TRUE, 6); - - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(app->find_in_files_dialog)->vbox), 6); - - gtk_widget_show_all(app->find_in_files_dialog); - } - - if (sci_get_lines_selected(doc_list[idx].sci) == 1) - { - sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); - sci_get_selected_text(doc_list[idx].sci, sel); - } - - entry2 = GTK_BIN(combo)->child; - if (sel) gtk_entry_set_text(GTK_ENTRY(entry2), sel); - g_free(sel); - - if (cur_dir) gtk_entry_set_text(GTK_ENTRY(entry1), cur_dir); - g_free(cur_dir); - - // put the focus to the directory entry if it is empty - if (utils_strcmp(gtk_entry_get_text(GTK_ENTRY(entry1)), "")) - gtk_widget_grab_focus(entry1); - else - gtk_widget_grab_focus(entry2); - - gtk_widget_show(app->find_in_files_dialog); -} - - void dialogs_show_includes_arguments_tex(void) { GtkWidget *dialog, *label, *entries[4];
Modified: trunk/src/dialogs.h =================================================================== --- trunk/src/dialogs.h 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/dialogs.h 2006-08-11 21:12:49 UTC (rev 698) @@ -49,12 +49,6 @@
void dialogs_show_make_target(void);
-void dialogs_show_find(void); - -void dialogs_show_replace(void); - -void dialogs_show_find_in_files(void); - void dialogs_show_goto_line(void);
void dialogs_show_includes_arguments_gen(void);
Modified: trunk/src/geany.h =================================================================== --- trunk/src/geany.h 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/geany.h 2006-08-11 21:12:49 UTC (rev 698) @@ -189,7 +189,6 @@ gchar *configdir; gchar *datadir; gchar *docdir; - gchar *search_text; gchar build_make_custopt[256]; gchar *tools_browser_cmd; gchar *tools_make_cmd; @@ -222,9 +221,6 @@ GtkWidget *open_filesel; GtkWidget *save_filesel; GtkWidget *prefs_dialog; - GtkWidget *find_dialog; - GtkWidget *replace_dialog; - GtkWidget *find_in_files_dialog; GtkWidget *default_tag_tree; const TMWorkspace *tm_workspace; GQueue *recent_queue;
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/keybindings.c 2006-08-11 21:12:49 UTC (rev 698) @@ -29,7 +29,6 @@ #include "utils.h" #include "document.h" #include "callbacks.h" -#include "dialogs.h" #include "prefs.h" #include "msgwindow.h" #include "sci_cb.h" @@ -411,7 +410,7 @@
static void cb_func_menu_open(void) { - dialogs_show_open_file(); + on_open1_activate(NULL, NULL); }
static void cb_func_menu_save(void) @@ -456,7 +455,7 @@
static void cb_func_menu_preferences(void) { - dialogs_show_prefs_dialog(); + on_preferences1_activate(NULL, NULL); }
static void cb_func_menu_findnext(void) @@ -471,12 +470,12 @@
static void cb_func_menu_replace(void) { - dialogs_show_replace(); + on_replace1_activate(NULL, NULL); }
static void cb_func_menu_findinfiles(void) { - dialogs_show_find_in_files(); + on_find_in_files1_activate(NULL, NULL); }
static void cb_func_menu_gotoline(void)
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/main.c 2006-08-11 21:12:49 UTC (rev 698) @@ -49,6 +49,7 @@ #include "notebook.h" #include "keybindings.h" #include "sci_cb.h" +#include "search.h"
#ifdef HAVE_VTE # include "vte.h" @@ -222,15 +223,11 @@ else app->configdir = g_strconcat(GEANY_HOME_DIR, G_DIR_SEPARATOR_S, ".", PACKAGE, NULL); app->window = NULL; - app->search_text = NULL; app->open_fontsel = NULL; app->open_colorsel = NULL; app->open_filesel = NULL; app->save_filesel = NULL; app->prefs_dialog = NULL; - app->find_dialog = NULL; - app->replace_dialog = NULL; - app->find_in_files_dialog = NULL; app->default_tag_tree = NULL; app->main_window_realized= FALSE; app->tab_order_ltr = FALSE; @@ -323,6 +320,8 @@ msgwindow.tree_status = lookup_widget(app->window, "treeview3"); msgwindow.tree_msg = lookup_widget(app->window, "treeview4"); msgwindow.tree_compiler = lookup_widget(app->window, "treeview5"); + + search_init(); }
Modified: trunk/src/search.c =================================================================== --- trunk/src/search.c 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/search.c 2006-08-11 21:12:49 UTC (rev 698) @@ -25,8 +25,11 @@ #include "support.h" #include "utils.h" #include "msgwindow.h" +#include "document.h" +#include "sciwrappers.h"
#include <unistd.h> +#include <string.h>
#ifdef G_OS_UNIX # include <sys/types.h> @@ -34,6 +37,23 @@ #endif
+enum { + GEANY_RESPONSE_REPLACE = 1, + GEANY_RESPONSE_REPLACE_ALL, + GEANY_RESPONSE_REPLACE_SEL, + GEANY_RESPONSE_FIND +}; + +GeanySearchData search_data; + +static struct +{ + GtkWidget *find_dialog; + GtkWidget *replace_dialog; + GtkWidget *find_in_files_dialog; +} widgets; + + static gboolean search_read_io (GIOChannel *source, GIOCondition condition, gpointer data); @@ -45,6 +65,619 @@ static GSList *search_get_file_list(const gchar *path, gint *length);
+static void add_find_checkboxes(GtkDialog *dialog); + +static void +on_find_replace_checkbutton_toggled(GtkToggleButton *togglebutton, gpointer user_data); + +static void +on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data); + +static void +on_find_entry_activate(GtkEntry *entry, gpointer user_data); + +static void +on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data); + +static void +on_replace_entry_activate(GtkEntry *entry, gpointer user_data); + +static void +on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data); + + +void search_init() +{ + widgets.find_dialog = NULL; + widgets.replace_dialog = NULL; + widgets.find_in_files_dialog = NULL; + search_data.text = NULL; +} + + +#define FREE_WIDGET(wid) \ + if (wid && GTK_IS_WIDGET(wid)) gtk_widget_destroy(wid); + +void search_finalise() +{ + FREE_WIDGET(widgets.find_dialog); + FREE_WIDGET(widgets.replace_dialog); + FREE_WIDGET(widgets.find_in_files_dialog); + g_free(search_data.text); +} + + +static void add_find_checkboxes(GtkDialog *dialog) +{ + GtkWidget *checkbox1, *checkbox2, *check_regexp, *checkbox4, *checkbox5, + *checkbox7, *hbox, *lbox, *rbox; + GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); + + checkbox1 = gtk_check_button_new_with_mnemonic(_("_Case sensitive")); + g_object_set_data_full(G_OBJECT(dialog), "check_case", + gtk_widget_ref(checkbox1), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox1), FALSE); + + checkbox2 = gtk_check_button_new_with_mnemonic(_("Match only a _whole word")); + g_object_set_data_full(G_OBJECT(dialog), "check_word", + gtk_widget_ref(checkbox2), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox2), FALSE); + + checkbox5 = gtk_check_button_new_with_mnemonic(_("Match only word s_tart")); + g_object_set_data_full(G_OBJECT(dialog), "check_wordstart", + gtk_widget_ref(checkbox5), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox5), FALSE); + + lbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(lbox), checkbox1); + gtk_container_add(GTK_CONTAINER(lbox), checkbox2); + gtk_container_add(GTK_CONTAINER(lbox), checkbox5); + + check_regexp = gtk_check_button_new_with_mnemonic(_("_Use regular expressions")); + g_object_set_data_full(G_OBJECT(dialog), "check_regexp", + gtk_widget_ref(check_regexp), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(check_regexp), FALSE); + gtk_tooltips_set_tip(tooltips, check_regexp, _("Use POSIX-like regular expressions. " + "For detailed information about using regular expressions, please read the documentation."), NULL); + g_signal_connect(G_OBJECT(check_regexp), "toggled", + G_CALLBACK(on_find_replace_checkbutton_toggled), GTK_WIDGET(dialog)); + + checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards")); + g_object_set_data_full(G_OBJECT(dialog), "check_back", + gtk_widget_ref(checkbox4), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox4), FALSE); + + checkbox7 = gtk_check_button_new_with_mnemonic(_("_Replace control characters")); + g_object_set_data_full(G_OBJECT(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, \r and \uXXXX (Unicode chararacters) with the " + "corresponding control characters."), NULL); + + rbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(rbox), check_regexp); + gtk_container_add(GTK_CONTAINER(rbox), checkbox7); + gtk_container_add(GTK_CONTAINER(rbox), checkbox4); + + hbox = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(hbox), lbox); + gtk_container_add(GTK_CONTAINER(hbox), rbox); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 6); +} + + +void search_show_find_dialog() +{ + gint idx = document_get_cur_idx(); + gchar *sel = NULL; + + if (idx == -1 || ! doc_list[idx].is_valid) return; + + if (sci_get_lines_selected(doc_list[idx].sci) == 1) + { + sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); + sci_get_selected_text(doc_list[idx].sci, sel); + } + + if (widgets.find_dialog == NULL) + { + GtkWidget *label, *entry, *vbox; + + widgets.find_dialog = gtk_dialog_new_with_buttons(_("Find"), + GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, + GTK_STOCK_FIND, GTK_RESPONSE_ACCEPT, NULL); + + label = gtk_label_new(_("Enter the search text here:")); + gtk_misc_set_padding(GTK_MISC(label), 0, 6); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + + entry = gtk_combo_box_entry_new_text(); + gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry))), 248); + gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry))), 50); + if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(entry)->child), sel); + g_object_set_data_full(G_OBJECT(widgets.find_dialog), "entry", + gtk_widget_ref(entry), (GDestroyNotify)gtk_widget_unref); + + g_signal_connect((gpointer) gtk_bin_get_child(GTK_BIN(entry)), "activate", + G_CALLBACK(on_find_entry_activate), NULL); + g_signal_connect((gpointer) widgets.find_dialog, "response", + G_CALLBACK(on_find_dialog_response), entry); + g_signal_connect((gpointer) widgets.find_dialog, "delete_event", + G_CALLBACK(gtk_widget_hide), NULL); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox), label); + gtk_container_add(GTK_CONTAINER(vbox), entry); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(widgets.find_dialog)->vbox), vbox); + + add_find_checkboxes(GTK_DIALOG(widgets.find_dialog)); + + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(widgets.find_dialog)->vbox), 3); + + gtk_widget_show_all(widgets.find_dialog); + } + else + { + if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN( + lookup_widget(widgets.find_dialog, "entry"))->child), sel); + gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(widgets.find_dialog, "entry"))->child)); + gtk_widget_show(widgets.find_dialog); + } + g_free(sel); +} + + +void search_show_replace_dialog() +{ + gint idx = document_get_cur_idx(); + gchar *sel = NULL; + + if (idx == -1 || ! doc_list[idx].is_valid) return; + + if (sci_get_lines_selected(doc_list[idx].sci) == 1) + { + sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); + sci_get_selected_text(doc_list[idx].sci, sel); + } + + if (widgets.replace_dialog == NULL) + { + GtkWidget *label_find, *label_replace, *entry_find, *entry_replace, + *checkbox6, *button, *align, *rbox, *fbox; + GtkSizeGroup *size_group; + GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); + + widgets.replace_dialog = gtk_dialog_new_with_buttons(_("Replace"), + GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL); + + button = gtk_button_new_with_mnemonic(_("_In Selection")); + gtk_tooltips_set_tip(tooltips, button, + _("Replace all matches found in the currently selected text"), NULL); + gtk_widget_show(button); + gtk_dialog_add_action_widget(GTK_DIALOG(widgets.replace_dialog), button, + GEANY_RESPONSE_REPLACE_SEL); + button = gtk_button_new_with_mnemonic(_("Replace _All")); + gtk_widget_show(button); + gtk_dialog_add_action_widget(GTK_DIALOG(widgets.replace_dialog), button, + GEANY_RESPONSE_REPLACE_ALL); + button = gtk_button_new_from_stock(GTK_STOCK_FIND); + gtk_widget_show(button); + gtk_dialog_add_action_widget(GTK_DIALOG(widgets.replace_dialog), button, + GEANY_RESPONSE_FIND); + button = gtk_button_new_with_mnemonic(_("_Replace")); + gtk_widget_show(button); + gtk_dialog_add_action_widget(GTK_DIALOG(widgets.replace_dialog), button, + GEANY_RESPONSE_REPLACE); + + label_find = gtk_label_new(_("Enter the search text here:")); + gtk_misc_set_alignment(GTK_MISC(label_find), 0, 0.5); + + label_replace = gtk_label_new(_("Enter the replace text here:")); + gtk_misc_set_alignment(GTK_MISC(label_replace), 0, 0.5); + + entry_find = gtk_combo_box_entry_new_text(); + gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))), 248); + gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))), 50); + if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(entry_find)->child), sel); + g_object_set_data_full(G_OBJECT(widgets.replace_dialog), "entry_find", + gtk_widget_ref(entry_find), (GDestroyNotify)gtk_widget_unref); + + entry_replace = gtk_combo_box_entry_new_text(); + gtk_entry_set_max_length(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))), 248); + gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))), 50); + g_object_set_data_full(G_OBJECT(widgets.replace_dialog), "entry_replace", + gtk_widget_ref(entry_replace), (GDestroyNotify)gtk_widget_unref); + + g_signal_connect((gpointer) gtk_bin_get_child(GTK_BIN(entry_replace)), "activate", + G_CALLBACK(on_replace_entry_activate), NULL); + g_signal_connect((gpointer) widgets.replace_dialog, "response", + G_CALLBACK(on_replace_dialog_response), entry_replace); + g_signal_connect((gpointer) widgets.replace_dialog, "delete_event", + G_CALLBACK(gtk_widget_hide), NULL); + + fbox = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(fbox), label_find); + gtk_container_add(GTK_CONTAINER(fbox), entry_find); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.replace_dialog)->vbox), fbox, + FALSE, FALSE, 6); + + rbox = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(rbox), label_replace); + gtk_container_add(GTK_CONTAINER(rbox), entry_replace); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.replace_dialog)->vbox), rbox, + FALSE, FALSE, 3); + + size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + gtk_size_group_add_widget(size_group, label_find); + gtk_size_group_add_widget(size_group, label_replace); + + add_find_checkboxes(GTK_DIALOG(widgets.replace_dialog)); + + checkbox6 = gtk_check_button_new_with_mnemonic(_("Replace in all _open files")); + g_object_set_data_full(G_OBJECT(widgets.replace_dialog), "check_all_buffers", + gtk_widget_ref(checkbox6), (GDestroyNotify)gtk_widget_unref); + gtk_tooltips_set_tip(tooltips, checkbox6, + _("Replaces the search text in all opened files. This option is only useful(and used) if you click on "Replace All"."), NULL); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox6), FALSE); + + align = gtk_alignment_new(0, 0, 1, 1); + gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 9, 0, 0); + gtk_container_add(GTK_CONTAINER(align), checkbox6); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(widgets.replace_dialog)->vbox), align); + + gtk_widget_show_all(widgets.replace_dialog); + } + else + { + if (sel) gtk_entry_set_text(GTK_ENTRY(GTK_BIN( + lookup_widget(widgets.replace_dialog, "entry_find"))->child), sel); + gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(widgets.replace_dialog, "entry_find"))->child)); + gtk_widget_show(widgets.replace_dialog); + } + g_free(sel); +} + + +void search_show_find_in_files_dialog() +{ + static GtkWidget *combo = NULL; + static GtkWidget *entry1; + GtkWidget *entry2; // the child GtkEntry of combo + gint idx = document_get_cur_idx(); + gchar *sel = NULL; + gchar *cur_dir; + + if (idx == -1 || ! doc_list[idx].is_valid) return; + + cur_dir = utils_get_current_file_dir(); + + if (widgets.find_in_files_dialog == NULL) + { + GtkWidget *label, *label1, *checkbox1, *checkbox2, *checkbox3, *vbox2, *vbox1; + GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips")); + + widgets.find_in_files_dialog = gtk_dialog_new_with_buttons( + _("Find in files"), GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + + gtk_dialog_add_button(GTK_DIALOG(widgets.find_in_files_dialog), "gtk-find", GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response(GTK_DIALOG(widgets.find_in_files_dialog), + GTK_RESPONSE_ACCEPT); + + label1 = gtk_label_new("Directory to be searched:"); + gtk_misc_set_alignment(GTK_MISC(label1), 0, 0); + + entry1 = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry1), 248); + gtk_entry_set_width_chars(GTK_ENTRY(entry1), 50); + g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "entry_dir", + gtk_widget_ref(entry1), (GDestroyNotify)gtk_widget_unref); + + vbox1 = gtk_vbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox1), label1, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox1), entry1, FALSE, FALSE, 0); + + label = gtk_label_new(_("Enter the search text here:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + + combo = gtk_combo_box_entry_new_text(); + entry2 = gtk_bin_get_child(GTK_BIN(combo)); + gtk_entry_set_max_length(GTK_ENTRY(entry2), 248); + gtk_entry_set_width_chars(GTK_ENTRY(entry2), 50); + gtk_entry_set_activates_default(GTK_ENTRY(entry2), TRUE); + + checkbox1 = gtk_check_button_new_with_mnemonic(_("_Case sensitive")); + g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "check_case", + gtk_widget_ref(checkbox1), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox1), FALSE); + + checkbox2 = gtk_check_button_new_with_mnemonic(_("Invert search results")); + g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "check_invert", + gtk_widget_ref(checkbox2), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox2), FALSE); + gtk_tooltips_set_tip(tooltips, checkbox2, + _("Invert the sense of matching, to select non-matching lines."), NULL); + + checkbox3 = gtk_check_button_new_with_mnemonic(_("_Use extended regular expressions")); + g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "check_eregexp", + gtk_widget_ref(checkbox3), (GDestroyNotify)gtk_widget_unref); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox3), FALSE); + gtk_tooltips_set_tip(tooltips, checkbox3, + _("See grep's manual page for more information."), NULL); + + vbox2 = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox2), checkbox1); + gtk_container_add(GTK_CONTAINER(vbox2), checkbox2); + gtk_container_add(GTK_CONTAINER(vbox2), checkbox3); + + g_signal_connect((gpointer) widgets.find_in_files_dialog, "response", + G_CALLBACK(on_find_in_files_dialog_response), combo); + g_signal_connect((gpointer) widgets.find_in_files_dialog, "delete_event", + G_CALLBACK(gtk_widget_hide), NULL); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.find_in_files_dialog)->vbox), + vbox1, TRUE, TRUE, 6); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.find_in_files_dialog)->vbox), + label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.find_in_files_dialog)->vbox), + combo, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(widgets.find_in_files_dialog)->vbox), + vbox2, TRUE, TRUE, 6); + + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(widgets.find_in_files_dialog)->vbox), 6); + + gtk_widget_show_all(widgets.find_in_files_dialog); + } + + if (sci_get_lines_selected(doc_list[idx].sci) == 1) + { + sel = g_malloc(sci_get_selected_text_length(doc_list[idx].sci)); + sci_get_selected_text(doc_list[idx].sci, sel); + } + + entry2 = GTK_BIN(combo)->child; + if (sel) gtk_entry_set_text(GTK_ENTRY(entry2), sel); + g_free(sel); + + if (cur_dir) gtk_entry_set_text(GTK_ENTRY(entry1), cur_dir); + g_free(cur_dir); + + // put the focus to the directory entry if it is empty + if (utils_strcmp(gtk_entry_get_text(GTK_ENTRY(entry1)), "")) + gtk_widget_grab_focus(entry1); + else + gtk_widget_grab_focus(entry2); + + gtk_widget_show(widgets.find_in_files_dialog); +} + + +static void +on_find_replace_checkbutton_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + GtkWidget *dialog = GTK_WIDGET(user_data); + GtkToggleButton *chk_regexp = GTK_TOGGLE_BUTTON( + lookup_widget(dialog, "check_regexp")); + + if (togglebutton == chk_regexp) + { + gboolean regex_set = gtk_toggle_button_get_active(chk_regexp); + GtkWidget *check_back = lookup_widget(dialog, "check_back"); + GtkWidget *check_word = lookup_widget(dialog, "check_word"); + GtkWidget *check_wordstart = lookup_widget(dialog, "check_wordstart"); + + gtk_widget_set_sensitive(check_back, ! regex_set); + gtk_widget_set_sensitive(check_word, ! regex_set); + gtk_widget_set_sensitive(check_wordstart, ! regex_set); + } +} + + +static void +on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) +{ + if (response == GTK_RESPONSE_ACCEPT) + { + gint idx = document_get_cur_idx(); + gboolean search_replace_escape; + gboolean + fl1 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_case"))), + fl2 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_word"))), + fl3 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_regexp"))), + fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_wordstart"))); + search_replace_escape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_escape"))); + search_data.backwards = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_back"))); + + g_free(search_data.text); + search_data.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data))))); + if (strlen(search_data.text) == 0 || + (search_replace_escape && ! utils_str_replace_escape(search_data.text))) + { + utils_beep(); + gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(widgets.find_dialog, "entry"))->child)); + return; + } + + gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), search_data.text); + search_data.flags = (fl1 ? SCFIND_MATCHCASE : 0) | + (fl2 ? SCFIND_WHOLEWORD : 0) | + (fl3 ? SCFIND_REGEXP | SCFIND_POSIX: 0) | + (fl4 ? SCFIND_WORDSTART : 0); + document_find_text(idx, search_data.text, search_data.flags, search_data.backwards); + } + else gtk_widget_hide(widgets.find_dialog); +} + + +static void +on_find_entry_activate(GtkEntry *entry, gpointer user_data) +{ + on_find_dialog_response(NULL, GTK_RESPONSE_ACCEPT, + lookup_widget(GTK_WIDGET(entry), "entry")); +} + + +static void +on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) +{ + gint idx = document_get_cur_idx(); + GtkWidget *entry_find = lookup_widget(GTK_WIDGET(widgets.replace_dialog), "entry_find"); + GtkWidget *entry_replace = lookup_widget(GTK_WIDGET(widgets.replace_dialog), "entry_replace"); + gint search_flags_re; + gboolean search_backwards_re, search_replace_escape_re, search_in_all_buffers_re; + gboolean fl1, fl2, fl3, fl4; + gchar *find, *replace; + + if (response == GTK_RESPONSE_CANCEL) + { + gtk_widget_hide(widgets.replace_dialog); + return; + } + + fl1 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_case"))); + fl2 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_word"))); + fl3 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_regexp"))); + fl4 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_wordstart"))); + search_backwards_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_back"))); + search_replace_escape_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_escape"))); + search_in_all_buffers_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(GTK_WIDGET(widgets.replace_dialog), "check_all_buffers"))); + find = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find))))); + replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))))); + + if ((response != GEANY_RESPONSE_FIND) && (! fl1) && (strcasecmp(find, replace) == 0)) + { + utils_beep(); + gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(widgets.replace_dialog, "entry_find"))->child)); + return; + } + + gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_find), find); + gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_replace), replace); + + if (search_replace_escape_re && + (! utils_str_replace_escape(find) || ! utils_str_replace_escape(replace))) + { + utils_beep(); + gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(widgets.replace_dialog, "entry_find"))->child)); + return; + } + + search_flags_re = (fl1 ? SCFIND_MATCHCASE : 0) | + (fl2 ? SCFIND_WHOLEWORD : 0) | + (fl3 ? SCFIND_REGEXP | SCFIND_POSIX : 0) | + (fl4 ? SCFIND_WORDSTART : 0); + + if (search_in_all_buffers_re && response == GEANY_RESPONSE_REPLACE_ALL) + { + gint i; + for (i = 0; i < GEANY_MAX_OPEN_FILES; i++) + { + if (! doc_list[i].is_valid) continue; + + document_replace_all(i, find, replace, search_flags_re); + } + gtk_widget_hide(widgets.replace_dialog); + } + else + { + switch (response) + { + case GEANY_RESPONSE_REPLACE: + { + document_replace_text(idx, find, replace, search_flags_re, + 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); + gtk_widget_hide(widgets.replace_dialog); + break; + } + case GEANY_RESPONSE_REPLACE_SEL: + { + document_replace_sel(idx, find, replace, search_flags_re); + gtk_widget_hide(widgets.replace_dialog); + break; + } + } + } + g_free(find); + g_free(replace); +} + + +static void +on_replace_entry_activate(GtkEntry *entry, gpointer user_data) +{ + on_replace_dialog_response(NULL, GEANY_RESPONSE_REPLACE, NULL); +} + + +static void +on_find_in_files_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) +{ + if (response == GTK_RESPONSE_ACCEPT) + { + const gchar *search_text = + gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))); + const gchar *utf8_dir = + gtk_entry_get_text(GTK_ENTRY(lookup_widget(widgets.find_in_files_dialog, "entry_dir"))); + + if (utf8_dir == NULL || utils_strcmp(utf8_dir, "")) + msgwin_status_add(_("Invalid directory for find in files.")); + else if (search_text && *search_text) + { + gchar *locale_dir; + gboolean eregexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(widgets.find_in_files_dialog, "check_eregexp"))); + gboolean invert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(widgets.find_in_files_dialog, "check_invert"))); + gboolean case_sens = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + lookup_widget(widgets.find_in_files_dialog, "check_case"))); + gint opts = (eregexp ? FIF_USE_EREGEXP : 0) | + (invert ? FIF_INVERT_MATCH : 0) | + (case_sens ? FIF_CASE_SENSITIVE : 0); + + locale_dir = g_locale_from_utf8(utf8_dir, -1, NULL, NULL, NULL); + if (locale_dir == NULL) locale_dir = g_strdup(utf8_dir); + + if (search_find_in_files(search_text, locale_dir, opts)) + { + gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), search_text); + gtk_widget_hide(widgets.find_in_files_dialog); + } + g_free(locale_dir); + } + else + msgwin_status_add(_("No text to find.")); + } + else + gtk_widget_hide(widgets.find_in_files_dialog); +} + + gboolean search_find_in_files(const gchar *search_text, const gchar *dir, fif_options opts) { gchar **argv_prefix;
Modified: trunk/src/search.h =================================================================== --- trunk/src/search.h 2006-08-11 18:16:28 UTC (rev 697) +++ trunk/src/search.h 2006-08-11 21:12:49 UTC (rev 698) @@ -28,6 +28,26 @@ FIF_INVERT_MATCH = 1 << 2 } fif_options;
+// the flags given in the search dialog(stored statically for "find next" and "replace") +typedef struct +{ + gchar *text; + gint flags; + gboolean backwards; +} GeanySearchData;
+extern GeanySearchData search_data; + + +void search_init(); + +void search_finalise(); + +void search_show_find_dialog(); + +void search_show_replace_dialog(); + +void search_show_find_in_files_dialog(); + gboolean search_find_in_files(const gchar *search_text, const gchar *dir, fif_options opts);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.