[gnome-builder/wip/libide: 171/237] libide: give IdeFileSettings a weak pointer to the file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide: 171/237] libide: give IdeFileSettings a weak pointer to the file
- Date: Tue, 17 Feb 2015 21:43:47 +0000 (UTC)
commit 81852b79ed5f2df102387587f271ac073ea9ecff
Author: Christian Hergert <christian hergert me>
Date: Sat Feb 14 16:37:03 2015 -0800
libide: give IdeFileSettings a weak pointer to the file
libide/ide-file-settings.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
libide/ide-file-settings.h | 6 +++-
2 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/libide/ide-file-settings.c b/libide/ide-file-settings.c
index 4d7c82a..1e66659 100644
--- a/libide/ide-file-settings.c
+++ b/libide/ide-file-settings.c
@@ -19,11 +19,13 @@
#include <glib/gi18n.h>
#include <gtksourceview/gtksource.h>
+#include "ide-file.h"
#include "ide-file-settings.h"
typedef struct
{
gchar *encoding;
+ IdeFile *file;
IdeIndentStyle indent_style : 2;
guint indent_width : 6;
guint insert_trailing_newline : 1;
@@ -37,6 +39,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeFileSettings, ide_file_settings, IDE_TYPE_OBJECT)
enum {
PROP_0,
PROP_ENCODING,
+ PROP_FILE,
PROP_INDENT_STYLE,
PROP_INDENT_WIDTH,
PROP_INSERT_TRAILING_NEWLINE,
@@ -74,6 +77,45 @@ ide_file_settings_set_encoding (IdeFileSettings *self,
}
}
+/**
+ * ide_file_settings_get_file:
+ * @self: An #IdeFileSettings.
+ *
+ * Retrieves the underlying file that @self refers to.
+ *
+ * This may be used by #IdeFileSettings implementations to discover additional
+ * information about the settings. For example, a modeline parser might load
+ * some portion of the file looking for modelines. An editorconfig
+ * implementation might look for ".editorconfig" files.
+ *
+ * Returns: (transfer none): An #IdeFile.
+ */
+IdeFile *
+ide_file_settings_get_file (IdeFileSettings *self)
+{
+ IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_FILE_SETTINGS (self), NULL);
+
+ return priv->file;
+}
+
+static void
+ide_file_settings_set_file (IdeFileSettings *self,
+ IdeFile *file)
+{
+ IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_FILE_SETTINGS (self));
+ g_return_if_fail (IDE_IS_FILE (file));
+
+ if (priv->file != file)
+ {
+ if (ide_set_weak_pointer (&priv->file, file))
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_FILE]);
+ }
+}
+
IdeIndentStyle
ide_file_settings_get_indent_style (IdeFileSettings *self)
{
@@ -248,6 +290,7 @@ ide_file_settings_finalize (GObject *object)
IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
g_clear_pointer (&priv->encoding, g_free);
+ ide_clear_weak_pointer (&priv->file);
G_OBJECT_CLASS (ide_file_settings_parent_class)->finalize (object);
}
@@ -356,6 +399,17 @@ ide_file_settings_class_init (IdeFileSettingsClass *klass)
g_object_class_install_property (object_class, PROP_ENCODING,
gParamSpecs [PROP_ENCODING]);
+ gParamSpecs [PROP_FILE] =
+ g_param_spec_object ("file",
+ _("File"),
+ _("The IdeFile the settings represent."),
+ IDE_TYPE_FILE,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_FILE,
+ gParamSpecs [PROP_FILE]);
+
gParamSpecs [PROP_INDENT_STYLE] =
g_param_spec_enum ("indent-style",
_("Indent Style"),
diff --git a/libide/ide-file-settings.h b/libide/ide-file-settings.h
index a3acf73..0e4348b 100644
--- a/libide/ide-file-settings.h
+++ b/libide/ide-file-settings.h
@@ -21,12 +21,13 @@
#include <gtksourceview/gtksource.h>
-#include "ide-object.h"
#include "ide-indent-style.h"
+#include "ide-object.h"
G_BEGIN_DECLS
-#define IDE_TYPE_FILE_SETTINGS (ide_file_settings_get_type())
+#define IDE_TYPE_FILE_SETTINGS (ide_file_settings_get_type())
+#define IDE_FILE_SETTINGS_EXTENSION_POINT "org.gnome.libide.extensions.file-settings"
G_DECLARE_DERIVABLE_TYPE (IdeFileSettings, ide_file_settings,
IDE, FILE_SETTINGS, IdeObject)
@@ -37,6 +38,7 @@ struct _IdeFileSettingsClass
};
const gchar *ide_file_settings_get_encoding (IdeFileSettings *self);
+IdeFile *ide_file_settings_get_file (IdeFileSettings *self);
IdeIndentStyle ide_file_settings_get_indent_style (IdeFileSettings *self);
guint ide_file_settings_get_indent_width (IdeFileSettings *self);
gboolean ide_file_settings_get_insert_trailing_newline (IdeFileSettings *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]