[gnome-builder/wip/completion-words: 1/2] editor: add GtkSourceCompletionWords.



commit 3577b4079d002f3f52cb98113384937b7c3404c1
Author: Christian Hergert <christian hergert me>
Date:   Fri Oct 10 16:45:54 2014 -0700

    editor: add GtkSourceCompletionWords.
    
    This allows you to auto-complete words that are currently in the
    document.
    
    We still need a toggle switch to enable if we want this feature. We
    probably want it to be able to be turned on globally, and disabled
    on a per-language basis.

 src/editor/gb-editor-tab-private.h |    3 ++-
 src/editor/gb-editor-tab.c         |    8 ++++++++
 src/resources/ui/gb-editor-tab.ui  |    2 ++
 3 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 8850211..0bba888 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -48,9 +48,10 @@ struct _GbEditorTabPrivate
   GbEditorDocument *document;
 
   /*
-   * Snippet related components.
+   * Variants completion providers.
    */
   GtkSourceCompletionProvider *snippets_provider;
+  GtkSourceCompletionProvider *words_provider;
 
   /*
    * Search releated components.
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 99e3967..b76e735 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -19,6 +19,7 @@
 #define G_LOG_DOMAIN "editor"
 
 #include <glib/gi18n.h>
+#include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h>
 
 #include "gb-editor-file-mark.h"
 #include "gb-editor-file-marks.h"
@@ -1173,8 +1174,13 @@ gb_editor_tab_constructed (GObject *object)
                             G_CALLBACK (on_search_occurrences_notify),
                             tab);
 
+  gtk_source_completion_words_register (
+      GTK_SOURCE_COMPLETION_WORDS (priv->words_provider),
+      GTK_TEXT_BUFFER (priv->document));
+
   comp = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->source_view));
   gtk_source_completion_add_provider (comp, priv->snippets_provider, NULL);
+  gtk_source_completion_add_provider (comp, priv->words_provider, NULL);
 
   /*
    * WORKAROUND:
@@ -1546,6 +1552,8 @@ gb_editor_tab_class_init (GbEditorTabClass *klass)
                                                 snippets_provider);
   gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
                                                 source_view);
+  gtk_widget_class_bind_template_child_private (widget_class, GbEditorTab,
+                                                words_provider);
 
   g_type_ensure (GB_TYPE_EDITOR_DOCUMENT);
   g_type_ensure (GB_TYPE_SOURCE_CHANGE_MONITOR);
diff --git a/src/resources/ui/gb-editor-tab.ui b/src/resources/ui/gb-editor-tab.ui
index fdf08ad..9f981a4 100644
--- a/src/resources/ui/gb-editor-tab.ui
+++ b/src/resources/ui/gb-editor-tab.ui
@@ -130,6 +130,8 @@
   <object class="GbSourceSnippetCompletionProvider" id="snippets_provider">
     <property name="source-view">source_view</property>
   </object>
+  <object class="GtkSourceCompletionWords" id="words_provider">
+  </object>
   <object class="GtkSourceSearchSettings" id="search_settings">
   </object>
   <object class="GtkSourceSearchContext" id="search_context">


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