[gtksourceview/wip/loader-saver: 5/5] FileSaver: do not depend on GtkSourceFile (not finished)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver: 5/5] FileSaver: do not depend on GtkSourceFile (not finished)
- Date: Sun, 16 Mar 2014 18:42:53 +0000 (UTC)
commit 70368c5caa3a1e97b5610896816776250577b9c2
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Mar 14 18:55:41 2014 +0100
FileSaver: do not depend on GtkSourceFile (not finished)
gtksourceview/gtksourcefilesaver.c | 128 ++++++++++++++++++++++++++---------
gtksourceview/gtksourcefilesaver.h | 16 +----
2 files changed, 98 insertions(+), 46 deletions(-)
---
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 73cf2b0..9954c01 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -49,24 +49,32 @@
enum
{
PROP_0,
+ PROP_BUFFER,
PROP_FILE,
PROP_ENCODING,
PROP_NEWLINE_TYPE,
PROP_COMPRESSION_TYPE,
PROP_ENSURE_TRAILING_NEWLINE,
+
+ /* TODO split flags */
PROP_FLAGS
};
struct _GtkSourceFileSaverPrivate
{
- GtkSourceFile *file;
+ /* Weak reference to the source_buffer. A subclass of GtkSourceBuffer
+ * can have the ownership of the FileSaver. And a FileSaver can be used
+ * several times, so the object can be kept around until the subclass of
+ * GtkSourceBuffer is disposed.
+ */
+ GtkSourceBuffer *source_buffer;
+ GFile *file;
+
const GtkSourceEncoding *encoding;
GtkSourceNewlineType newline_type;
GtkSourceCompressionType compression_type;
GtkSourceFileSaveFlags flags;
- GTimeVal old_mtime;
-
GTask *task;
/* This field is used when cancelling the output stream: an error occurs
@@ -112,16 +120,22 @@ gtk_source_file_saver_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_BUFFER:
+ g_assert (saver->priv->source_buffer == NULL);
+ saver->priv->source_buffer = g_value_get_object (value);
+ /* TODO weak reference to the source_buffer */
+ break;
+
case PROP_FILE:
g_assert (saver->priv->file == NULL);
- saver->priv->file = g_value_get_object (value);
+ saver->priv->file = g_value_dup_object (value);
break;
case PROP_ENCODING:
- g_assert (saver->priv->encoding == NULL);
saver->priv->encoding = g_value_get_boxed (value);
if (saver->priv->encoding == NULL)
{
+ /* FIXME ok? */
saver->priv->encoding = gtk_source_encoding_get_utf8 ();
}
break;
@@ -150,14 +164,18 @@ gtk_source_file_saver_set_property (GObject *object,
static void
gtk_source_file_saver_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
switch (prop_id)
{
+ case PROP_BUFFER:
+ g_value_set_object (value, saver->priv->source_buffer);
+ break;
+
case PROP_FILE:
g_value_set_object (value, saver->priv->file);
break;
@@ -193,14 +211,13 @@ gtk_source_file_saver_dispose (GObject *object)
{
GtkSourceFileSaverPrivate *priv = GTK_SOURCE_FILE_SAVER (object)->priv;
+ g_clear_object (&priv->file);
g_clear_object (&priv->output_stream);
g_clear_object (&priv->input_stream);
g_clear_object (&priv->task);
g_clear_object (&priv->info);
g_clear_error (&priv->error);
- priv->file = NULL;
-
G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->dispose (object);
}
@@ -213,56 +230,108 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
object_class->set_property = gtk_source_file_saver_set_property;
object_class->get_property = gtk_source_file_saver_get_property;
+ /**
+ * GtkSourceFileSaver:buffer:
+ *
+ * The #GtkSourceBuffer to save.
+ *
+ * Since: 3.14
+ */
+ g_object_class_install_property (object_class,
+ PROP_BUFFER,
+ g_param_spec_object ("buffer",
+ "GtkSourceBuffer",
+ NULL,
+ GTK_SOURCE_TYPE_BUFFER,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GtkSourceFileSaver:file:
+ *
+ * The #GFile where to save the buffer.
+ *
+ * Since: 3.14
+ */
g_object_class_install_property (object_class,
PROP_FILE,
g_param_spec_object ("file",
- "File",
- "The associated GtkSourceFile",
- GTK_SOURCE_TYPE_FILE,
+ "GFile",
+ NULL,
+ G_TYPE_FILE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceFileSaver:encoding:
+ *
+ * The file's encoding.
+ *
+ * Since: 3.14
+ */
g_object_class_install_property (object_class,
PROP_ENCODING,
g_param_spec_boxed ("encoding",
- "Encoding",
- "The encoding of the saved file",
+ "GtkSourceEncoding",
+ NULL,
GTK_SOURCE_TYPE_ENCODING,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceFileSaver:newline-type:
+ *
+ * The newline type.
+ *
+ * Since: 3.14
+ */
g_object_class_install_property (object_class,
PROP_NEWLINE_TYPE,
g_param_spec_enum ("newline-type",
- "Newline type",
- "The type of line ending",
+ _("Newline type"),
+ NULL,
GTK_SOURCE_TYPE_NEWLINE_TYPE,
GTK_SOURCE_NEWLINE_TYPE_LF,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceFileSaver:compression-type:
+ *
+ * The compression type.
+ *
+ * Since: 3.14
+ */
g_object_class_install_property (object_class,
PROP_COMPRESSION_TYPE,
g_param_spec_enum ("compression-type",
- "Compression type",
- "The compression type",
+ _("Compression type"),
+ NULL,
GTK_SOURCE_TYPE_COMPRESSION_TYPE,
GTK_SOURCE_COMPRESSION_TYPE_NONE,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceFileSaver:ensure-trailing-newline:
+ *
+ * Ensure the file ends with a trailing newline.
+ *
+ * Since: 3.14
+ */
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",
+ _("Ensure Trailing Newline"),
+ NULL,
TRUE,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
@@ -359,6 +428,7 @@ query_info_cb (GFile *location,
g_print ("Finished query info on file\n");
});
+ /* TODO update mtime stored in GtkSourceBuffer */
g_clear_object (&saver->priv->info);
saver->priv->info = g_file_query_info_finish (location, result, &error);
@@ -786,11 +856,3 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
return g_task_propagate_boolean (G_TASK (result), error);
}
-
-GFileInfo *
-gtk_source_file_saver_get_info (GtkSourceFileSaver *saver)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
-
- return saver->priv->info;
-}
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index 46952de..4984cf0 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -44,16 +44,12 @@ typedef struct _GtkSourceFileSaverPrivate GtkSourceFileSaverPrivate;
/**
* GtkSourceFileSaveFlags:
* @GTK_SOURCE_FILE_SAVE_CREATE_BACKUP: create a backup before saving the file.
- * @GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS: do not save invalid characters.
- *
- * FIXME ignore invalid chars is not yet used in gsv
*
* Since: 3.14
*/
typedef enum
{
- GTK_SOURCE_FILE_SAVE_CREATE_BACKUP = 1 << 0,
- GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS = 1 << 1
+ GTK_SOURCE_FILE_SAVE_CREATE_BACKUP = 1 << 0
} GtkSourceFileSaveFlags;
struct _GtkSourceFileSaver
@@ -70,12 +66,8 @@ struct _GtkSourceFileSaverClass
GType gtk_source_file_saver_get_type (void) G_GNUC_CONST;
-GtkSourceFileSaver *gtk_source_file_saver_new (GtkSourceFile *file,
- const GtkSourceEncoding *encoding,
- GtkSourceNewlineType newline_type,
- GtkSourceCompressionType compression_type,
- gboolean
ensure_trailing_newline,
- GtkSourceFileSaveFlags flags);
+GtkSourceFileSaver *gtk_source_file_saver_new (GtkSourceBuffer *buffer,
+ GFile *file);
void gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
gint io_priority,
@@ -89,8 +81,6 @@ gboolean gtk_source_file_saver_save_finish (GtkSourceFileSaver
*saver,
GAsyncResult *result,
GError **error);
-GFileInfo *gtk_source_file_saver_get_info (GtkSourceFileSaver *saver);
-
G_END_DECLS
#endif /* __GTK_SOURCE_FILE_SAVER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]