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



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

    File and FileSaver: fixes

 gtksourceview/gtksourcefile.c      |   10 +++++++-
 gtksourceview/gtksourcefilesaver.c |   39 ++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 23 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index fb6ab35..362b6e5 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -264,7 +264,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_file_dup (file->priv->location);
 }
 
 GtkSourceBuffer *
@@ -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]