#include "main.h" GtkWidget *search_dialog = NULL; GtkWidget *entry_srch, *entry_repl, *chk_ef, *chk_ci;; gchar *needle = NULL, *replace = NULL; gboolean case_insensitive, entire_file, first_find_click = TRUE, first_replace_click = TRUE; gint row; /* Performs the actual search. * clist: the clist to search * needle: the string to find * row: row to search from * * returns: -1 on error (not found) otherwise the row where 'needle' was found */ gint gse_srch_search_clist (GtkWidget *clist, gchar *needle, gint row) { gint i; gchar *haystack; for (i = row; i < GTK_CLIST (clist)->rows; i++) { gtk_clist_get_text (GTK_CLIST (clist), i, 3, &haystack); if (strstr (haystack, needle)) return i; } return -1; } void gse_srch_close_dialog (GtkWidget *btn, gpointer data) { g_free (needle); g_free (replace); gnome_dialog_close (GNOME_DIALOG (search_dialog)); search_dialog = NULL; needle = replace = NULL; first_find_click = first_replace_click = TRUE; } void gse_srch_btn_find_clicked (GtkWidget *btn, gpointer data) { if (first_find_click) { needle = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_srch))); entire_file = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chk_ef)); first_find_click = FALSE; if (entire_file) row = -1; else row = (gint) GTK_CLIST (mwin_clist)->selection->data - 1; } row = gse_srch_search_clist (mwin_clist, needle, row + 1); if (row != -1) { gtk_clist_select_row (GTK_CLIST (mwin_clist), row, 0); gtk_clist_moveto (GTK_CLIST (mwin_clist), row, 0, 0.5, 0); } else { gnome_dialog_run_and_close (GNOME_DIALOG (gnome_message_box_new (_("Search string not found"), GNOME_MESSAGE_BOX_INFO, GNOME_STOCK_BUTTON_OK, NULL))); gse_srch_close_dialog (NULL, NULL); } } void gse_srch_btn_replace_clicked (GtkWidget *btn, gpointer data) { gchar *haystack, *tmp_str; GString *new_str; gboolean not_found_first = FALSE; if (first_replace_click) { if (!needle) { gtk_button_clicked (GTK_BUTTON (g_list_nth_data (GNOME_DIALOG (search_dialog)->buttons, 0))); not_found_first = TRUE; if (row == -1) return; } replace = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry_repl))); first_replace_click = FALSE; } else if (row == -1) return; gtk_clist_get_text (GTK_CLIST (mwin_clist), row, 3, &haystack); new_str = g_string_new (""); while (strstr (haystack, needle)) { tmp_str = g_strdup (haystack); *(strstr (tmp_str, needle)) = '\0'; haystack = strstr (haystack, needle) + strlen (needle); g_string_append (new_str, tmp_str); g_string_append (new_str, replace); g_free (tmp_str); } g_string_append (new_str, haystack); tmp_str = new_str->str; gtk_clist_set_text (GTK_CLIST (mwin_clist), row, 3, tmp_str); g_string_free (new_str, TRUE); cur_open_file.changed = TRUE; gse_set_title_changed (TRUE); /* Automaticly search for the next string */ if (not_found_first == FALSE) gtk_button_clicked (GTK_BUTTON (g_list_nth_data (GNOME_DIALOG (search_dialog)->buttons, 0))); } void gse_srch_show_replace_dialog (GtkWidget *wgt, gpointer data) { GtkWidget *lbl, *gnome_entry, *hbox; if (gse_clist_is_empty (mwin_clist) || search_dialog) return; search_dialog = gnome_dialog_new (_("Replace"), _("Find next"), _("Replace"), GNOME_STOCK_BUTTON_CLOSE, NULL); if (main_window) gnome_dialog_set_parent (GNOME_DIALOG (search_dialog), GTK_WINDOW (main_window)); lbl = gtk_label_new (_("Search for:")); gnome_entry = gnome_entry_new (NULL); hbox = gtk_hbox_new (FALSE, 5); gtk_widget_show (lbl); gtk_widget_show (gnome_entry); gtk_widget_show (hbox); gtk_box_pack_start (GTK_BOX (hbox), lbl, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), gnome_entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (search_dialog)->vbox), hbox, FALSE, FALSE, 5); entry_srch = gnome_entry_gtk_entry (GNOME_ENTRY (gnome_entry)); gtk_entry_set_max_length (GTK_ENTRY (entry_srch), BUF_LEN - 1); lbl = gtk_label_new (_("Replace with:")); gnome_entry = gnome_entry_new (NULL); hbox = gtk_hbox_new (FALSE, 5); gtk_widget_show (lbl); gtk_widget_show (gnome_entry); gtk_widget_show (hbox); gtk_box_pack_start (GTK_BOX (hbox), lbl, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), gnome_entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (search_dialog)->vbox), hbox, FALSE, FALSE, 5); entry_repl = gnome_entry_gtk_entry (GNOME_ENTRY (gnome_entry)); gtk_entry_set_max_length (GTK_ENTRY (entry_repl), BUF_LEN - 1); chk_ef = gtk_check_button_new_with_label (_("Entire file")); gtk_widget_show (chk_ef); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (search_dialog)->vbox), chk_ef, FALSE, FALSE, 5); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chk_ef), TRUE); gnome_dialog_editable_enters (GNOME_DIALOG (search_dialog), GTK_EDITABLE (entry_srch)); gnome_dialog_editable_enters (GNOME_DIALOG (search_dialog), GTK_EDITABLE (entry_repl)); gnome_dialog_set_default (GNOME_DIALOG (search_dialog), 0); gtk_widget_grab_focus (entry_srch); /* chk_ci = gtk_check_button_new_with_label (_("Case insensitive")); gtk_widget_show (chk_ci); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), chk_ci, FALSE, FALSE, 10); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chk_ci), TRUE);*/ gnome_dialog_button_connect (GNOME_DIALOG (search_dialog), 0, gse_srch_btn_find_clicked, NULL); gnome_dialog_button_connect (GNOME_DIALOG (search_dialog), 1, gse_srch_btn_replace_clicked, NULL); gnome_dialog_button_connect (GNOME_DIALOG (search_dialog), 2, gse_srch_close_dialog, NULL); gnome_dialog_run (GNOME_DIALOG (search_dialog)); } /* Asks the user for a searchstring and performs a search of the clist */ void gse_srch_show_find_dialog (GtkWidget *wgt, gpointer data) { GtkWidget *lbl, *hbox; if (gse_clist_is_empty (mwin_clist) || search_dialog); search_dialog = gnome_dialog_new (_("Find"), _("Find next"), GNOME_STOCK_BUTTON_CLOSE, NULL); if (main_window) gnome_dialog_set_parent (GNOME_DIALOG (search_dialog), GTK_WINDOW (main_window)); hbox = gtk_hbox_new (FALSE, 0); lbl = gtk_label_new (_("Search for:")); gtk_box_pack_start (GTK_BOX (hbox), lbl, FALSE, FALSE, 2); gtk_widget_show (lbl); entry_srch = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (hbox), entry_srch, FALSE, FALSE, 2); gnome_dialog_editable_enters (GNOME_DIALOG (search_dialog), GTK_EDITABLE (entry_srch)); gnome_dialog_set_default (GNOME_DIALOG (search_dialog), 0); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (search_dialog)->vbox), hbox, FALSE, FALSE, 2); gtk_widget_show (entry_srch); gtk_widget_show (hbox); gtk_widget_grab_focus (entry_srch); chk_ef = gtk_check_button_new_with_label (_("Entire file")); gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (search_dialog)->vbox), chk_ef, FALSE, FALSE, 5); gtk_widget_show (chk_ef); gnome_dialog_button_connect (GNOME_DIALOG (search_dialog), 0, gse_srch_btn_find_clicked, NULL); gnome_dialog_button_connect (GNOME_DIALOG (search_dialog), 1, gse_srch_close_dialog, NULL); gnome_dialog_run (GNOME_DIALOG (search_dialog)); }