[gtksourceview/wip/loader-saver] FileSaver: boring getters and setters
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver] FileSaver: boring getters and setters
- Date: Sat, 29 Mar 2014 14:30:28 +0000 (UTC)
commit 578e2ccb98426e9e997d5113c5d93c71ed8fc571
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Mar 29 15:29:41 2014 +0100
FileSaver: boring getters and setters
gtksourceview/gtksourcefilesaver.c | 252 +++++++++++++++++++++++++++++++++--
gtksourceview/gtksourcefilesaver.h | 35 +++++
2 files changed, 272 insertions(+), 15 deletions(-)
---
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 05aa81c..1ce7ed4 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -135,33 +135,23 @@ gtk_source_file_saver_set_property (GObject *object,
break;
case PROP_ENCODING:
- g_return_if_fail (saver->priv->task == NULL);
- saver->priv->encoding = g_value_get_boxed (value);
- if (saver->priv->encoding == NULL)
- {
- /* FIXME ok? */
- saver->priv->encoding = gtk_source_encoding_get_utf8 ();
- }
+ gtk_source_file_saver_set_encoding (saver, g_value_get_boxed (value));
break;
case PROP_NEWLINE_TYPE:
- g_return_if_fail (saver->priv->task == NULL);
- saver->priv->newline_type = g_value_get_enum (value);
+ gtk_source_file_saver_set_newline_type (saver, g_value_get_enum (value));
break;
case PROP_COMPRESSION_TYPE:
- g_return_if_fail (saver->priv->task == NULL);
- saver->priv->compression_type = g_value_get_enum (value);
+ gtk_source_file_saver_set_compression_type (saver, g_value_get_enum (value));
break;
case PROP_ENSURE_TRAILING_NEWLINE:
- g_return_if_fail (saver->priv->task == NULL);
- saver->priv->ensure_trailing_newline = g_value_get_boolean (value);
+ gtk_source_file_saver_set_ensure_trailing_newline (saver, g_value_get_boolean
(value));
break;
case PROP_CREATE_BACKUP:
- g_return_if_fail (saver->priv->task == NULL);
- saver->priv->create_backup = g_value_get_boolean (value);
+ gtk_source_file_saver_set_create_backup (saver, g_value_get_boolean (value));
break;
default:
@@ -841,6 +831,238 @@ gtk_source_file_saver_new (GtkSourceBuffer *buffer,
}
/**
+ * gtk_source_file_saver_get_buffer:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: (transfer none): the #GtkSourceBuffer to save.
+ * Since: 3.14
+ */
+GtkSourceBuffer *
+gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
+
+ return saver->priv->source_buffer;
+}
+
+/**
+ * gtk_source_file_saver_get_file:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: (transfer none): the #GFile where to save the buffer to.
+ * Since: 3.14
+ */
+GFile *
+gtk_source_file_saver_get_file (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
+
+ return saver->priv->file;
+}
+
+/**
+ * gtk_source_file_saver_set_encoding:
+ * @saver: a #GtkSourceFileSaver.
+ * @encoding: (allow-none): the new encoding, or %NULL for UTF-8.
+ *
+ * Changes the #GtkSourceFileSaver:file encoding that will be used for the next
+ * file saving. If @encoding is %NULL, the UTF-8 encoding will be set.
+ *
+ * Note that a #GtkSourceBuffer has always a UTF-8 encoding.
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_file_saver_set_encoding (GtkSourceFileSaver *saver,
+ const GtkSourceEncoding *encoding)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (saver->priv->task == NULL);
+
+ if (encoding == NULL)
+ {
+ encoding = gtk_source_encoding_get_utf8 ();
+ }
+
+ if (saver->priv->encoding != encoding)
+ {
+ saver->priv->encoding = encoding;
+ g_object_notify (G_OBJECT (saver), "encoding");
+ }
+}
+
+/**
+ * gtk_source_file_saver_get_encoding:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: the encoding.
+ * Since: 3.14
+ */
+const GtkSourceEncoding *
+gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
+
+ return saver->priv->encoding;
+}
+
+/**
+ * gtk_source_file_saver_set_newline_type:
+ * @saver: a #GtkSourceFileSaver.
+ * @newline_type: the new newline type.
+ *
+ * Changes the #GtkSourceFileSaver:file newline type that will be used for the
+ * next file saving. It doesn't change the newline type of the
+ * #GtkSourceFileSaver:buffer.
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_file_saver_set_newline_type (GtkSourceFileSaver *saver,
+ GtkSourceNewlineType newline_type)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (saver->priv->task == NULL);
+
+ if (saver->priv->newline_type != newline_type)
+ {
+ saver->priv->newline_type = newline_type;
+ g_object_notify (G_OBJECT (saver), "newline-type");
+ }
+}
+
+/**
+ * gtk_source_file_saver_get_newline_type:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: the newline type.
+ * Since: 3.14
+ */
+GtkSourceNewlineType
+gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
+
+ return saver->priv->newline_type;
+}
+
+/**
+ * gtk_source_file_saver_set_compression_type:
+ * @saver: a #GtkSourceFileSaver.
+ * @compression_type: the new compression type.
+ *
+ * Changes the #GtkSourceFileSaver:file compression type that will be used for
+ * the next file saving.
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_file_saver_set_compression_type (GtkSourceFileSaver *saver,
+ GtkSourceCompressionType compression_type)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (saver->priv->task == NULL);
+
+ if (saver->priv->compression_type != compression_type)
+ {
+ saver->priv->compression_type = compression_type;
+ g_object_notify (G_OBJECT (saver), "compression-type");
+ }
+}
+
+/**
+ * gtk_source_file_saver_get_compression_type:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: the compression type.
+ * Since: 3.14
+ */
+GtkSourceCompressionType
+gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_COMPRESSION_TYPE_NONE);
+
+ return saver->priv->compression_type;
+}
+
+/**
+ * gtk_source_file_saver_set_ensure_trailing_newline:
+ * @saver: a #GtkSourceFileSaver.
+ * @ensure_trailing_newline: whether the file should end with a trailing
+ * newline.
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_file_saver_set_ensure_trailing_newline (GtkSourceFileSaver *saver,
+ gboolean ensure_trailing_newline)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (saver->priv->task == NULL);
+
+ ensure_trailing_newline = ensure_trailing_newline != FALSE;
+
+ if (saver->priv->ensure_trailing_newline != ensure_trailing_newline)
+ {
+ saver->priv->ensure_trailing_newline = ensure_trailing_newline;
+ g_object_notify (G_OBJECT (saver), "ensure-trailing-newline");
+ }
+}
+
+/**
+ * gtk_source_file_saver_get_ensure_trailing_newline:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: whether the file should end with a trailing newline.
+ * Since: 3.14
+ */
+gboolean
+gtk_source_file_saver_get_ensure_trailing_newline (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), TRUE);
+
+ return saver->priv->ensure_trailing_newline;
+}
+
+/**
+ * gtk_source_file_saver_set_create_backup:
+ * @saver: a #GtkSourceFileSaver.
+ * @create_backup: whether to create a backup before saving the file.
+ *
+ * Since: 3.14
+ */
+void
+gtk_source_file_saver_set_create_backup (GtkSourceFileSaver *saver,
+ gboolean create_backup)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (saver->priv->task == NULL);
+
+ create_backup = create_backup != FALSE;
+
+ if (saver->priv->create_backup != create_backup)
+ {
+ saver->priv->create_backup = create_backup;
+ g_object_notify (G_OBJECT (saver), "create-backup");
+ }
+}
+
+/**
+ * gtk_source_file_saver_get_create_backup:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: whether to create a backup before saving the file.
+ * Since: 3.14
+ */
+gboolean
+gtk_source_file_saver_get_create_backup (GtkSourceFileSaver *saver)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), FALSE);
+
+ return saver->priv->create_backup;
+}
+
+/**
* gtk_source_file_saver_save_async:
* @saver: a #GtkSourceFileSaver.
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index fdcb5b8..2649310 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -58,6 +58,41 @@ GType gtk_source_file_saver_get_type (void) G_GNUC_CONST;
GtkSourceFileSaver *gtk_source_file_saver_new (GtkSourceBuffer *buffer,
GFile *file);
+GtkSourceBuffer *gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver);
+
+GFile *gtk_source_file_saver_get_file (GtkSourceFileSaver *saver);
+
+void gtk_source_file_saver_set_encoding (GtkSourceFileSaver *saver,
+ const GtkSourceEncoding *encoding);
+
+const GtkSourceEncoding *gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver);
+
+void gtk_source_file_saver_set_newline_type (GtkSourceFileSaver *saver,
+ GtkSourceNewlineType newline_type);
+
+GtkSourceNewlineType gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver);
+
+void gtk_source_file_saver_set_compression_type
+ (GtkSourceFileSaver *saver,
+ GtkSourceCompressionType compression_type);
+
+GtkSourceCompressionType gtk_source_file_saver_get_compression_type
+ (GtkSourceFileSaver *saver);
+
+void gtk_source_file_saver_set_ensure_trailing_newline
+ (GtkSourceFileSaver *saver,
+ gboolean
ensure_trailing_newline);
+
+gboolean gtk_source_file_saver_get_ensure_trailing_newline
+ (GtkSourceFileSaver *saver);
+
+void gtk_source_file_saver_set_create_backup
+ (GtkSourceFileSaver *saver,
+ gboolean create_backup);
+
+gboolean gtk_source_file_saver_get_create_backup
+ (GtkSourceFileSaver *saver);
+
void gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
gint io_priority,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]