diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c index 8911b5a..a4ff068 100644 --- a/mousepad/mousepad-replace-dialog.c +++ b/mousepad/mousepad-replace-dialog.c @@ -651,3 +651,11 @@ mousepad_replace_dialog_page_switched (MousepadReplaceDialog *dialog) { mousepad_replace_dialog_changed (dialog); } + + + +void +mousepad_replace_dialog_set_text (MousepadReplaceDialog *dialog, gchar *text) +{ + gtk_entry_set_text (GTK_ENTRY (dialog->search_entry), text); +} diff --git a/mousepad/mousepad-replace-dialog.h b/mousepad/mousepad-replace-dialog.h index b3e7d2f..15db2ce 100644 --- a/mousepad/mousepad-replace-dialog.h +++ b/mousepad/mousepad-replace-dialog.h @@ -37,6 +37,8 @@ void mousepad_replace_dialog_history_clean (void); void mousepad_replace_dialog_page_switched (MousepadReplaceDialog *dialog); +void mousepad_replace_dialog_set_text (MousepadReplaceDialog *dialog, gchar *text); + G_END_DECLS #endif /* !__MOUSEPAD_REPLACE_DIALOG_H__ */ diff --git a/mousepad/mousepad-search-bar.c b/mousepad/mousepad-search-bar.c index ab97fec..2c608a1 100644 --- a/mousepad/mousepad-search-bar.c +++ b/mousepad/mousepad-search-bar.c @@ -534,3 +534,13 @@ mousepad_search_bar_find_previous (MousepadSearchBar *bar) /* search */ mousepad_search_bar_find_string (bar, flags); } + + + +void +mousepad_search_bar_set_text (MousepadSearchBar *bar, gchar *text) +{ + mousepad_return_if_fail (MOUSEPAD_IS_SEARCH_BAR (bar)); + + gtk_entry_set_text (GTK_ENTRY (bar->entry), text); +} diff --git a/mousepad/mousepad-search-bar.h b/mousepad/mousepad-search-bar.h index 4dbfe11..d2ea0e3 100644 --- a/mousepad/mousepad-search-bar.h +++ b/mousepad/mousepad-search-bar.h @@ -41,6 +41,8 @@ void mousepad_search_bar_find_next (MousepadSearchBar *bar); void mousepad_search_bar_find_previous (MousepadSearchBar *bar); +void mousepad_search_bar_set_text (MousepadSearchBar *bar, gchar *text); + G_END_DECLS #endif /* !__MOUSEPAD_SEARCH_BAR_H__ */ diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index b789d71..386f106 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -4299,6 +4299,10 @@ static void mousepad_window_action_find (GtkAction *action, MousepadWindow *window) { + GtkTextIter selection_start; + GtkTextIter selection_end; + gchar *selection; + mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window)); mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); @@ -4314,6 +4318,22 @@ mousepad_window_action_find (GtkAction *action, g_signal_connect_swapped (G_OBJECT (window->search_bar), "search", G_CALLBACK (mousepad_window_search), window); } + /* set the search entry text if the search bar is hidden*/ + if (GTK_WIDGET_VISIBLE (window->search_bar) == FALSE) + { + if (gtk_text_buffer_get_has_selection (window->active->buffer) == TRUE) + { + gtk_text_buffer_get_selection_bounds (window->active->buffer, &selection_start, &selection_end); + selection = gtk_text_buffer_get_text (window->active->buffer, &selection_start, &selection_end, 0); + + /* selection should be one line */ + if (g_strrstr (selection, "\n") == NULL && g_strrstr (selection, "\r") == NULL) + mousepad_search_bar_set_text (MOUSEPAD_SEARCH_BAR (window->search_bar), selection); + + g_free (selection); + } + } + /* show the search bar */ gtk_widget_show (window->search_bar); @@ -4379,6 +4399,10 @@ static void mousepad_window_action_replace (GtkAction *action, MousepadWindow *window) { + GtkTextIter selection_start; + GtkTextIter selection_end; + gchar *selection; + mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window)); mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active)); @@ -4392,6 +4416,19 @@ mousepad_window_action_replace (GtkAction *action, gtk_window_set_transient_for (GTK_WINDOW (window->replace_dialog), GTK_WINDOW (window)); gtk_widget_show (window->replace_dialog); + /* set the search entry text */ + if (gtk_text_buffer_get_has_selection (window->active->buffer) == TRUE) + { + gtk_text_buffer_get_selection_bounds (window->active->buffer, &selection_start, &selection_end); + selection = gtk_text_buffer_get_text (window->active->buffer, &selection_start, &selection_end, 0); + + /* selection should be one line */ + if (g_strrstr(selection, "\n") == NULL && g_strrstr(selection, "\r") == NULL) + mousepad_replace_dialog_set_text (MOUSEPAD_REPLACE_DIALOG (window->replace_dialog), selection); + + g_free (selection); + } + /* connect signals */ g_signal_connect_swapped (G_OBJECT (window->replace_dialog), "destroy", G_CALLBACK (mousepad_window_action_replace_destroy), window); g_signal_connect_swapped (G_OBJECT (window->replace_dialog), "search", G_CALLBACK (mousepad_window_search), window);