[gnome-builder] vim: remove dependence on Builder for initiating search.



commit 0c89af6c04f246faff5e8fa543840da121978201
Author: Christian Hergert <christian hergert me>
Date:   Sun Oct 5 16:37:16 2014 -0700

    vim: remove dependence on Builder for initiating search.
    
    This allows the consuming code to hook to begin_search and show their
    own search dialog. Useful for consumers outside of Builder.

 src/editor/gb-editor-tab.c |   15 ++++++++++++++
 src/editor/gb-editor-vim.c |   45 ++++++++++++++++++++++++++++++++++++++-----
 src/editor/gb-editor-vim.h |   12 +++++++++++
 3 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 5729533..6db8b67 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -995,6 +995,17 @@ on_vim_command_visibility_toggled (GbEditorVim *vim,
 }
 
 static void
+on_vim_begin_search (GbEditorVim *vim,
+                     const gchar *search_text,
+                     GbEditorTab *tab)
+{
+  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+  gb_source_view_begin_search (tab->priv->source_view, GTK_DIR_DOWN,
+                               search_text);
+}
+
+static void
 on_vim_command_entry_activate (GtkEntry    *entry,
                                GbEditorTab *tab)
 {
@@ -1276,6 +1287,10 @@ gb_editor_tab_constructed (GObject *object)
                     G_CALLBACK (on_vim_command_visibility_toggled),
                     tab);
   g_signal_connect (priv->vim,
+                    "begin-search",
+                    G_CALLBACK (on_vim_begin_search),
+                    tab);
+  g_signal_connect (priv->vim,
                     "notify::phrase",
                     G_CALLBACK (on_vim_notify_phrase),
                     tab);
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index ee1d8ca..905f751 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -140,6 +140,7 @@ enum
 
 enum
 {
+  BEGIN_SEARCH,
   COMMAND_VISIBILITY_TOGGLED,
   LAST_SIGNAL
 };
@@ -2736,13 +2737,24 @@ gb_editor_vim_cmd_begin_search (GbEditorVim *vim,
                                 guint        count,
                                 gchar        modifier)
 {
-#ifndef GB_EDITOR_VIM_EXTERNAL
+  GtkTextBuffer *buffer;
+  GtkTextIter begin;
+  GtkTextIter end;
+  gchar *text = NULL;
+
   g_assert (GB_IS_EDITOR_VIM (vim));
 
-  if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
-    gb_source_view_begin_search (GB_SOURCE_VIEW (vim->priv->text_view),
-                                 GTK_DIR_DOWN, NULL);
-#endif
+  buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+
+  if (gtk_text_buffer_get_has_selection (buffer))
+    {
+      gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+      text = gtk_text_iter_get_slice (&begin, &end);
+    }
+
+  g_signal_emit (vim, gSignals [BEGIN_SEARCH], 0, text);
+
+  g_free (text);
 }
 
 static void
@@ -3394,6 +3406,26 @@ gb_editor_vim_class_init (GbEditorVimClass *klass)
                                    gParamSpecs [PROP_TEXT_VIEW]);
 
   /**
+   * GbEditorVim::begin-search:
+   * @search_text: (allow none): Optional search text to apply to the search.
+   *
+   * This signal is emitted when the `/` key is pressed. The consuming code
+   * should make their search entry widget visible and set the search text
+   * to @search_text if non-%NULL.
+   */
+  gSignals [BEGIN_SEARCH] =
+    g_signal_new ("begin-search",
+                  GB_TYPE_EDITOR_VIM,
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GbEditorVimClass, begin_search),
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_VOID__STRING,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_STRING);
+
+  /**
    * GbEditorVim::command-visibility-toggled:
    * @visible: If the the command entry should be visible.
    *
@@ -3405,7 +3437,8 @@ gb_editor_vim_class_init (GbEditorVimClass *klass)
     g_signal_new ("command-visibility-toggled",
                   GB_TYPE_EDITOR_VIM,
                   G_SIGNAL_RUN_LAST,
-                  0,
+                  G_STRUCT_OFFSET (GbEditorVimClass,
+                                   command_visibility_toggled),
                   NULL,
                   NULL,
                   g_cclosure_marshal_VOID__BOOLEAN,
diff --git a/src/editor/gb-editor-vim.h b/src/editor/gb-editor-vim.h
index 9036e3e..fd96400 100644
--- a/src/editor/gb-editor-vim.h
+++ b/src/editor/gb-editor-vim.h
@@ -54,6 +54,18 @@ struct _GbEditorVim
 struct _GbEditorVimClass
 {
   GObjectClass parent_class;
+
+  void (*begin_search)               (GbEditorVim *vim,
+                                      const gchar *search_text);
+  void (*command_visibility_toggled) (GbEditorVim *vim,
+                                      gboolean     visibility);
+
+  gpointer _padding1;
+  gpointer _padding2;
+  gpointer _padding3;
+  gpointer _padding4;
+  gpointer _padding5;
+  gpointer _padding6;
 };
 
 GType            gb_editor_vim_get_type        (void) G_GNUC_CONST;


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