[gnome-builder: 48/139] modelines: move modelines support to a plugin



commit 3ead35a718de23139cf4dc631ea74ecb9476b00d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 16:39:08 2019 -0800

    modelines: move modelines support to a plugin
    
    This also ports things to use better API now that IdeFile has been gotten
    rid of.

 src/libide/modelines/meson.build                   |  8 ---
 .../modelines/gbp-modelines-file-settings.c}       | 84 +++++++++++-----------
 .../modelines/gbp-modelines-file-settings.h}       |  9 ++-
 .../modelines/language-mappings                    |  0
 src/plugins/modelines/meson.build                  | 17 +++++
 .../modelines/modeline-parser.c                    |  2 +-
 .../modelines/modeline-parser.h                    |  3 +-
 src/plugins/modelines/modelines-plugin.c           | 37 ++++++++++
 src/plugins/modelines/modelines.gresource.xml      |  7 ++
 src/plugins/modelines/modelines.plugin             | 10 +++
 10 files changed, 121 insertions(+), 56 deletions(-)
---
diff --git a/src/libide/modelines/ide-modelines-file-settings.c 
b/src/plugins/modelines/gbp-modelines-file-settings.c
similarity index 52%
rename from src/libide/modelines/ide-modelines-file-settings.c
rename to src/plugins/modelines/gbp-modelines-file-settings.c
index eba94a862..8c75ca757 100644
--- a/src/libide/modelines/ide-modelines-file-settings.c
+++ b/src/plugins/modelines/gbp-modelines-file-settings.c
@@ -1,4 +1,4 @@
-/* ide-modelines-file-settings.c
+/* gbp-modelines-file-settings.c
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -18,77 +18,81 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#define G_LOG_DOMAIN "ide-modelines-file-settings"
+#define G_LOG_DOMAIN "gbp-modelines-file-settings"
 
 #include "config.h"
 
+#include <libide-code.h>
 #include <glib/gi18n.h>
 
-#include "ide-context.h"
+#include "gbp-modelines-file-settings.h"
+#include "modeline-parser.h"
 
-#include "buffers/ide-buffer-manager.h"
-#include "buffers/ide-buffer.h"
-#include "modelines/ide-modelines-file-settings.h"
-#include "modelines/modeline-parser.h"
-
-struct _IdeModelinesFileSettings
+struct _GbpModelinesFileSettings
 {
   IdeFileSettings parent_instance;
 };
 
-G_DEFINE_TYPE (IdeModelinesFileSettings, ide_modelines_file_settings, IDE_TYPE_FILE_SETTINGS)
+G_DEFINE_TYPE (GbpModelinesFileSettings, gbp_modelines_file_settings, IDE_TYPE_FILE_SETTINGS)
+
+static gboolean
+buffer_file_matches (GbpModelinesFileSettings *self,
+                     IdeBuffer                *buffer)
+{
+  GFile *our_file;
+  GFile *buffer_file;
+
+  g_assert (GBP_IS_MODELINES_FILE_SETTINGS (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  buffer_file = ide_buffer_get_file (buffer);
+  our_file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self));
+
+  return g_file_equal (buffer_file, our_file);
+}
 
 static void
-buffer_loaded_cb (IdeModelinesFileSettings *self,
+buffer_loaded_cb (GbpModelinesFileSettings *self,
                   IdeBuffer                *buffer,
                   IdeBufferManager         *buffer_manager)
 {
-  IdeFile *our_file;
-  IdeFile *buffer_file;
-
-  g_assert (IDE_IS_MODELINES_FILE_SETTINGS (self));
+  g_assert (GBP_IS_MODELINES_FILE_SETTINGS (self));
   g_assert (IDE_IS_BUFFER (buffer));
   g_assert (IDE_IS_BUFFER_MANAGER (buffer_manager));
 
-  if ((buffer_file = ide_buffer_get_file (buffer)) &&
-      (our_file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self))) &&
-      ide_file_equal (buffer_file, our_file))
-    {
-      modeline_parser_apply_modeline (GTK_TEXT_BUFFER (buffer), IDE_FILE_SETTINGS (self));
-    }
+  if (buffer_file_matches (self, buffer))
+    modeline_parser_apply_modeline (GTK_TEXT_BUFFER (buffer), IDE_FILE_SETTINGS (self));
 }
 
 static void
-buffer_saved_cb (IdeModelinesFileSettings *self,
+buffer_saved_cb (GbpModelinesFileSettings *self,
                  IdeBuffer                *buffer,
                  IdeBufferManager         *buffer_manager)
 {
-  IdeFile *our_file;
-  IdeFile *buffer_file;
-
-  g_assert (IDE_IS_MODELINES_FILE_SETTINGS (self));
+  g_assert (GBP_IS_MODELINES_FILE_SETTINGS (self));
   g_assert (IDE_IS_BUFFER (buffer));
   g_assert (IDE_IS_BUFFER_MANAGER (buffer_manager));
 
-  if ((buffer_file = ide_buffer_get_file (buffer)) &&
-      (our_file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self))) &&
-      ide_file_equal (buffer_file, our_file))
-    {
-      modeline_parser_apply_modeline (GTK_TEXT_BUFFER (buffer), IDE_FILE_SETTINGS (self));
-    }
+  if (buffer_file_matches (self, buffer))
+    modeline_parser_apply_modeline (GTK_TEXT_BUFFER (buffer), IDE_FILE_SETTINGS (self));
 }
 
 static void
-ide_modelines_file_settings_constructed (GObject *object)
+gbp_modelines_file_settings_parent_set (IdeObject *object,
+                                        IdeObject *parent)
 {
-  IdeModelinesFileSettings *self = (IdeModelinesFileSettings *)object;
+  GbpModelinesFileSettings *self = (GbpModelinesFileSettings *)object;
   IdeBufferManager *buffer_manager;
   IdeContext *context;
 
-  G_OBJECT_CLASS (ide_modelines_file_settings_parent_class)->constructed (object);
+  g_assert (IDE_IS_OBJECT (object));
+  g_assert (!parent || IDE_IS_OBJECT (parent));
+
+  if (parent == NULL)
+    return;
 
   context = ide_object_get_context (IDE_OBJECT (self));
-  buffer_manager = ide_context_get_buffer_manager (context);
+  buffer_manager = ide_buffer_manager_from_context (context);
 
   g_signal_connect_object (buffer_manager,
                            "buffer-loaded",
@@ -104,14 +108,14 @@ ide_modelines_file_settings_constructed (GObject *object)
 }
 
 static void
-ide_modelines_file_settings_class_init (IdeModelinesFileSettingsClass *klass)
+gbp_modelines_file_settings_class_init (GbpModelinesFileSettingsClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeObjectClass *i_object_class = IDE_OBJECT_CLASS (klass);
 
-  object_class->constructed = ide_modelines_file_settings_constructed;
+  i_object_class->parent_set = gbp_modelines_file_settings_parent_set;
 }
 
 static void
-ide_modelines_file_settings_init (IdeModelinesFileSettings *self)
+gbp_modelines_file_settings_init (GbpModelinesFileSettings *self)
 {
 }
diff --git a/src/libide/modelines/ide-modelines-file-settings.h 
b/src/plugins/modelines/gbp-modelines-file-settings.h
similarity index 74%
rename from src/libide/modelines/ide-modelines-file-settings.h
rename to src/plugins/modelines/gbp-modelines-file-settings.h
index 547f7e4ac..bd15e9804 100644
--- a/src/libide/modelines/ide-modelines-file-settings.h
+++ b/src/plugins/modelines/gbp-modelines-file-settings.h
@@ -1,4 +1,4 @@
-/* ide-modelines-file-settings.h
+/* gbp-modelines-file-settings.h
  *
  * Copyright 2015-2019 Christian Hergert <christian hergert me>
  *
@@ -20,13 +20,12 @@
 
 #pragma once
 
-#include "files/ide-file-settings.h"
+#include "ide-file-settings.h"
 
 G_BEGIN_DECLS
 
-#define IDE_TYPE_MODELINES_FILE_SETTINGS (ide_modelines_file_settings_get_type())
+#define GBP_TYPE_MODELINES_FILE_SETTINGS (gbp_modelines_file_settings_get_type())
 
-G_DECLARE_FINAL_TYPE (IdeModelinesFileSettings, ide_modelines_file_settings,
-                      IDE, MODELINES_FILE_SETTINGS, IdeFileSettings)
+G_DECLARE_FINAL_TYPE (GbpModelinesFileSettings, gbp_modelines_file_settings, GBP, MODELINES_FILE_SETTINGS, 
IdeFileSettings)
 
 G_END_DECLS
diff --git a/src/libide/modelines/language-mappings b/src/plugins/modelines/language-mappings
similarity index 100%
rename from src/libide/modelines/language-mappings
rename to src/plugins/modelines/language-mappings
diff --git a/src/plugins/modelines/meson.build b/src/plugins/modelines/meson.build
new file mode 100644
index 000000000..7916fc4ae
--- /dev/null
+++ b/src/plugins/modelines/meson.build
@@ -0,0 +1,17 @@
+if get_option('plugin_modelines')
+
+plugins_sources += files([
+  'gbp-modelines-file-settings.c',
+  'modeline-parser.c',
+  'modelines-plugin.c',
+])
+
+plugin_modelines_resources = gnome.compile_resources(
+  'gbp-modelines-resources',
+  'modelines.gresource.xml',
+  c_name: 'gbp_modelines',
+)
+
+plugins_sources += plugin_modelines_resources[0]
+
+endif
diff --git a/src/libide/modelines/modeline-parser.c b/src/plugins/modelines/modeline-parser.c
similarity index 99%
rename from src/libide/modelines/modeline-parser.c
rename to src/plugins/modelines/modeline-parser.c
index bdf111da0..9e6ea7d0c 100644
--- a/src/libide/modelines/modeline-parser.c
+++ b/src/plugins/modelines/modeline-parser.c
@@ -27,7 +27,7 @@
 
 #include "modelines/modeline-parser.h"
 
-#define MODELINES_LANGUAGE_MAPPINGS_FILE "/org/gnome/builder/modelines/language-mappings"
+#define MODELINES_LANGUAGE_MAPPINGS_FILE "/plugins/modelines/language-mappings"
 #define gedit_debug_message(ignored,fmt,...) g_debug(fmt,__VA_ARGS__)
 
 /* Mappings: language name -> Gedit language ID */
