[gtksourceview/wip/loader-saver: 1/2] File and FileSaver: fixes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver: 1/2] File and FileSaver: fixes
- Date: Fri, 20 Dec 2013 05:07:35 +0000 (UTC)
commit aa28bdaad94256737aad59336bf9980d3ee5e422
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Dec 18 16:05:42 2013 +0100
File and FileSaver: fixes
gtksourceview/gtksourcefile.c | 16 ++++++++-----
gtksourceview/gtksourcefilesaver.c | 41 ++++++++++++++++-------------------
2 files changed, 29 insertions(+), 28 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index fb6ab35..456ec41 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -111,14 +111,12 @@ gtk_source_file_set_property (GObject *object,
{
case PROP_LOCATION:
g_assert (file->priv->location == NULL);
- file->priv->location = g_value_get_object (value);
- g_object_ref (file->priv->location);
+ file->priv->location = g_value_dup_object (value);
break;
case PROP_BUFFER:
g_assert (file->priv->buffer == NULL);
- file->priv->buffer = g_value_get_object (value);
- g_object_ref (file->priv->buffer);
+ file->priv->buffer = g_value_dup_object (value);
break;
case PROP_ENCODING:
@@ -264,7 +262,7 @@ gtk_source_file_get_location (GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
- return file->priv->location;
+ return g_object_ref (file->priv->location);
}
GtkSourceBuffer *
@@ -463,9 +461,15 @@ gtk_source_file_save_finish (GtkSourceFile *file,
GAsyncResult *result,
GError **error)
{
+ gboolean ok;
+
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (file->priv->saver != NULL, FALSE);
- return gtk_source_file_saver_save_finish (file->priv->saver, result, error);
+ ok = gtk_source_file_saver_save_finish (file->priv->saver, result, error);
+
+ g_clear_object (&file->priv->saver);
+
+ return ok;
}
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 1b379a6..b6449a4 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -106,8 +106,6 @@ struct _GtkSourceFileSaverPrivate
GtkSourceMountOperationFactory mount_operation_factory;
gpointer mount_operation_userdata;
- /* FIXME is used used? */
- guint used : 1;
guint ensure_trailing_newline : 1;
guint tried_mount : 1;
};
@@ -141,6 +139,10 @@ gtk_source_file_saver_set_property (GObject *object,
case PROP_ENCODING:
g_assert (saver->priv->encoding == NULL);
saver->priv->encoding = g_value_get_boxed (value);
+ if (saver->priv->encoding == NULL)
+ {
+ saver->priv->encoding = gtk_source_encoding_get_utf8 ();
+ }
break;
case PROP_NEWLINE_TYPE:
@@ -324,12 +326,7 @@ gtk_source_file_saver_new (GtkTextBuffer *buffer,
gboolean ensure_trailing_newline)
{
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
-
- /* TODO move this code to set_property() */
- if (encoding == NULL)
- {
- encoding = gtk_source_encoding_get_utf8 ();
- }
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
return g_object_new (GTK_SOURCE_TYPE_FILE_SAVER,
"buffer", buffer,
@@ -920,7 +917,7 @@ gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
- return g_file_dup (saver->priv->location);
+ return g_object_ref (saver->priv->location);
}
void
@@ -946,15 +943,23 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
{
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
g_return_if_fail (saver->priv->task == NULL);
- g_return_if_fail (saver->priv->location != NULL);
- g_return_if_fail (!saver->priv->used);
-
- saver->priv->used = TRUE;
saver->priv->task = g_task_new (saver, cancellable, callback, user_data);
g_task_set_priority (saver->priv->task, io_priority);
- saver->priv->old_mtime = *old_mtime;
+ if (old_mtime != NULL)
+ {
+ saver->priv->old_mtime = *old_mtime;
+ }
+ else
+ {
+ /* FIXME hacky temporary solution.
+ * Install a FileMonitor in GtkSourceFile, with an
+ * externally-modified property, or a signal.
+ */
+ saver->priv->flags |= GTK_SOURCE_FILE_SAVE_IGNORE_MTIME;
+ }
+
saver->priv->progress_cb = progress_callback;
saver->priv->progress_cb_data = progress_callback_data;
@@ -962,20 +967,12 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
g_print ("Starting save\n");
});
- /* TODO create a thread and use sync GIO functions for the first steps.
- * Destroy the thread for the main step, reading the buffer and writing
- * the file. Because the buffer must be read in the main thread.
- */
-
if (saver->priv->flags & GTK_SOURCE_FILE_SAVE_IGNORE_MTIME)
{
begin_write (saver);
}
else
{
- /* TODO install a FileMonitor in GtkSourceFile, with an
- * externally-modified property, or a signal.
- */
check_externally_modified (saver);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]