[gnome-builder] editor: update search text from find action



commit 9a06540fe06fdd88e178102ca21d5e4308aeb3a5
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 24 18:17:51 2017 -0700

    editor: update search text from find action

 libide/editor/ide-editor-search-bar.c   |   13 +++++++++++++
 libide/editor/ide-editor-search-bar.h   |    2 ++
 libide/editor/ide-editor-view-actions.c |    8 ++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/libide/editor/ide-editor-search-bar.c b/libide/editor/ide-editor-search-bar.c
index cb4f5af..0673cfd 100644
--- a/libide/editor/ide-editor-search-bar.c
+++ b/libide/editor/ide-editor-search-bar.c
@@ -778,3 +778,16 @@ ide_editor_search_bar_set_context (IdeEditorSearchBar     *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CONTEXT]);
     }
 }
+
+void
+ide_editor_search_bar_set_search_text (IdeEditorSearchBar *self,
+                                       const gchar        *search_text)
+{
+  g_return_if_fail (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+  if (search_text == NULL)
+    search_text = "";
+
+  if (self->settings != NULL)
+    gtk_source_search_settings_set_search_text (self->settings, search_text);
+}
diff --git a/libide/editor/ide-editor-search-bar.h b/libide/editor/ide-editor-search-bar.h
index e727cd3..28360cb 100644
--- a/libide/editor/ide-editor-search-bar.h
+++ b/libide/editor/ide-editor-search-bar.h
@@ -30,6 +30,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (IdeEditorSearchBar, ide_editor_search_bar, IDE, EDITOR_SEARCH_BAR, DzlBin)
 
 GtkWidget *ide_editor_search_bar_new              (void);
+void       ide_editor_search_bar_set_search_text  (IdeEditorSearchBar      *self,
+                                                   const gchar             *word);
 void       ide_editor_search_bar_set_replace_mode (IdeEditorSearchBar      *self,
                                                    gboolean                 replace_mode);
 void       ide_editor_search_bar_set_context      (IdeEditorSearchBar      *self,
diff --git a/libide/editor/ide-editor-view-actions.c b/libide/editor/ide-editor-view-actions.c
index 7648c19..3e0f68d 100644
--- a/libide/editor/ide-editor-view-actions.c
+++ b/libide/editor/ide-editor-view-actions.c
@@ -395,10 +395,18 @@ ide_editor_view_actions_find (GSimpleAction *action,
                               gpointer       user_data)
 {
   IdeEditorView *self = user_data;
+  GtkTextIter begin;
+  GtkTextIter end;
 
   g_assert (G_IS_SIMPLE_ACTION (action));
   g_assert (IDE_IS_EDITOR_VIEW (self));
 
+  if (gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (self->buffer), &begin, &end))
+    {
+      g_autofree gchar *word = gtk_text_iter_get_slice (&begin, &end);
+      ide_editor_search_bar_set_search_text (self->search_bar, word);
+    }
+
   ide_editor_search_bar_set_replace_mode (self->search_bar, FALSE);
   gtk_revealer_set_reveal_child (self->search_revealer, TRUE);
   gtk_widget_grab_focus (GTK_WIDGET (self->search_bar));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]