[Xfce4-commits] [apps/mousepad] 01/03: Fill search textbox with the selected text
noreply at xfce.org
noreply at xfce.org
Sat Jul 12 04:26:02 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit 0e350fc12258f0d89a4e04520d13bb4f41e8e347
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Fri Jul 11 18:30:39 2014 -0700
Fill search textbox with the selected text
Closes #5905 (https://bugzilla.xfce.org/show_bug.cgi?id=5905)
Thanks to Carlos Ortiz for the original patch and André Miranda for
re-writing the patch for new Mousepad.
---
mousepad/mousepad-replace-dialog.c | 8 ++++++++
mousepad/mousepad-replace-dialog.h | 2 ++
mousepad/mousepad-search-bar.c | 10 ++++++++++
mousepad/mousepad-search-bar.h | 2 ++
mousepad/mousepad-window.c | 37 ++++++++++++++++++++++++++++++++++++
5 files changed, 59 insertions(+)
diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c
index 8bf568a..6426453 100644
--- a/mousepad/mousepad-replace-dialog.c
+++ b/mousepad/mousepad-replace-dialog.c
@@ -566,3 +566,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 917bb3c..75d8851 100644
--- a/mousepad/mousepad-search-bar.c
+++ b/mousepad/mousepad-search-bar.c
@@ -505,3 +505,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 1acc390..cf98a8e 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -4629,6 +4629,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));
@@ -4644,6 +4648,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);
@@ -4709,6 +4729,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));
@@ -4722,6 +4746,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);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list