[gtksourceview/wip/loader-saver] File and FileSaver: fixes



commit f926abad8879c3ace6e44904300f91f8cf174142
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Dec 18 16:05:42 2013 +0100

    File and FileSaver: fixes

 gtksourceview/gtksourcefile.c      |    8 ++++++-
 gtksourceview/gtksourcefilesaver.c |   39 ++++++++++++++++-------------------
 2 files changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index fb6ab35..c27159c 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -463,9 +463,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..a5cecfd 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,
@@ -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]