[gedit-code-assistance/wip/indent] Load indent backends
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-code-assistance/wip/indent] Load indent backends
- Date: Mon, 7 Apr 2014 19:14:13 +0000 (UTC)
commit b7208dbe6ad05e9184eb84772b4e56348d26f31a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun Apr 6 21:11:37 2014 +0200
Load indent backends
Makefile.am | 1 +
configure.ac | 17 ++++++
indentbackends/Makefile.am | 11 ++++
indentbackends/c/Makefile.am | 22 ++++++++
indentbackends/c/gca-c-backend.vala | 54 ++++++++++++++++++++
indentbackends/c/gcaindentbackendc.plugin | 11 ++++
src/Makefile.am | 19 +++++--
src/gca-backend-manager.vala | 77 +++++++++++++++++++++++++++++
src/gca-indent-backend.vala | 33 ++++++++++++
src/gca-plugin.vala | 2 +-
vapi/config.vapi | 11 ++++
11 files changed, 252 insertions(+), 6 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 155b36f..c27c8b0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@ geditcodeassistanceplugindir = $(GEDIT_PLUGIN_DIR)
include data/Makefile.am
include src/Makefile.am
include vapi/Makefile.am
+include indentbackends/Makefile.am
dist-hook-changelog:
@if test -d "$(srcdir)/.git"; \
diff --git a/configure.ac b/configure.ac
index 7bae58a..2f19f7f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,12 +70,29 @@ fi
GEDIT_PLUGIN_DIR="$geditlibdir/gedit/plugins"
GEDIT_DATA_DIR="$geditdatadir/gedit/plugins"
+GCA_INDENT_BACKENDS_LIBS_DIR="$GEDIT_PLUGIN_DIR/gca/indent-backends"
+GCA_INDENT_BACKENDS_DATA_DIR="$GEDIT_DATA_DIR/gca/indent-backends"
+
+GCA_LIBS_DIR="$GEDIT_PLUGIN_DIR/gca"
+AC_SUBST(GCA_LIBS_DIR)
+
+GCA_DATA_DIR="$GEDIT_DATA_DIR/gca"
+AC_SUBST(GCA_DATA_DIR)
+
AC_SUBST(GEDIT_PLUGIN_DIR)
AC_SUBST(GEDIT_DATA_DIR)
AC_SUBST(GEDIT_CFLAGS)
AC_SUBST(GEDIT_LIBS)
+AC_SUBST(GCA_INDENT_BACKENDS_LIBS_DIR)
+AC_SUBST(GCA_INDENT_BACKENDS_DATA_DIR)
+
+AC_DEFINE_UNQUOTED([GCA_INDENT_BACKENDS_DIR], "$GCA_INDENT_BACKENDS_LIBS_DIR", [Indent Backends dir])
+AC_DEFINE_UNQUOTED([GCA_INDENT_BACKENDS_DATA_DIR], "$GCA_INDENT_BACKENDS_DATA_DIR", [Indent Backends data
dir])
+AC_DEFINE_UNQUOTED([GCA_LIBS_DIR], "$GCA_LIBS_DIR", [Library dir])
+AC_DEFINE_UNQUOTED([GCA_DATA_DIR], "$GCA_DATA_DIR", [Data dir])
+
AC_CONFIG_FILES([
Makefile
data/codeassistance.plugin
diff --git a/indentbackends/Makefile.am b/indentbackends/Makefile.am
new file mode 100644
index 0000000..6874e59
--- /dev/null
+++ b/indentbackends/Makefile.am
@@ -0,0 +1,11 @@
+plugindir = $(GCA_INDENT_BACKENDS_LIBS_DIR)
+
+plugin_in_files =
+plugin_LTLIBRARIES =
+
+include indentbackends/c/Makefile.am
+
+plugin_DATA = $(plugin_in_files)
+
+EXTRA_DIST += \
+ $(plugin_in_files)
diff --git a/indentbackends/c/Makefile.am b/indentbackends/c/Makefile.am
new file mode 100644
index 0000000..6862fa6
--- /dev/null
+++ b/indentbackends/c/Makefile.am
@@ -0,0 +1,22 @@
+plugin_LTLIBRARIES += indentbackends/c/libgcaindentbackendc.la
+
+indentbackends_c_libgcaindentbackendc_la_SOURCES = \
+ indentbackends/c/gca-c-backend.vala
+
+indentbackends_c_libgcaindentbackendc_la_CFLAGS = $(GEDIT_CFLAGS) -I$(top_srcdir)/src
+indentbackends_c_libgcaindentbackendc_la_LIBADD = $(GEDIT_LIBS)
+indentbackends_c_libgcaindentbackendc_la_LDFLAGS = -module -avoid-version
+
+indentbackends_c_libgcaindentbackendc_la_VALAFLAGS = \
+ --vapidir $(builddir)/vapi \
+ --vapidir $(builddir)/src \
+ --pkg gca \
+ --pkg gio-unix-2.0 \
+ --pkg gee-0.8 \
+ --pkg gca-utils \
+ --pkg gedit \
+ --pkg libpeas-1.0 \
+ --target-glib=2.36 \
+ --thread
+
+plugin_in_files += indentbackends/c/gcaindentbackendc.plugin
diff --git a/indentbackends/c/gca-c-backend.vala b/indentbackends/c/gca-c-backend.vala
new file mode 100644
index 0000000..b64cab9
--- /dev/null
+++ b/indentbackends/c/gca-c-backend.vala
@@ -0,0 +1,54 @@
+/*
+ * This file is part of gedit-code-assistant.
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gedit-code-assistant 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.
+ *
+ * gedit-code-assistant 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 gedit-code-assistant. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gca.C
+{
+
+class Backend : Object, Gca.IndentBackend
+{
+ private Gedit.Document d_document;
+
+ public Gedit.Document document
+ {
+ get { return d_document; }
+ construct set { d_document = value; }
+ }
+
+ void activate()
+ {
+ }
+
+ void deactivate()
+ {
+
+ }
+}
+
+}
+
+[ModuleInit]
+public void peas_register_types (TypeModule module)
+{
+ Peas.ObjectModule mod = module as Peas.ObjectModule;
+
+ mod.register_extension_type (typeof (Gca.IndentBackend),
+ typeof (Gca.C.Backend));
+}
+
+/* vi:ex:ts=4 */
diff --git a/indentbackends/c/gcaindentbackendc.plugin b/indentbackends/c/gcaindentbackendc.plugin
new file mode 100644
index 0000000..21e2829
--- /dev/null
+++ b/indentbackends/c/gcaindentbackendc.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Module=gcaindentbackendc
+IAge=3
+Name=Code Assistance C Indent Backend
+Hidden=yes
+Builtin=yes
+Description=Code assistance indent backend for C
+Authors=Ignacio Casal Quinteiro <icq gnome org>
+Copyright=Copyright © 2014 Ignacio Casal Quinteiro
+Website=http://www.gedit.org
+X-Languages=c
diff --git a/src/Makefile.am b/src/Makefile.am
index 9fc00ab..0e2bd62 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,7 +27,8 @@ gedit_plugin_vala_sources = \
src/gca-diagnostic-message.vala \
src/gca-dbus.vala \
src/gca-remote-service.vala \
- src/gca-log.vala
+ src/gca-log.vala \
+ src/gca-indent-backend.vala
gedit_plugin_libcodeassistance_NOINSTHFILES = \
src/gca-utils-c.h
@@ -40,18 +41,19 @@ src_libcodeassistance_la_SOURCES = \
src_libcodeassistance_la_VALAFLAGS = \
--vapidir $(builddir)/vapi \
- --vapi src/libcodeassistance-internal.vapi \
+ --header src/gca.h \
+ --vapi src/gca.vapi \
--library libcodeassistance \
--pkg gio-unix-2.0 \
--pkg gee-0.8 \
--pkg gca-utils \
--pkg gedit \
--pkg libpeas-1.0 \
+ --pkg gobject-introspection-1.0 \
+ --pkg config \
--target-glib=2.36 \
--thread
-noinst_DATA = src/libcodeassistance-internal.vapi
-
if ENABLE_DEBUG
src_libcodeassistance_la_VALAFLAGS += --debug
endif
@@ -59,13 +61,20 @@ endif
src_libcodeassistance_la_CFLAGS = $(GEDIT_CFLAGS) -I$(top_srcdir) -w
src_libcodeassistance_la_LDFLAGS = -module -shared -avoid-version $(GEDIT_LIBS)
+vapidir = $(datadir)/vala/vapi
+dist_vapi_DATA = \
+ src/gca.vapi
+
+gcahdir = $(prefix)/include/gedit-$(GEDIT_API_VERSION)/gca
+gcah_HEADERS = src/gca.h
+
CLEANFILES += \
$(gedit_plugin_vala_sources:.vala=.c) \
$(srcdir)/src_libcodeassistance_la_vala.stamp
GITIGNOREFILES += \
src/$(DEPDIR) \
- src/libcodeassistance-internal.vapi \
+ src/gca.vapi \
src/*.lo \
src/*.o \
src/.libs \
diff --git a/src/gca-backend-manager.vala b/src/gca-backend-manager.vala
index 9c7b859..3084d92 100644
--- a/src/gca-backend-manager.vala
+++ b/src/gca-backend-manager.vala
@@ -26,6 +26,19 @@ class BackendManager
private Gee.HashMap<string, Backend?> d_backends;
private Gee.HashMap<string, string> d_language_mapping;
private Settings? d_settings;
+ private Gee.HashMap<string, IndentBackendInfo> d_indent_backends;
+ private Peas.Engine d_engine;
+
+ class IndentBackendInfo : Object
+ {
+ public IndentBackend ?backend { get; set; }
+ public Peas.PluginInfo info { get; set; }
+
+ public IndentBackendInfo(Peas.PluginInfo info)
+ {
+ Object(info: info);
+ }
+ }
private BackendManager()
{
@@ -49,6 +62,52 @@ class BackendManager
update_language_mapping();
});
}
+
+ d_indent_backends = new Gee.HashMap<string, IndentBackendInfo>();
+
+ d_engine = new Peas.Engine();
+
+ d_engine.add_search_path(Gca.Config.GCA_INDENT_BACKENDS_DIR,
+ Gca.Config.GCA_INDENT_BACKENDS_DATA_DIR);
+
+ d_engine.enable_loader("python3");
+
+ // require the gca gir
+ string tpdir = Path.build_filename(Gca.Config.GCA_LIBS_DIR,
+ "girepository-1.0");
+
+ var repo = GI.Repository.get_default();
+
+ try
+ {
+ repo.require_private(tpdir, "Gca", "3.0", 0);
+ }
+ catch (Error error)
+ {
+ warning("Could not load Gca typelib: %s", error.message);
+ }
+
+ register_backends();
+ }
+
+ private void register_backends()
+ {
+ foreach (Peas.PluginInfo info in d_engine.get_plugin_list())
+ {
+ string? langs = info.get_external_data("Languages");
+
+ if (langs == null)
+ {
+ continue;
+ }
+
+ IndentBackendInfo binfo = new IndentBackendInfo(info);
+
+ foreach (string lang in langs.split(","))
+ {
+ d_indent_backends[lang] = binfo;
+ }
+ }
}
private void update_language_mapping()
@@ -112,6 +171,24 @@ class BackendManager
return backend;
}
+ public async IndentBackend? indent_backend(string language)
+ {
+ if (!d_indent_backends.has_key(language))
+ {
+ return null;
+ }
+
+ IndentBackendInfo info = d_indent_backends[language];
+
+ if (info.backend == null)
+ {
+ d_engine.load_plugin(info.info);
+ info.backend = (Gca.IndentBackend)d_engine.create_extension(info.info,
typeof(Gca.IndentBackend));
+ }
+
+ return info.backend;
+ }
+
public static BackendManager instance
{
get
diff --git a/src/gca-indent-backend.vala b/src/gca-indent-backend.vala
new file mode 100644
index 0000000..c86b8f3
--- /dev/null
+++ b/src/gca-indent-backend.vala
@@ -0,0 +1,33 @@
+/*
+ * This file is part of gedit-code-assistant.
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gedit-code-assistant 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.
+ *
+ * gedit-code-assistant 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 gedit-code-assistant. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gca
+{
+
+public interface IndentBackend : Object
+{
+ public abstract Gedit.Document document { get; construct set; }
+
+ public abstract void activate();
+ public abstract void deactivate();
+}
+
+}
+
+/* vi:ex:ts=4 */
diff --git a/src/gca-plugin.vala b/src/gca-plugin.vala
index bbfd370..f7aeba9 100644
--- a/src/gca-plugin.vala
+++ b/src/gca-plugin.vala
@@ -18,7 +18,7 @@
*/
//[ModuleInit]
-public static void peas_register_types(TypeModule module)
+internal void peas_register_types(TypeModule module)
{
Peas.ObjectModule mod = module as Peas.ObjectModule;
diff --git a/vapi/config.vapi b/vapi/config.vapi
new file mode 100644
index 0000000..0c8235b
--- /dev/null
+++ b/vapi/config.vapi
@@ -0,0 +1,11 @@
+[CCode(cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Gca.Config
+{
+ public const string GCA_INDENT_BACKENDS_DIR;
+ public const string GCA_INDENT_BACKENDS_DATA_DIR;
+ public const string GCA_LIBS_DIR;
+ public const string GCA_DATA_DIR;
+}
+
+// ex:ts=4 noet
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]