[gnome-builder/wip/libide: 189/237] libide: add gsettings based IdeFileSettings implementation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide: 189/237] libide: add gsettings based IdeFileSettings implementation
- Date: Tue, 17 Feb 2015 21:45:18 +0000 (UTC)
commit 5330c23250a23d57d4a7add1cc4c1d94476e1842
Author: Christian Hergert <christian hergert me>
Date: Sat Feb 14 19:50:58 2015 -0800
libide: add gsettings based IdeFileSettings implementation
libide/Makefile.am | 3 +
libide/gsettings/ide-gsettings-file-settings.c | 164 ++++++++++++++++++++++++
libide/gsettings/ide-gsettings-file-settings.h | 33 +++++
libide/ide.c | 7 +-
4 files changed, 206 insertions(+), 1 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 15de308..1bb5f5c 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -30,6 +30,8 @@ libide_la_public_sources = \
libide/editorconfig/ide-editorconfig-file-settings.h \
libide/git/ide-git-vcs.c \
libide/git/ide-git-vcs.h \
+ libide/gsettings/ide-gsettings-file-settings.c \
+ libide/gsettings/ide-gsettings-file-settings.h \
libide/ide-back-forward-item.c \
libide/ide-back-forward-item.h \
libide/ide-back-forward-list.c \
@@ -150,6 +152,7 @@ libide_la_CFLAGS = \
-I$(top_srcdir)/libide/directory \
-I$(top_srcdir)/libide/editorconfig \
-I$(top_srcdir)/libide/git \
+ -I$(top_srcdir)/libide/gsettings \
-I$(top_srcdir)/libide/local \
-I$(top_srcdir)/libide/tasks \
$(LIBIDE_CFLAGS)
diff --git a/libide/gsettings/ide-gsettings-file-settings.c b/libide/gsettings/ide-gsettings-file-settings.c
new file mode 100644
index 0000000..c912209
--- /dev/null
+++ b/libide/gsettings/ide-gsettings-file-settings.c
@@ -0,0 +1,164 @@
+/* ide-gsettings-file-settings.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "ide-context.h"
+#include "ide-file.h"
+#include "ide-gsettings-file-settings.h"
+#include "ide-language.h"
+
+struct _IdeGsettingsFileSettings
+{
+ IdeFileSettings parent_instance;
+
+ GSettings *settings;
+};
+
+static void async_initable_iface_init (GAsyncInitableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeGsettingsFileSettings,
+ ide_gsettings_file_settings,
+ IDE_TYPE_FILE_SETTINGS,
+ 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
+ async_initable_iface_init))
+
+static void
+ide_gsettings_file_settings_finalize (GObject *object)
+{
+ IdeGsettingsFileSettings *self = (IdeGsettingsFileSettings *)object;
+
+ g_clear_object (&self->settings);
+
+ G_OBJECT_CLASS (ide_gsettings_file_settings_parent_class)->finalize (object);
+}
+
+static void
+ide_gsettings_file_settings_class_init (IdeGsettingsFileSettingsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_gsettings_file_settings_finalize;
+}
+
+static void
+ide_gsettings_file_settings_init (IdeGsettingsFileSettings *self)
+{
+}
+
+static gboolean
+indent_style_get (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ if (g_variant_get_boolean (variant))
+ g_value_set_enum (value, IDE_INDENT_STYLE_SPACES);
+ else
+ g_value_set_enum (value, IDE_INDENT_STYLE_TABS);
+
+ return TRUE;
+}
+
+static void
+ide_gsettings_file_settings_init_async (GAsyncInitable *initable,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ IdeGsettingsFileSettings *self = (IdeGsettingsFileSettings *)initable;
+ g_autoptr(GSettings) settings = NULL;
+ g_autoptr(GTask) task = NULL;
+ g_autoptr(gchar) path = NULL;
+ IdeLanguage *language;
+ IdeFile *file;
+ const gchar *lang_id;
+
+ g_return_if_fail (IDE_IS_GSETTINGS_FILE_SETTINGS (self));
+
+ task = g_task_new (self, cancellable, callback, user_data);
+
+ file = ide_file_settings_get_file (IDE_FILE_SETTINGS (self));
+
+ if (!file)
+ {
+ g_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_FOUND,
+ _("No file was provided"));
+ return;
+ }
+
+ language = ide_file_get_language (file);
+
+ if (!language)
+ {
+ g_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ _("Failed to retrieve langauge for file."));
+ return;
+ }
+
+ lang_id = ide_language_get_id (language);
+
+ path = g_strdup_printf ("/org/gnome/builder/editor/language/%s/", lang_id);
+ settings = g_settings_new_with_path ("org.gnome.builder.editor.language", path);
+
+ self->settings = g_object_ref (settings);
+
+ g_settings_bind (self->settings, "indent-width", self, "indent-width",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind (self->settings, "tab-width", self, "tab-width",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind_with_mapping (self->settings, "insert-spaces-instead-of-tabs",
+ self, "indent-style", G_SETTINGS_BIND_GET,
+ indent_style_get, NULL, NULL, NULL);
+ g_settings_bind_with_mapping (self->settings, "insert-spaces-instead-of-tabs",
+ self, "indent-style", G_SETTINGS_BIND_GET,
+ indent_style_get, NULL, NULL, NULL);
+ g_settings_bind (self->settings, "right-margin-position",
+ self, "right-margin-position",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind (self->settings, "trim-trailing-whitespace",
+ self, "trim-trailing-whitespace",
+ G_SETTINGS_BIND_GET);
+
+ g_task_return_boolean (task, TRUE);
+}
+
+static gboolean
+ide_gsettings_file_settings_init_finish (GAsyncInitable *initable,
+ GAsyncResult *result,
+ GError **error)
+{
+ GTask *task = (GTask *)result;
+
+ g_return_val_if_fail (IDE_IS_GSETTINGS_FILE_SETTINGS (initable), FALSE);
+ g_return_val_if_fail (G_IS_TASK (task), FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+static void
+async_initable_iface_init (GAsyncInitableIface *iface)
+{
+ iface->init_async = ide_gsettings_file_settings_init_async;
+ iface->init_finish = ide_gsettings_file_settings_init_finish;
+}
diff --git a/libide/gsettings/ide-gsettings-file-settings.h b/libide/gsettings/ide-gsettings-file-settings.h
new file mode 100644
index 0000000..ae2612d
--- /dev/null
+++ b/libide/gsettings/ide-gsettings-file-settings.h
@@ -0,0 +1,33 @@
+/* ide-gsettings-file-settings.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_GSETTINGS_FILE_SETTINGS_H
+#define IDE_GSETTINGS_FILE_SETTINGS_H
+
+#include "ide-file-settings.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GSETTINGS_FILE_SETTINGS (ide_gsettings_file_settings_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGsettingsFileSettings, ide_gsettings_file_settings,
+ IDE, GSETTINGS_FILE_SETTINGS, IdeFileSettings)
+
+G_END_DECLS
+
+#endif /* IDE_GSETTINGS_FILE_SETTINGS_H */
diff --git a/libide/ide.c b/libide/ide.c
index b59a0fe..5fdd504 100644
--- a/libide/ide.c
+++ b/libide/ide.c
@@ -30,6 +30,7 @@
#include "ide-editorconfig-file-settings.h"
#include "ide-file-settings.h"
#include "ide-git-vcs.h"
+#include "ide-gsettings-file-settings.h"
static gboolean gProgramNameRead;
static const gchar *gProgramName = "libide";
@@ -79,7 +80,11 @@ ide_init_ctor (void)
g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
IDE_TYPE_EDITORCONFIG_FILE_SETTINGS,
IDE_FILE_SETTINGS_EXTENSION_POINT".editorconfig",
- 0);
+ -100);
+ g_io_extension_point_implement (IDE_FILE_SETTINGS_EXTENSION_POINT,
+ IDE_TYPE_GSETTINGS_FILE_SETTINGS,
+ IDE_FILE_SETTINGS_EXTENSION_POINT".gsettings",
+ -200);
g_io_extension_point_implement (IDE_LANGUAGE_EXTENSION_POINT,
IDE_TYPE_C_LANGUAGE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]