[gtksourceview/wip/loader-saver] File: ensure-trailing-newline property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver] File: ensure-trailing-newline property
- Date: Thu, 12 Dec 2013 14:17:02 +0000 (UTC)
commit 8be4b8477eb2b1417c6c9df66b74ce761c7d1a4a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Dec 12 15:16:15 2013 +0100
File: ensure-trailing-newline property
gtksourceview/gtksourcefile.c | 45 ++++++++++++++++++++++++++++++++++++++++-
gtksourceview/gtksourcefile.h | 5 ++++
2 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 19c74ff..e52af91 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -31,7 +31,8 @@ enum
PROP_BUFFER,
PROP_ENCODING,
PROP_NEWLINE_TYPE,
- PROP_COMPRESSION_TYPE
+ PROP_COMPRESSION_TYPE,
+ PROP_ENSURE_TRAILING_NEWLINE
};
struct _GtkSourceFilePrivate
@@ -41,6 +42,8 @@ struct _GtkSourceFilePrivate
const GtkSourceEncoding *encoding;
GtkSourceNewlineType newline_type;
GtkSourceCompressionType compression_type;
+
+ guint ensure_trailing_newline : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFile, gtk_source_file, G_TYPE_OBJECT)
@@ -79,6 +82,10 @@ gtk_source_file_get_property (GObject *object,
g_value_set_enum (value, file->priv->compression_type);
break;
+ case PROP_ENSURE_TRAILING_NEWLINE:
+ g_value_set_boolean (value, file->priv->ensure_trailing_newline);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -123,6 +130,10 @@ gtk_source_file_set_property (GObject *object,
gtk_source_file_set_compression_type (file, g_value_get_enum (value));
break;
+ case PROP_ENSURE_TRAILING_NEWLINE:
+ gtk_source_file_set_ensure_trailing_newline (file, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -202,6 +213,15 @@ gtk_source_file_class_init (GtkSourceFileClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_ENSURE_TRAILING_NEWLINE,
+ g_param_spec_boolean ("ensure-trailing-newline",
+ "Ensure trailing newline",
+ "Ensure the buffer ends with a trailing
newline",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -302,6 +322,29 @@ gtk_source_file_set_compression_type (GtkSourceFile *file,
}
}
+gboolean
+gtk_source_file_get_ensure_trailing_newline (GtkSourceFile *file)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), TRUE);
+
+ return file->priv->ensure_trailing_newline;
+}
+
+void
+gtk_source_file_set_ensure_trailing_newline (GtkSourceFile *file,
+ gboolean ensure_trailing_newline)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+ ensure_trailing_newline = ensure_trailing_newline != FALSE;
+
+ if (file->priv->ensure_trailing_newline != ensure_trailing_newline)
+ {
+ file->priv->ensure_trailing_newline = ensure_trailing_newline;
+ g_object_notify (G_OBJECT (file), "ensure-trailing-newline");
+ }
+}
+
/* FIXME add load flags parameter for future expension? */
gboolean
gtk_source_file_load (GtkSourceFile *file,
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index ddeee02..d77ec9e 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -114,6 +114,11 @@ GtkSourceCompressionType gtk_source_file_get_compression_type (GtkSourceFile
*
void gtk_source_file_set_compression_type (GtkSourceFile *file,
GtkSourceCompressionType compression_type);
+gboolean gtk_source_file_get_ensure_trailing_newline (GtkSourceFile *file);
+
+void gtk_source_file_set_ensure_trailing_newline (GtkSourceFile *file,
+ gboolean
ensure_trailing_newline);
+
gboolean gtk_source_file_load (GtkSourceFile *file,
GCancellable *cancellable,
GFileProgressCallback progress_callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]