[gnome-builder] editor: wire enable-word-completion to editor setting.



commit 736fbf1eb137e61c50ccf91e03f0f6731cfe8b40
Author: Christian Hergert <christian hergert me>
Date:   Sat Oct 11 15:46:02 2014 -0400

    editor: wire enable-word-completion to editor setting.
    
    This allows to enable/disable the word completion provider in the
    editor settings.

 src/editor/gb-editor-tab-private.h |    5 ++
 src/editor/gb-editor-tab.c         |   73 +++++++++++++++++++++++++++++++++---
 2 files changed, 72 insertions(+), 6 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 0bba888..b651125 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -118,6 +118,11 @@ struct _GbEditorTabPrivate
    * Animation for save progress.
    */
   GbAnimation *save_animation;
+
+  /*
+   * If we want to use word completion in this editor.
+   */
+  guint enable_word_completion : 1;
 };
 
 G_END_DECLS
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index b76e735..8a10b76 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -43,6 +43,7 @@
 enum {
   PROP_0,
   PROP_DOCUMENT,
+  PROP_ENABLE_WORD_COMPLETION,
   PROP_FILE,
   PROP_FONT_DESC,
   PROP_SETTINGS,
@@ -59,6 +60,42 @@ gb_editor_tab_new (void)
   return g_object_new (GB_TYPE_EDITOR_TAB, NULL);
 }
 
+gboolean
+gb_editor_tab_get_enable_word_completion (GbEditorTab *tab)
+{
+  g_return_val_if_fail (GB_IS_EDITOR_TAB (tab), FALSE);
+
+  return tab->priv->enable_word_completion;
+}
+
+void
+gb_editor_tab_set_enable_word_completion (GbEditorTab *tab,
+                                          gboolean     enable_word_completion)
+{
+  GtkSourceCompletion *completion;
+
+  g_return_val_if_fail (GB_IS_EDITOR_TAB (tab), FALSE);
+
+  completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (tab->priv->source_view));
+
+  if (enable_word_completion != tab->priv->enable_word_completion)
+    {
+      if (!enable_word_completion)
+        gtk_source_completion_remove_provider (
+            completion,
+            GTK_SOURCE_COMPLETION_PROVIDER (tab->priv->words_provider),
+            NULL);
+      else
+        gtk_source_completion_add_provider (
+            completion,
+            GTK_SOURCE_COMPLETION_PROVIDER (tab->priv->words_provider),
+            NULL);
+      tab->priv->enable_word_completion = enable_word_completion;
+      g_object_notify_by_pspec (G_OBJECT (tab),
+                                gParamSpecs [PROP_ENABLE_WORD_COMPLETION]);
+    }
+}
+
 /**
  * gb_editor_tab_get_is_default:
  * @tab: A #GbEditorTab.
@@ -1262,6 +1299,8 @@ gb_editor_tab_constructed (GObject *object)
   settings = g_settings_new ("org.gnome.builder.editor");
   g_settings_bind (settings, "vim-mode", priv->vim, "enabled",
                    G_SETTINGS_BIND_DEFAULT);
+  g_settings_bind (settings, "word-completion", tab, "enable-word-completion",
+                   G_SETTINGS_BIND_DEFAULT);
   g_object_unref (settings);
 
   gb_editor_tab_cursor_moved (tab, priv->document);
@@ -1422,6 +1461,11 @@ gb_editor_tab_get_property (GObject    *object,
       g_value_set_object (value, gb_editor_tab_get_document (tab));
       break;
 
+    case PROP_ENABLE_WORD_COMPLETION:
+      g_value_set_boolean (value,
+                           gb_editor_tab_get_enable_word_completion (tab));
+      break;
+
     case PROP_FILE:
       g_value_set_object (value, gb_editor_tab_get_file (tab));
       break;
@@ -1449,6 +1493,11 @@ gb_editor_tab_set_property (GObject      *object,
       gb_editor_tab_set_font_desc (tab, g_value_get_boxed (value));
       break;
 
+    case PROP_ENABLE_WORD_COMPLETION:
+      gb_editor_tab_set_enable_word_completion (tab,
+                                                g_value_get_boolean (value));
+      break;
+
     case PROP_SETTINGS:
       gb_editor_tab_set_settings (tab, g_value_get_object (value));
       break;
@@ -1487,13 +1536,23 @@ gb_editor_tab_class_init (GbEditorTabClass *klass)
   g_object_class_install_property (object_class, PROP_DOCUMENT,
                                    gParamSpecs[PROP_DOCUMENT]);
 
+  gParamSpecs [PROP_ENABLE_WORD_COMPLETION] =
+    g_param_spec_boolean ("enable-word-completion",
+                          _("Enable Word Completion"),
+                          _("Enable Word Completion"),
+                          TRUE,
+                          (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_FILE] =
-      g_param_spec_object ("file",
-                           _("File"),
-                           _("The file for the tab."),
-                           GTK_SOURCE_TYPE_FILE,
-                           (G_PARAM_READABLE |
-                            G_PARAM_STATIC_STRINGS));
+    g_param_spec_object ("file",
+                         _("File"),
+                         _("The file for the tab."),
+                         GTK_SOURCE_TYPE_FILE,
+                         (G_PARAM_READABLE |
+                          G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (object_class, PROP_FILE,
                                    gParamSpecs [PROP_FILE]);
 
@@ -1569,5 +1628,7 @@ gb_editor_tab_init (GbEditorTab *tab)
 {
   tab->priv = gb_editor_tab_get_instance_private (tab);
 
+  tab->priv->enable_word_completion = TRUE;
+
   gtk_widget_init_template (GTK_WIDGET (tab));
 }


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