[gnome-builder/wip/gtk4-port: 720/1774] snippets: add application addin for setting up the search path




commit ee44a463d90a9989878dd9a3d21f8ea0833f730a
Author: Günther Wagner <info gunibert de>
Date:   Tue Apr 26 20:24:38 2022 +0200

    snippets: add application addin for setting up the search path

 src/plugins/meson.build                            |  2 +-
 .../snippets/ide-snippet-application-addin.c       | 80 ++++++++++++++++++++++
 .../snippets/ide-snippet-application-addin.h       | 33 +++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 09f40b87b..6136cbdc2 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -117,7 +117,7 @@ subdir('rstcheck')
 subdir('rubocop')
 subdir('rust-analyzer')
 #subdir('shellcmd')
-#subdir('snippets')
+subdir('snippets')
 subdir('spellcheck')
 subdir('stylelint')
 #subdir('sublime')
diff --git a/src/plugins/snippets/ide-snippet-application-addin.c 
b/src/plugins/snippets/ide-snippet-application-addin.c
new file mode 100644
index 000000000..9ee1b848c
--- /dev/null
+++ b/src/plugins/snippets/ide-snippet-application-addin.c
@@ -0,0 +1,80 @@
+/* ide-snippet-application-addin.c
+ *
+ * Copyright 2022 Günther Wagner <info gunibert de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "ide-snippet-application-addin.h"
+#include "libide-gui.h"
+
+struct _IdeSnippetApplicationAddin
+{
+  IdeObject parent_instance;
+};
+
+void application_addin_implement_iface (IdeApplicationAddinInterface *iface);
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (IdeSnippetApplicationAddin, ide_snippet_application_addin, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, 
application_addin_implement_iface))
+
+IdeSnippetApplicationAddin *
+ide_snippet_application_addin_new (void)
+{
+  return g_object_new (IDE_TYPE_SNIPPET_APPLICATION_ADDIN, NULL);
+}
+
+static void
+ide_snippet_application_addin_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (ide_snippet_application_addin_parent_class)->finalize (object);
+}
+
+static void
+ide_snippet_application_addin_class_init (IdeSnippetApplicationAddinClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_snippet_application_addin_finalize;
+}
+
+static void
+ide_snippet_application_addin_init (IdeSnippetApplicationAddin *self)
+{
+}
+
+static void
+ide_snippet_application_addin_load (IdeApplicationAddin *addin,
+                                    IdeApplication      *app)
+{
+  IdeSnippetApplicationAddin *self = IDE_SNIPPET_APPLICATION_ADDIN (addin);
+  GtkSourceSnippetManager *snippet_manager;
+  g_autoptr(GStrvBuilder) builder = NULL;
+
+  g_return_if_fail (IDE_IS_SNIPPET_APPLICATION_ADDIN (self));
+
+  snippet_manager = gtk_source_snippet_manager_get_default ();
+  builder = g_strv_builder_new ();
+  g_strv_builder_add (builder, "resource:///org/gnome/builder/snippets/");
+
+  gtk_source_snippet_manager_set_search_path (snippet_manager, (const char * const *) g_strv_builder_end 
(builder));
+}
+
+void
+application_addin_implement_iface (IdeApplicationAddinInterface *iface)
+{
+  iface->load = ide_snippet_application_addin_load;
+}
diff --git a/src/plugins/snippets/ide-snippet-application-addin.h 
b/src/plugins/snippets/ide-snippet-application-addin.h
new file mode 100644
index 000000000..1f5867310
--- /dev/null
+++ b/src/plugins/snippets/ide-snippet-application-addin.h
@@ -0,0 +1,33 @@
+/* ide-snippet-application-addin.h
+ *
+ * Copyright 2022 Günther Wagner <info gunibert de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_SNIPPET_APPLICATION_ADDIN (ide_snippet_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeSnippetApplicationAddin, ide_snippet_application_addin, IDE, 
SNIPPET_APPLICATION_ADDIN, IdeObject)
+
+IdeSnippetApplicationAddin *ide_snippet_application_addin_new (void);
+
+G_END_DECLS


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