[gnome-builder] snippets: allow enable/disabling of snippet autocompletion



commit 3087a29912b8ad68bb7add09ed1d37dd0c235cbc
Author: Christian Hergert <christian hergert me>
Date:   Sat Sep 12 17:26:59 2015 -0700

    snippets: allow enable/disabling of snippet autocompletion
    
    For those that find this distracting/annoying, allow a switch to disable
    the autocompletion of snippets.

 .../org.gnome.builder.code-insight.gschema.xml.in  |    5 +++
 data/ui/gb-preferences-page-insight.ui             |   10 +++++
 libide/ide-source-snippet-completion-provider.c    |   36 +++++++++++++++++++-
 3 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.code-insight.gschema.xml.in 
b/data/gsettings/org.gnome.builder.code-insight.gschema.xml.in
index 3a356f5..2f1eecf 100644
--- a/data/gsettings/org.gnome.builder.code-insight.gschema.xml.in
+++ b/data/gsettings/org.gnome.builder.code-insight.gschema.xml.in
@@ -1,5 +1,10 @@
 <schemalist>
   <schema id="org.gnome.builder.code-insight" path="/org/gnome/builder/code-insight/" 
gettext-domain="gnome-builder">
+    <key name="snippet-completion" type="b">
+      <default>true</default>
+      <summary>Suggest Snippet Completion</summary>
+      <description>Allow snippets to be inserted into the document.</description>
+    </key>
     <key name="clang-autocompletion" type="b">
       <default>false</default>
       <summary>Clang based autocompletion (Experimental)</summary>
diff --git a/data/ui/gb-preferences-page-insight.ui b/data/ui/gb-preferences-page-insight.ui
index 128d83e..fc767e6 100644
--- a/data/ui/gb-preferences-page-insight.ui
+++ b/data/ui/gb-preferences-page-insight.ui
@@ -34,6 +34,16 @@
           </object>
         </child>
         <child>
+          <object class="GbPreferencesSwitch" id="snippet_autocompletion">
+            <property name="title" translatable="yes">Suggest Snippet Completion</property>
+            <property name="description" translatable="yes">Allow snippets to be inserted into the 
document.</property>
+            <property name="settings">insight_settings</property>
+            <property name="settings-schema-key">snippet-completion</property>
+            <property name="size-group">control_group</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
           <object class="GbPreferencesSwitch" id="word_autocompletion">
             <property name="title" translatable="yes">Suggest Word Completion</property>
             <property name="description" translatable="yes">Suggest completion of words found within all 
open documents.</property>
diff --git a/libide/ide-source-snippet-completion-provider.c b/libide/ide-source-snippet-completion-provider.c
index 23c53ab..f5dc014 100644
--- a/libide/ide-source-snippet-completion-provider.c
+++ b/libide/ide-source-snippet-completion-provider.c
@@ -26,8 +26,11 @@ struct _IdeSourceSnippetCompletionProvider
 {
   GObject            parent_instance;
 
+  GSettings         *settings;
   IdeSourceView     *source_view;
   IdeSourceSnippets *snippets;
+
+  guint              enabled : 1;
 };
 
 
@@ -48,6 +51,7 @@ typedef struct
 
 enum {
   PROP_0,
+  PROP_ENABLED,
   PROP_SNIPPETS,
   PROP_SOURCE_VIEW,
   LAST_PROP
@@ -84,12 +88,24 @@ ide_source_snippet_completion_provider_set_snippets (IdeSourceSnippetCompletionP
   g_object_notify_by_pspec (G_OBJECT (provider), gParamSpecs[PROP_SNIPPETS]);
 }
 
+static gboolean
+ide_source_snippet_completion_provider_match (GtkSourceCompletionProvider *provider,
+                                              GtkSourceCompletionContext  *context)
+{
+  IdeSourceSnippetCompletionProvider *self = (IdeSourceSnippetCompletionProvider *)provider;
+
+  g_assert (IDE_IS_SOURCE_SNIPPET_COMPLETION_PROVIDER (self));
+
+  return self->enabled;
+}
+
 static void
 ide_source_snippet_completion_provider_finalize (GObject *object)
 {
   IdeSourceSnippetCompletionProvider *self = IDE_SOURCE_SNIPPET_COMPLETION_PROVIDER (object);
 
   g_clear_object (&self->snippets);
+  g_clear_object (&self->settings);
 
   if (self->source_view)
     g_object_remove_weak_pointer (G_OBJECT (self->source_view),
@@ -108,6 +124,10 @@ ide_source_snippet_completion_provider_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_ENABLED:
+      g_value_set_boolean (value, provider->enabled);
+      break;
+
     case PROP_SOURCE_VIEW:
       g_value_set_object (value, provider->source_view);
       break;
@@ -131,6 +151,10 @@ ide_source_snippet_completion_provider_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_ENABLED:
+      provider->enabled = g_value_get_boolean (value);
+      break;
+
     case PROP_SOURCE_VIEW:
       if (provider->source_view)
         {
@@ -162,6 +186,13 @@ ide_source_snippet_completion_provider_class_init (IdeSourceSnippetCompletionPro
   object_class->get_property = ide_source_snippet_completion_provider_get_property;
   object_class->set_property = ide_source_snippet_completion_provider_set_property;
 
+  gParamSpecs [PROP_ENABLED] =
+    g_param_spec_boolean ("enabled",
+                          "Enabled",
+                          "If the provider is enabled.",
+                          TRUE,
+                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gParamSpecs[PROP_SOURCE_VIEW] =
     g_param_spec_object ("source-view",
                          "Source View",
@@ -180,8 +211,10 @@ ide_source_snippet_completion_provider_class_init (IdeSourceSnippetCompletionPro
 }
 
 static void
-ide_source_snippet_completion_provider_init (IdeSourceSnippetCompletionProvider *provider)
+ide_source_snippet_completion_provider_init (IdeSourceSnippetCompletionProvider *self)
 {
+  self->settings = g_settings_new ("org.gnome.builder.code-insight");
+  g_settings_bind (self->settings, "snippet-completion", self, "enabled", G_SETTINGS_BIND_GET);
 }
 
 static gboolean
@@ -363,4 +396,5 @@ init_provider (GtkSourceCompletionProviderIface *iface)
   iface->get_name = provider_get_name;
   iface->get_priority = provider_get_priority;
   iface->populate = provider_populate;
+  iface->match = ide_source_snippet_completion_provider_match;
 }


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