[gtksourceview/wip/loader-saver] File: add an mtime attribute



commit 1c590e26b40cdcee7a9167f2e3c641fd4c9370d0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 26 23:20:41 2013 +0100

    File: add an mtime attribute

 gtksourceview/gtksourcefile.c      |   20 +++++++++++++++++++-
 gtksourceview/gtksourcefilesaver.c |   19 +++++--------------
 2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 4369472..0e3268d 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -46,6 +46,12 @@ struct _GtkSourceFilePrivate
 
        GtkSourceFileSaver *saver;
 
+       /* The time when the file was last modified, from our point of view. The
+        * file may be externally modified.
+        */
+       GTimeVal mtime;
+
+       guint mtime_set : 1;
        guint ensure_trailing_newline : 1;
 };
 
@@ -420,6 +426,8 @@ gtk_source_file_save_async (GtkSourceFile          *file,
                            GAsyncReadyCallback     callback,
                            gpointer                user_data)
 {
+       GTimeVal *mtime;
+
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
        if (file->priv->saver != NULL)
@@ -436,6 +444,16 @@ gtk_source_file_save_async (GtkSourceFile          *file,
                return;
        }
 
+       if (file->priv->mtime_set)
+       {
+               mtime = &file->priv->mtime;
+       }
+       else
+       {
+               mtime = NULL;
+               flags |= GTK_SOURCE_FILE_SAVE_IGNORE_MTIME;
+       }
+
        file->priv->saver = gtk_source_file_saver_new (GTK_TEXT_BUFFER (file->priv->buffer),
                                                       file->priv->location,
                                                       file->priv->encoding,
@@ -447,7 +465,7 @@ gtk_source_file_save_async (GtkSourceFile          *file,
        gtk_source_file_saver_save_async (file->priv->saver,
                                          file,
                                          io_priority,
-                                         NULL,
+                                         mtime,
                                          cancellable,
                                          progress_callback,
                                          progress_callback_data,
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index a159abd..2896f5c 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -756,7 +756,9 @@ check_externally_modified_cb (GFile              *location,
 
        if (error != NULL)
        {
-               if (error->code == G_IO_ERROR_NOT_MOUNTED && !saver->priv->tried_mount)
+               if (error->domain == G_IO_ERROR &&
+                   error->code == G_IO_ERROR_NOT_MOUNTED &&
+                   !saver->priv->tried_mount)
                {
                        recover_not_mounted (saver);
                        g_error_free (error);
@@ -856,19 +858,6 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
        saver->priv->task = g_task_new (file, cancellable, callback, user_data);
        g_task_set_priority (saver->priv->task, io_priority);
 
-       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;
 
@@ -882,6 +871,8 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
        }
        else
        {
+               g_return_if_fail (old_mtime != NULL);
+               saver->priv->old_mtime = *old_mtime;
                check_externally_modified (saver);
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]