diff --git a/src/search.c b/src/search.c index 07e29c7..d60d2f2 100644 --- a/src/search.c +++ b/src/search.c @@ -184,6 +184,9 @@ gint run_dialog_find(StructData *sd) GtkWidget *entry_find = NULL; GtkWidget *check_case; gint res; + GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(sd->mainwin->textview)); + GtkTextIter selection_start; + GtkTextIter selection_end; dialog = gtk_dialog_new_with_buttons(_("Find"), GTK_WINDOW(gtk_widget_get_toplevel(sd->mainwin->textview)), @@ -210,6 +213,10 @@ gint run_dialog_find(StructData *sd) G_CALLBACK(toggle_sensitivity), NULL); g_signal_connect(G_OBJECT(entry_find), "delete-text", G_CALLBACK(toggle_sensitivity), NULL); + if (gtk_text_buffer_get_has_selection(textbuffer) == TRUE) { + gtk_text_buffer_get_selection_bounds(textbuffer, &selection_start,&selection_end); + sd->search.string_find = gtk_text_buffer_get_text(textbuffer,&selection_start, &selection_end, 0); + } if (sd->search.string_find) gtk_entry_set_text(GTK_ENTRY(entry_find), sd->search.string_find); @@ -249,6 +256,9 @@ gint run_dialog_replace(StructData *sd) GtkWidget *entry_find, *entry_replace = NULL; GtkWidget *check_case, *check_all; gint res; + GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(sd->mainwin->textview)); + GtkTextIter selection_start; + GtkTextIter selection_end; dialog = gtk_dialog_new_with_buttons(_("Replace"), GTK_WINDOW(gtk_widget_get_toplevel(sd->mainwin->textview)), @@ -275,6 +285,10 @@ gint run_dialog_replace(StructData *sd) G_CALLBACK(toggle_sensitivity), NULL); g_signal_connect(G_OBJECT(entry_find), "delete-text", G_CALLBACK(toggle_sensitivity), NULL); + if (gtk_text_buffer_get_has_selection(textbuffer) == TRUE) { + gtk_text_buffer_get_selection_bounds(textbuffer, &selection_start,&selection_end); + sd->search.string_find = gtk_text_buffer_get_text(textbuffer,&selection_start, &selection_end, 0); + } if (sd->search.string_find) gtk_entry_set_text(GTK_ENTRY(entry_find), sd->search.string_find); label_replace = gtk_label_new_with_mnemonic(_("Re_place with: ")); @@ -283,6 +297,7 @@ gint run_dialog_replace(StructData *sd) entry_replace = gtk_entry_new(); gtk_table_attach_defaults(GTK_TABLE(table), entry_replace, 1, 2, 1, 2); gtk_label_set_mnemonic_widget(GTK_LABEL(label_replace), entry_replace); + if (sd->search.string_replace) gtk_entry_set_text(GTK_ENTRY(entry_replace), sd->search.string_replace);