[gnome-builder] modlines: add modeline based IdeFileSettings



commit faf65c3cbf7909d0f1bc878ef7617c0161e3eb4d
Author: Christian Hergert <christian hergert me>
Date:   Wed May 6 16:19:48 2015 -0700

    modlines: add modeline based IdeFileSettings
    
    This will take precedence over editorconfig, project settings, and
    global settings. However, using the tweak widget in the editor will
    override these settings.

 libide/Makefile.am                             |    2 +
 libide/ide.c                                   |    9 ++-
 libide/modelines/ide-modelines-file-settings.c |  113 ++++++++++++++++++++++++
 libide/modelines/ide-modelines-file-settings.h |   33 +++++++
 4 files changed, 155 insertions(+), 2 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 24242a5..b27772c 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -200,6 +200,8 @@ libide_1_0_la_public_sources = \
        mingw/ide-mingw-device-provider.h \
        mingw/ide-mingw-device.c \
        mingw/ide-mingw-device.h \
+       modelines/ide-modelines-file-settings.c \
+       modelines/ide-modelines-file-settings.h \
        pygobject/ide-pygobject-script.c \
        pygobject/ide-pygobject-script.h \
        python/ide-python-format-provider.c \
diff --git a/libide/ide.c b/libide/ide.c
index af76811..a06b454 100644
--- a/libide/ide.c
+++ b/libide/ide.c
@@ -40,6 +40,7 @@
 #include "ide-gsettings-file-settings.h"
 #include "ide-html-language.h"
 #include "ide-mingw-device-provider.h"
+#include "ide-modelines-file-settings.h"
 #include "ide-internal.h"
 #include "ide-project-miner.h"
 #include "ide-pygobject-script.h"
@@ -115,13 +116,17 @@ ide_init_ctor (void)
                                   0);
 
   g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
+                                  IDE_TYPE_MODELINES_FILE_SETTINGS,
+                                  IDE_FILE_SETTINGS_EXTENSION_POINT".modelines",
+                                  -100);
+  g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
                                   IDE_TYPE_EDITORCONFIG_FILE_SETTINGS,
                                   IDE_FILE_SETTINGS_EXTENSION_POINT".editorconfig",
-                                  -100);
+                                  -200);
   g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
                                   IDE_TYPE_GSETTINGS_FILE_SETTINGS,
                                   IDE_FILE_SETTINGS_EXTENSION_POINT".gsettings",
-                                  -200);
+                                  -300);
 
   g_io_extension_point_implement (IDE_LANGUAGE_EXTENSION_POINT,
                                   IDE_TYPE_C_LANGUAGE,
diff --git a/libide/modelines/ide-modelines-file-settings.c b/libide/modelines/ide-modelines-file-settings.c
new file mode 100644
index 0000000..82dafd0
--- /dev/null
+++ b/libide/modelines/ide-modelines-file-settings.c
@@ -0,0 +1,113 @@
+/* ide-modelines-file-settings.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#define G_LOG_DOMAIN "ide-modelines-file-settings"
+
+#include <glib/gi18n.h>
+
+#include "ide-buffer.h"
+#include "ide-buffer-manager.h"
+#include "ide-context.h"
+#include "ide-modelines-file-settings.h"
+
+#include "modeline-parser.h"
+
+struct _IdeModelinesFileSettings
+{
+  IdeFileSettings parent_instance;
+};
+
+G_DEFINE_TYPE (IdeModelinesFileSettings, ide_modelines_file_settings, IDE_TYPE_FILE_SETTINGS)
+
+static void
+buffer_loaded_cb (IdeModelinesFileSettings *self,
+                  IdeBuffer                *buffer,
+                  IdeBufferManager         *buffer_manager)
+{
+  IdeFile *our_file;
+  IdeFile *buffer_file;
+
+  g_assert (IDE_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));
+    }
+}
+
+static void
+buffer_saved_cb (IdeModelinesFileSettings *self,
+                 IdeBuffer                *buffer,
+                 IdeBufferManager         *buffer_manager)
+{
+  IdeFile *our_file;
+  IdeFile *buffer_file;
+
+  g_assert (IDE_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));
+    }
+}
+
+static void
+ide_modelines_file_settings_constructed (GObject *object)
+{
+  IdeModelinesFileSettings *self = (IdeModelinesFileSettings *)object;
+  IdeBufferManager *buffer_manager;
+  IdeContext *context;
+
+  G_OBJECT_CLASS (ide_modelines_file_settings_parent_class)->constructed (object);
+
+  context = ide_object_get_context (IDE_OBJECT (self));
+  buffer_manager = ide_context_get_buffer_manager (context);
+
+  g_signal_connect_object (buffer_manager,
+                           "buffer-loaded",
+                           G_CALLBACK (buffer_loaded_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (buffer_manager,
+                           "buffer-saved",
+                           G_CALLBACK (buffer_saved_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+static void
+ide_modelines_file_settings_class_init (IdeModelinesFileSettingsClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = ide_modelines_file_settings_constructed;
+}
+
+static void
+ide_modelines_file_settings_init (IdeModelinesFileSettings *self)
+{
+}
diff --git a/libide/modelines/ide-modelines-file-settings.h b/libide/modelines/ide-modelines-file-settings.h
new file mode 100644
index 0000000..5c95470
--- /dev/null
+++ b/libide/modelines/ide-modelines-file-settings.h
@@ -0,0 +1,33 @@
+/* ide-modelines-file-settings.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#ifndef IDE_MODELINES_FILE_SETTINGS_H
+#define IDE_MODELINES_FILE_SETTINGS_H
+
+#include "ide-file-settings.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_MODELINES_FILE_SETTINGS (ide_modelines_file_settings_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeModelinesFileSettings, ide_modelines_file_settings,
+                      IDE, MODELINES_FILE_SETTINGS, IdeFileSettings)
+
+G_END_DECLS
+
+#endif /* IDE_MODELINES_FILE_SETTINGS_H */


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