[gnome-builder] libide: add IdeSourceView:enable-word-completion gproperty



commit 5067ff9514936d373d9d1ced9af649a8a461e4e5
Author: Christian Hergert <christian hergert me>
Date:   Tue Mar 10 15:20:12 2015 -0700

    libide: add IdeSourceView:enable-word-completion gproperty
    
    Setting this property to TRUE will enable autocompletion using words
    contained in any loaded buffer.

 libide/ide-source-view.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-source-view.h |    3 ++
 2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index e0d918f..139e575 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -26,6 +26,7 @@
 #include "ide-back-forward-list.h"
 #include "ide-box-theatric.h"
 #include "ide-buffer.h"
+#include "ide-buffer-manager.h"
 #include "ide-context.h"
 #include "ide-debug.h"
 #include "ide-diagnostic.h"
@@ -119,6 +120,7 @@ typedef struct
 
   guint                        auto_indent : 1;
   guint                        completion_visible : 1;
+  guint                        enable_word_completion : 1;
   guint                        insert_matching_brace : 1;
   guint                        overwrite_braces : 1;
   guint                        show_grid_lines : 1;
@@ -132,6 +134,7 @@ enum {
   PROP_0,
   PROP_AUTO_INDENT,
   PROP_BACK_FORWARD_LIST,
+  PROP_ENABLE_WORD_COMPLETION,
   PROP_FONT_NAME,
   PROP_FONT_DESC,
   PROP_INSERT_MATCHING_BRACE,
@@ -592,6 +595,37 @@ text_iter_get_line_prefix (const GtkTextIter *iter)
 }
 
 static void
+ide_source_view_reload_word_completion (IdeSourceView *self)
+{
+  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;
+      GtkSourceCompletion *completion;
+      GtkSourceCompletionWords *words;
+      GList *list;
+
+      bufmgr = ide_context_get_buffer_manager (context);
+      words = ide_buffer_manager_get_word_completion (bufmgr);
+      completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (self));
+      list = gtk_source_completion_get_providers (completion);
+
+      if (priv->enable_word_completion && !g_list_find (list, words))
+        gtk_source_completion_add_provider (completion,
+                                            GTK_SOURCE_COMPLETION_PROVIDER (words),
+                                            NULL);
+      else if (!priv->enable_word_completion && g_list_find (list, words))
+        gtk_source_completion_remove_provider (completion,
+                                               GTK_SOURCE_COMPLETION_PROVIDER (words),
+                                               NULL);
+    }
+}
+
+static void
 ide_source_view_reload_snippets (IdeSourceView *self)
 {
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
@@ -1051,6 +1085,7 @@ ide_source_view_connect_buffer (IdeSourceView *self,
   ide_source_view__buffer_notify_language_cb (self, NULL, buffer);
   ide_source_view__buffer_notify_file_cb (self, NULL, buffer);
   ide_source_view__buffer_notify_highlight_diagnostics_cb (self, NULL, buffer);
+  ide_source_view_reload_word_completion (self);
 
   if (priv->mode && ide_source_view_mode_get_coalesce_undo (priv->mode))
     BEGIN_USER_ACTION (self);
@@ -2826,6 +2861,10 @@ ide_source_view_get_property (GObject    *object,
       g_value_set_boolean (value, priv->auto_indent);
       break;
 
+    case PROP_ENABLE_WORD_COMPLETION:
+      g_value_set_boolean (value, ide_source_view_get_enable_word_completion (self));
+      break;
+
     case PROP_FONT_DESC:
       g_value_set_boxed (value, ide_source_view_get_font_desc (self));
       break;
@@ -2875,6 +2914,10 @@ ide_source_view_set_property (GObject      *object,
       ide_source_view_reload_indenter (self);
       break;
 
+    case PROP_ENABLE_WORD_COMPLETION:
+      ide_source_view_set_enable_word_completion (self, g_value_get_boolean (value));
+      break;
+
     case PROP_FONT_NAME:
       ide_source_view_set_font_name (self, g_value_get_string (value));
       break;
@@ -2971,6 +3014,15 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   g_object_class_install_property (object_class, PROP_FONT_DESC,
                                    gParamSpecs [PROP_FONT_DESC]);
 
+  gParamSpecs [PROP_ENABLE_WORD_COMPLETION] =
+    g_param_spec_boolean ("enable-word-completion",
+                          _("Enable Word Completion"),
+                          _("If words from all buffers can be used to autocomplete"),
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_ENABLE_WORD_COMPLETION,
+                                   gParamSpecs [PROP_ENABLE_WORD_COMPLETION]);
+
   gParamSpecs [PROP_FONT_NAME] =
     g_param_spec_string ("font-name",
                          _("Font Name"),
@@ -4026,3 +4078,29 @@ ide_source_view_place_cursor_onscreen (IdeSourceView *self)
 
   return ide_source_view_move_mark_onscreen (self, insert);
 }
+
+gboolean
+ide_source_view_get_enable_word_completion (IdeSourceView *self)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_SOURCE_VIEW (self), FALSE);
+
+  return priv->enable_word_completion;
+}
+
+void
+ide_source_view_set_enable_word_completion (IdeSourceView *self,
+                                            gboolean       enable_word_completion)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SOURCE_VIEW (self));
+
+  if (priv->enable_word_completion != enable_word_completion)
+    {
+      priv->enable_word_completion = enable_word_completion;
+      ide_source_view_reload_word_completion (self);
+      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_ENABLE_WORD_COMPLETION]);
+    }
+}
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index a1a9178..9a20a63 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -254,6 +254,7 @@ struct _IdeSourceViewClass
 
 void                        ide_source_view_clear_snippets            (IdeSourceView              *self);
 IdeBackForwardList         *ide_source_view_get_back_forward_list     (IdeSourceView              *self);
+gboolean                    ide_source_view_get_enable_word_completion(IdeSourceView              *self);
 const PangoFontDescription *ide_source_view_get_font_desc             (IdeSourceView              *self);
 gboolean                    ide_source_view_get_insert_matching_brace (IdeSourceView              *self);
 gboolean                    ide_source_view_get_overwrite_braces      (IdeSourceView              *self);
@@ -265,6 +266,8 @@ GType                       ide_source_view_get_type                  (void);
 void                        ide_source_view_pop_snippet               (IdeSourceView              *self);
 void                        ide_source_view_push_snippet              (IdeSourceView              *self,
                                                                        IdeSourceSnippet           *snippet);
+void                        ide_source_view_set_enable_word_completion(IdeSourceView              *self,
+                                                                       gboolean                    
enable_word_copletion);
 void                        ide_source_view_set_font_desc             (IdeSourceView              *self,
                                                                        const PangoFontDescription 
*font_desc);
 void                        ide_source_view_set_font_name             (IdeSourceView              *self,


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