[gtksourceview/wip/chergert/snippets] stub out bundle for parsing/loading



commit e37d9bb2b208c5fcb23efc5389865d9903a45fa7
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 27 18:09:06 2020 -0800

    stub out bundle for parsing/loading

 docs/reference/meson.build                     |  2 +
 gtksourceview/gtksourcesnippetbundle-private.h | 36 ++++++++++++++
 gtksourceview/gtksourcesnippetbundle.c         | 46 +++++++++++++++++
 gtksourceview/gtksourcesnippetmanager.c        | 68 ++++++--------------------
 gtksourceview/gtksourcetypes-private.h         |  1 +
 gtksourceview/meson.build                      |  1 +
 6 files changed, 100 insertions(+), 54 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 7fd35b46..707e2b3d 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -36,7 +36,9 @@ reference_private_h = [
   'gtksourceregex-private.h',
   'gtksourcesearchcontext-private.h',
   'gtksourcesnippet-private.h',
+  'gtksourcesnippetbundle-private.h',
   'gtksourcesnippetcontext-private.h',
+  'gtksourcesnippetmanager-private.h',
   'gtksourcestyle-private.h',
   'gtksourcestylescheme-private.h',
   'gtksourcestyleschememanager-private.h',
diff --git a/gtksourceview/gtksourcesnippetbundle-private.h b/gtksourceview/gtksourcesnippetbundle-private.h
new file mode 100644
index 00000000..9d957fb0
--- /dev/null
+++ b/gtksourceview/gtksourcesnippetbundle-private.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_SNIPPET_BUNDLE (_gtk_source_snippet_bundle_get_type())
+
+G_DECLARE_FINAL_TYPE (GtkSourceSnippetBundle, _gtk_source_snippet_bundle, GTK_SOURCE, SNIPPET_BUNDLE, 
GObject)
+
+GtkSourceSnippetBundle *_gtk_source_snippet_bundle_new_from_file (const gchar             *path,
+                                                                  GtkSourceSnippetManager *manager);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcesnippetbundle.c b/gtksourceview/gtksourcesnippetbundle.c
new file mode 100644
index 00000000..24f875cb
--- /dev/null
+++ b/gtksourceview/gtksourcesnippetbundle.c
@@ -0,0 +1,46 @@
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtksourcesnippetbundle-private.h"
+
+struct _GtkSourceSnippetBundle
+{
+       GObject parent_instance;
+};
+
+G_DEFINE_TYPE (GtkSourceSnippetBundle, _gtk_source_snippet_bundle, G_TYPE_OBJECT)
+
+static void
+_gtk_source_snippet_bundle_class_init (GtkSourceSnippetBundleClass *klass)
+{
+}
+
+static void
+_gtk_source_snippet_bundle_init (GtkSourceSnippetBundle *self)
+{
+}
+
+GtkSourceSnippetBundle *
+_gtk_source_snippet_bundle_new_from_file (const gchar             *path,
+                                          GtkSourceSnippetManager *manager)
+{
+       return NULL;
+}
diff --git a/gtksourceview/gtksourcesnippetmanager.c b/gtksourceview/gtksourcesnippetmanager.c
index 1975e578..5e695d51 100644
--- a/gtksourceview/gtksourcesnippetmanager.c
+++ b/gtksourceview/gtksourcesnippetmanager.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "gtksourcesnippet-private.h"
+#include "gtksourcesnippetbundle-private.h"
 #include "gtksourcesnippetmanager-private.h"
 #include "gtksourceutils-private.h"
 
@@ -46,9 +47,9 @@
 
 struct _GtkSourceSnippetManager
 {
-       GObject parent_instance;
-
-       gchar **snippet_dirs;
+       GObject     parent_instance;
+       gchar     **snippet_dirs;
+       GPtrArray  *bundles;
 };
 
 enum {
@@ -67,6 +68,7 @@ gtk_source_snippet_manager_finalize (GObject *object)
 {
        GtkSourceSnippetManager *self = GTK_SOURCE_SNIPPET_MANAGER (object);
 
+       g_clear_pointer (&self->bundles, g_ptr_array_unref);
        g_clear_pointer (&self->snippet_dirs, g_strfreev);
 
        G_OBJECT_CLASS (gtk_source_snippet_manager_parent_class)->finalize (object);
@@ -243,71 +245,29 @@ gtk_source_snippet_manager_get_search_path (GtkSourceSnippetManager *self)
 static void
 ensure_snippets (GtkSourceSnippetManager *self)
 {
-#if 0
-       GSList *filenames, *l;
-       GPtrArray *ids_array = NULL;
+       GSList *filenames;
 
-       if (self->snippet_ids != NULL)
-       {
-               return;
-       }
+       g_assert (GTK_SOURCE_IS_SNIPPET_MANAGER (self));
 
        filenames = _gtk_source_utils_get_file_list (
                (gchar **)gtk_source_snippet_manager_get_search_path (self),
                SNIPPET_FILE_SUFFIX,
                TRUE);
 
-       for (l = filenames; l != NULL; l = l->next)
+       for (const GSList *f = filenames; f; f = f->next)
        {
-               GtkSourceSnippet *lang;
-               const gchar *id;
-               gchar *filename;
-
-               filename = l->data;
-
-               lang = _gtk_source_snippet_new_from_file (filename, self);
-
-               if (lang == NULL)
-               {
-                       g_warning ("Error reading snippet specification file '%s'", filename);
-                       continue;
-               }
-
-               id = gtk_source_snippet_get_id (lang);
+               const gchar *filename = f->data;
+               GtkSourceSnippetBundle *bundle;
 
-               if (g_hash_table_lookup (self->snippet_ids, id) == NULL)
-               {
-                       g_hash_table_insert (self->snippet_ids,
-                                            g_strdup (id),
-                                            lang);
+               bundle = _gtk_source_snippet_bundle_new_from_file (filename, self);
 
-                       if (ids_array == NULL)
-                               ids_array = g_ptr_array_new ();
-
-                       g_ptr_array_add (ids_array, g_strdup (id));
-               }
+               if (bundle != NULL)
+                       g_ptr_array_add (self->bundles, bundle);
                else
-               {
-                       g_object_unref (lang);
-               }
-       }
-
-       if (ids_array != NULL)
-       {
-               /* Sort the array alphabetically so that it
-                * is ready to use in a list of a GUI */
-               g_ptr_array_sort_with_data (ids_array,
-                                           (GCompareDataFunc)snippet_compare,
-                                           self->snippet_ids);
-
-               /* Ensure the array is NULL terminated */
-               g_ptr_array_add (ids_array, NULL);
-
-               self->ids = (gchar **)g_ptr_array_free (ids_array, FALSE);
+                       g_warning ("Error reading snippet file '%s'", filename);
        }
 
        g_slist_free_full (filenames, g_free);
-#endif
 }
 
 /**
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index 5d0570db..c49946d3 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -33,6 +33,7 @@ typedef struct _GtkSourceGutterRendererMarks    GtkSourceGutterRendererMarks;
 typedef struct _GtkSourceMarksSequence          GtkSourceMarksSequence;
 typedef struct _GtkSourcePixbufHelper           GtkSourcePixbufHelper;
 typedef struct _GtkSourceRegex                  GtkSourceRegex;
+typedef struct _GtkSourceSnippetBundle          GtkSourceSnippetBundle;
 
 #ifdef _MSC_VER
 /* For Visual Studio, we need to export the symbols used by the unit tests */
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index bedfebb9..aa2b5d54 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -108,6 +108,7 @@ core_private_c = files([
   'gtksourcemarkssequence.c',
   'gtksourcepixbufhelper.c',
   'gtksourceregex.c',
+  'gtksourcesnippetbundle.c',
   'gtksourceview-snippets.c',
 ])
 


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