[gnome-builder/wip/cleanup-source] editor: move snippets provider into sourceview.



commit fef307c714bd7939d28e938aba35e33127020f66
Author: Christian Hergert <christian hergert me>
Date:   Fri Oct 17 16:20:22 2014 -0700

    editor: move snippets provider into sourceview.

 src/editor/gb-editor-tab-private.h |    2 -
 src/editor/gb-editor-tab.c         |   50 -----------------------
 src/editor/gb-source-view.c        |   76 +++++++++++++++++++++++++++++-------
 3 files changed, 62 insertions(+), 66 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index f23a21b..fba8d66 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -31,7 +31,6 @@
 #include "gb-notebook.h"
 #include "gb-source-change-monitor.h"
 #include "gb-source-search-highlighter.h"
-#include "gb-source-snippet-completion-provider.h"
 #include "gb-source-view.h"
 #include "gd-tagged-entry.h"
 #include "nautilus-floating-bar.h"
@@ -48,7 +47,6 @@ struct _GbEditorTabPrivate
   /*
    * Variants completion providers.
    */
-  GtkSourceCompletionProvider *snippets_provider;
   GtkSourceCompletionProvider *words_provider;
 
   /*
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 384b065..fac8e0a 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -166,28 +166,6 @@ gb_editor_tab_get_file (GbEditorTab *tab)
 }
 
 static void
-gb_editor_tab_reload_snippets (GbEditorTab       *tab,
-                               GtkSourceLanguage *language)
-{
-  GbSourceSnippetsManager *manager;
-  GbEditorTabPrivate *priv;
-  GbSourceSnippets *snippets = NULL;
-
-  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-
-  priv = tab->priv;
-
-  if (language)
-    {
-      manager = gb_source_snippets_manager_get_default ();
-      snippets = gb_source_snippets_manager_get_for_language (manager,
-                                                              language);
-    }
-
-  g_object_set (priv->snippets_provider, "snippets", snippets, NULL);
-}
-
-static void
 gb_editor_tab_connect_settings (GbEditorTab      *tab,
                                 GbEditorSettings *settings)
 {
@@ -414,22 +392,6 @@ on_search_occurrences_notify (GbEditorTab            *tab,
 }
 
 static void
-gb_editor_tab_language_changed (GbEditorTab      *tab,
-                                GParamSpec       *pspec,
-                                GbEditorDocument *document)
-{
-  GtkSourceLanguage *language;
-
-  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
-
-  language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (document));
-
-  gb_editor_tab_reload_snippets (tab, language);
-
-}
-
-static void
 gb_editor_tab_cursor_moved (GbEditorTab      *tab,
                             GbEditorDocument *document)
 {
@@ -1186,11 +1148,6 @@ gb_editor_tab_constructed (GObject *object)
                             "text-view", priv->source_view,
                             NULL);
 
-  priv->snippets_provider =
-    g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
-                  "source-view", priv->source_view,
-                  NULL);
-
   if (!priv->settings)
     gb_editor_tab_set_settings (tab, NULL);
 
@@ -1234,10 +1191,6 @@ gb_editor_tab_constructed (GObject *object)
                             "cursor-moved",
                             G_CALLBACK (gb_editor_tab_cursor_moved),
                             tab);
-  g_signal_connect_swapped (priv->document,
-                            "notify::language",
-                            G_CALLBACK (gb_editor_tab_language_changed),
-                            tab);
 
   g_signal_connect (priv->source_view,
                     "focus-in-event",
@@ -1276,7 +1229,6 @@ gb_editor_tab_constructed (GObject *object)
       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);
 
   /*
@@ -1475,7 +1427,6 @@ gb_editor_tab_dispose (GObject *object)
   g_clear_object (&tab->priv->document);
   g_clear_object (&tab->priv->search_entry_tag);
   g_clear_object (&tab->priv->file);
-  g_clear_object (&tab->priv->snippets_provider);
   g_clear_object (&tab->priv->search_highlighter);
   g_clear_object (&tab->priv->search_settings);
   g_clear_object (&tab->priv->search_context);
@@ -1628,7 +1579,6 @@ gb_editor_tab_class_init (GbEditorTabClass *klass)
   g_type_ensure (GB_TYPE_EDITOR_DOCUMENT);
   g_type_ensure (GB_TYPE_SOURCE_CHANGE_MONITOR);
   g_type_ensure (GB_TYPE_SOURCE_VIEW);
-  g_type_ensure (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER);
   g_type_ensure (GB_TYPE_SOURCE_SEARCH_HIGHLIGHTER);
   g_type_ensure (GD_TYPE_TAGGED_ENTRY);
   g_type_ensure (NAUTILUS_TYPE_FLOATING_BAR);
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index c0dde6e..e53f45a 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -31,6 +31,9 @@
 #include "gb-log.h"
 #include "gb-source-auto-indenter.h"
 #include "gb-source-search-highlighter.h"
+#include "gb-source-snippets.h"
+#include "gb-source-snippets-manager.h"
+#include "gb-source-snippet-completion-provider.h"
 #include "gb-source-snippet-context.h"
 #include "gb-source-snippet-private.h"
 #include "gb-source-view.h"
@@ -38,20 +41,21 @@
 
 struct _GbSourceViewPrivate
 {
-  GQueue                    *snippets;
-  GbSourceSearchHighlighter *search_highlighter;
-  GtkTextBuffer             *buffer;
-  GbSourceAutoIndenter      *auto_indenter;
-
-  guint                      buffer_insert_text_handler;
-  guint                      buffer_insert_text_after_handler;
-  guint                      buffer_delete_range_handler;
-  guint                      buffer_delete_range_after_handler;
-  guint                      buffer_mark_set_handler;
-  guint                      buffer_notify_language_handler;
-
-  guint                      show_shadow : 1;
-  guint                      auto_indent : 1;
+  GQueue                      *snippets;
+  GbSourceSearchHighlighter   *search_highlighter;
+  GtkTextBuffer               *buffer;
+  GbSourceAutoIndenter        *auto_indenter;
+  GtkSourceCompletionProvider *snippets_provider;
+
+  guint                        buffer_insert_text_handler;
+  guint                        buffer_insert_text_after_handler;
+  guint                        buffer_delete_range_handler;
+  guint                        buffer_delete_range_after_handler;
+  guint                        buffer_mark_set_handler;
+  guint                        buffer_notify_language_handler;
+
+  guint                        show_shadow : 1;
+  guint                        auto_indent : 1;
 };
 
 typedef void (*GbSourceViewMatchFunc) (GbSourceView      *view,
@@ -832,6 +836,27 @@ on_mark_set (GtkTextBuffer *buffer,
 }
 
 static void
+gb_source_view_reload_snippets (GbSourceView      *source_view,
+                                GtkSourceLanguage *language)
+{
+  GbSourceSnippetsManager *mgr;
+  GbSourceSnippets *snippets = NULL;
+
+  g_return_if_fail (GB_IS_SOURCE_VIEW (source_view));
+  g_return_if_fail (!language || GTK_SOURCE_IS_LANGUAGE (language));
+
+  if (language)
+    {
+      mgr = gb_source_snippets_manager_get_default ();
+      snippets = gb_source_snippets_manager_get_for_language (mgr, language);
+    }
+
+  g_object_set (source_view->priv->snippets_provider,
+                "snippets", snippets,
+                NULL);
+}
+
+static void
 on_language_set (GtkSourceBuffer *buffer,
                  GParamSpec      *pspec,
                  GbSourceView    *source_view)
@@ -859,6 +884,8 @@ on_language_set (GtkSourceBuffer *buffer,
     }
 
   source_view->priv->auto_indenter = auto_indenter;
+
+  gb_source_view_reload_snippets (source_view, language);
 }
 
 static void
@@ -1357,6 +1384,20 @@ gb_source_view_get_auto_indenter (GbSourceView *view)
 }
 
 static void
+gb_source_view_constructed (GObject *object)
+{
+  GtkSourceCompletion *completion;
+  GbSourceView *source_view = (GbSourceView *)object;
+
+  G_OBJECT_CLASS (gb_source_view_parent_class)->constructed (object);
+
+  completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (object));
+  gtk_source_completion_add_provider (completion,
+                                      source_view->priv->snippets_provider,
+                                      NULL);
+}
+
+static void
 gb_source_view_finalize (GObject *object)
 {
   GbSourceViewPrivate *priv;
@@ -1373,6 +1414,7 @@ gb_source_view_finalize (GObject *object)
   g_clear_pointer (&priv->snippets, g_queue_free);
   g_clear_object (&priv->search_highlighter);
   g_clear_object (&priv->auto_indenter);
+  g_clear_object (&priv->snippets_provider);
 
   G_OBJECT_CLASS (gb_source_view_parent_class)->finalize (object);
 }
@@ -1442,6 +1484,7 @@ gb_source_view_class_init (GbSourceViewClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
 
+  object_class->constructed = gb_source_view_constructed;
   object_class->finalize = gb_source_view_finalize;
   object_class->get_property = gb_source_view_get_property;
   object_class->set_property = gb_source_view_set_property;
@@ -1533,4 +1576,9 @@ gb_source_view_init (GbSourceView *view)
                     "notify::buffer",
                     G_CALLBACK (gb_source_view_notify_buffer),
                     NULL);
+
+  view->priv->snippets_provider =
+    g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
+                  "source-view", view,
+                  NULL);
 }


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