diff --git a/src/libide/modelines/modeline-parser.h b/src/plugins/modelines/modeline-parser.h
similarity index 96%
rename from src/libide/modelines/modeline-parser.h
rename to src/plugins/modelines/modeline-parser.h
index 587fbd7fe..e02a5e9dd 100644
--- a/src/libide/modelines/modeline-parser.h
+++ b/src/plugins/modelines/modeline-parser.h
@@ -23,8 +23,7 @@
 
 #include <glib.h>
 #include <gtksourceview/gtksource.h>
-
-#include "files/ide-file-settings.h"
+#include <libide-code.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/plugins/modelines/modelines-plugin.c b/src/plugins/modelines/modelines-plugin.c
new file mode 100644
index 000000000..5f64312dc
--- /dev/null
+++ b/src/plugins/modelines/modelines-plugin.c
@@ -0,0 +1,37 @@
+/* modelines-plugin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * 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
+ */
+
+#define G_LOG_DOMAIN "modelines-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-code.h>
+
+#include "gbp-modelines-file-settings.h"
+
+_IDE_EXTERN void
+_gbp_modelines_register_types (PeasObjectModule *module)
+{
+  g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
+                                  GBP_TYPE_MODELINES_FILE_SETTINGS,
+                                  IDE_FILE_SETTINGS_EXTENSION_POINT".modelines",
+                                  -100);
+}
diff --git a/src/plugins/modelines/modelines.gresource.xml b/src/plugins/modelines/modelines.gresource.xml
new file mode 100644
index 000000000..44765383e
--- /dev/null
+++ b/src/plugins/modelines/modelines.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/modelines">
+    <file>modelines.plugin</file>
+    <file>language-mappings</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/modelines/modelines.plugin b/src/plugins/modelines/modelines.plugin
new file mode 100644
index 000000000..c8f2e862a
--- /dev/null
+++ b/src/plugins/modelines/modelines.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2014-2018 Christian Hergert
+Depends=editor;
+Description=Support for modelines in source code files
+Embedded=_gbp_modelines_register_types
+Hidden=true
+Module=modelines
+Name=Modelines


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