[gedit/wip/reusable-code] DocumentSaver: weaker dependency to Document and GSettings



commit 594233aa4d1cf08a2c99c4028cfa749f9f485a40
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 16 18:04:29 2013 +0200

    DocumentSaver: weaker dependency to Document and GSettings
    
    GSettings is still needed for another thing.

 gedit/gedit-document-saver.c |   20 ++++----------------
 gedit/gedit-document.c       |    9 +++++++++
 2 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index 3653cd2..24f333d 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -94,7 +94,7 @@ struct _GeditDocumentSaverPrivate
 
        GeditDocumentSaveFlags    flags;
 
-       gboolean                  keep_backup;
+       gboolean                  make_backup;
 
        GTimeVal                  old_mtime;
 
@@ -813,7 +813,6 @@ static void
 begin_write (AsyncData *async)
 {
        GeditDocumentSaver *saver;
-       gboolean backup;
 
        DEBUG ({
               g_print ("Start replacing file contents\n");
@@ -824,9 +823,6 @@ begin_write (AsyncData *async)
         */
        saver = async->saver;
 
-       /* Do not make backups for remote files so they do not clutter remote systems */
-       backup = (saver->priv->keep_backup && gedit_document_is_local (saver->priv->document));
-
        DEBUG ({
               g_print ("File contents size: %" G_GINT64_FORMAT "\n", saver->priv->size);
               g_print ("Calling replace_async\n");
@@ -835,7 +831,7 @@ begin_write (AsyncData *async)
 
        g_file_replace_async (saver->priv->location,
                              NULL,
-                             backup,
+                             saver->priv->make_backup,
                              G_FILE_CREATE_NONE,
                              G_PRIORITY_HIGH,
                              async->cancellable,
@@ -1033,16 +1029,8 @@ gedit_document_saver_save (GeditDocumentSaver *saver,
         report async (in an idle handler) or sync (bool ret)
         async is extra work here, sync is special casing in the caller */
 
-       /* never keep backup of autosaves */
-       if ((saver->priv->flags & GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP) != 0)
-       {
-               saver->priv->keep_backup = FALSE;
-       }
-       else
-       {
-               saver->priv->keep_backup = g_settings_get_boolean (saver->priv->editor_settings,
-                                                                  GEDIT_SETTINGS_CREATE_BACKUP_COPY);
-       }
+       saver->priv->make_backup = (saver->priv->flags & GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP) == 0 &&
+                                  (saver->priv->flags & GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP) == 0;
 
        saver->priv->old_mtime = *old_mtime;
 
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index b1d8aa7..f9e1b88 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1815,6 +1815,15 @@ gedit_document_save_real (GeditDocument                *doc,
        }
        else
        {
+               /* Do not make backups for remote files so they do not clutter
+                * remote systems. */
+               if (!gedit_document_is_local (doc) ||
+                   !g_settings_get_boolean (doc->priv->editor_settings,
+                                            GEDIT_SETTINGS_CREATE_BACKUP_COPY))
+               {
+                       flags |= GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP;
+               }
+
                /* create a saver, it will be destroyed once saving is complete */
                doc->priv->saver = gedit_document_saver_new (doc,
                                                             location,


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