[gnome-builder/wip/uajain/word-completion: 4/4] sourceview: Add begin-word-completion signal



commit 12b62037bcd00b4a452391f8a73b5595e55f8c75
Author: Umang Jain <mailumangjain gmail com>
Date:   Tue Aug 29 21:47:18 2017 +0530

    sourceview: Add begin-word-completion signal

 data/keybindings/vim.css            |    4 +-
 libide/sourceview/ide-source-view.c |   46 +++++++++++++++++++++++++++++++++++
 libide/sourceview/ide-source-view.h |    2 +
 3 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 826bf21..55ec239 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -1900,8 +1900,8 @@
                    "delete-selection" () };
   bind "<ctrl>w" { "movement" (previous-word-start, 1, 1, 0)
                    "delete-selection" () };
-  bind "<ctrl>n" { "cycle-completion" (down) };
-  bind "<ctrl>p" { "cycle-completion" (up) };
+  bind "<ctrl>n" { "begin-word-completion" (1) };
+  bind "<ctrl>p" { "begin-word-completion" (-1) };
 
   bind "<ctrl>e" { "movement" (screen-up, 0, 0, 1) };
   bind "<ctrl>y" { "movement" (screen-down, 0, 0, 1) };
diff --git a/libide/sourceview/ide-source-view.c b/libide/sourceview/ide-source-view.c
index e8fb9b0..339157e 100644
--- a/libide/sourceview/ide-source-view.c
+++ b/libide/sourceview/ide-source-view.c
@@ -243,6 +243,7 @@ enum {
   BEGIN_MACRO,
   BEGIN_RENAME,
   BEGIN_USER_ACTION,
+  BEGIN_WORD_COMPLETION,
   CAPTURE_MODIFIER,
   CLEAR_COUNT,
   CLEAR_MODIFIER,
@@ -5018,6 +5019,33 @@ ide_source_view_focus_out_event (GtkWidget     *widget,
 }
 
 static void
+ide_source_view_real_begin_word_completion (IdeSourceView *self,
+                                            gint           direction)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+  IdeContext *context;
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  if ((priv->buffer != NULL) && (context = ide_buffer_get_context (priv->buffer)))
+    {
+      IdeBufferManager *bufmgr;
+      IdeWordCompletionProvider *words;
+      GValue *value;
+
+      bufmgr = ide_context_get_buffer_manager (context);
+      words = ide_buffer_manager_get_word_completion (bufmgr);
+
+      value = g_new0(GValue, 1);
+      g_value_init (value, G_TYPE_INT);
+      g_value_set_int (value, direction);
+      g_object_set_property (G_OBJECT(words), "direction", value);
+
+      g_signal_emit_by_name (self, "show-completion");
+    }
+}
+
+static void
 ide_source_view_real_begin_macro (IdeSourceView *self)
 {
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
@@ -6488,6 +6516,7 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   klass->remove_cursors = ide_source_view_real_remove_cursors;
   klass->append_to_count = ide_source_view_real_append_to_count;
   klass->begin_macro = ide_source_view_real_begin_macro;
+  klass->begin_word_completion = ide_source_view_real_begin_word_completion;
   klass->begin_rename = ide_source_view_real_begin_rename;
   klass->capture_modifier = ide_source_view_real_capture_modifier;
   klass->clear_count = ide_source_view_real_clear_count;
@@ -6765,6 +6794,23 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
                   G_STRUCT_OFFSET (IdeSourceViewClass, begin_rename),
                   NULL, NULL, NULL, G_TYPE_NONE, 0);
 
+ /**
+   * IdeSourceView::begin-word-completion:
+   *
+   * This signal is emitted when the user requests word completion using
+   * Ctrl-n for forward matches and Ctrl-p for backward matches as happens
+   * in Vim.
+   */
+  signals [BEGIN_WORD_COMPLETION] =
+    g_signal_new ("begin-word-completion",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (IdeSourceViewClass, begin_word_completion),
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_INT);
+
   signals [BEGIN_USER_ACTION] =
     g_signal_new_class_handler ("begin-user-action",
                                 G_TYPE_FROM_CLASS (klass),
diff --git a/libide/sourceview/ide-source-view.h b/libide/sourceview/ide-source-view.h
index 8b66765..c4c95ec 100644
--- a/libide/sourceview/ide-source-view.h
+++ b/libide/sourceview/ide-source-view.h
@@ -223,6 +223,8 @@ struct _IdeSourceViewClass
                                        gint                     digit);
   void (*auto_indent)                 (IdeSourceView           *self);
   void (*begin_macro)                 (IdeSourceView           *self);
+  void (*begin_word_completion)       (IdeSourceView           *self,
+                                       gint                     direction);
   void (*capture_modifier)            (IdeSourceView           *self);
   void (*clear_count)                 (IdeSourceView           *self);
   void (*clear_modifier)              (IdeSourceView           *self);


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