[gtksourceview/wip/loader-saver] File and FileSaver: some clean-up



commit 256ddc417dafe6fb804799bd63357cbaaa272c32
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Dec 28 17:59:40 2013 +0100

    File and FileSaver: some clean-up

 gtksourceview/gtksourcefile.h      |   45 ++++++++++++++++++++----------------
 gtksourceview/gtksourcefilesaver.c |    7 +----
 2 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index 08717e2..352a139 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -47,6 +47,7 @@ typedef enum
 /* NOTE: when adding a new compression type, make sure to update:
  *   1) The buffer loader to support it
  *   2) gedit_document_compression_type_for_display
+ * TODO update this comment when finished
  */
 
 /**
@@ -65,21 +66,23 @@ typedef enum
 /**
  * GtkSourceFileSaveFlags:
  * @GTK_SOURCE_FILE_SAVE_IGNORE_MTIME: save file despite external modifications.
- * @GTK_SOURCE_FILE_SAVE_IGNORE_BACKUP: write the file directly without attempting to backup.
- * @GTK_SOURCE_FILE_SAVE_PRESERVE_BACKUP: preserve previous backup file, needed to support autosaving.
+ * @GTK_SOURCE_FILE_SAVE_CREATE_BACKUP: create a backup before saving the file.
  * @GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS: do not save invalid characters.
+ *
+ * FIXME ignore invalid chars is not yet used in gsv
+ *
+ * Since: 3.12
  */
-/* FIXME: merge IGNORE_BACKUP and PRESERVE_BACKUP? */
 typedef enum
 {
        GTK_SOURCE_FILE_SAVE_IGNORE_MTIME               = 1 << 0,
-       GTK_SOURCE_FILE_SAVE_IGNORE_BACKUP              = 1 << 1,
-       GTK_SOURCE_FILE_SAVE_PRESERVE_BACKUP            = 1 << 2,
-       GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS       = 1 << 3
+       GTK_SOURCE_FILE_SAVE_CREATE_BACKUP              = 1 << 1,
+       GTK_SOURCE_FILE_SAVE_IGNORE_INVALID_CHARS       = 1 << 2
 } GtkSourceFileSaveFlags;
 
 #define GTK_SOURCE_FILE_ERROR gtk_source_file_error_quark ()
 
+/* TODO check if these errors are used, and document them. */
 enum
 {
        GTK_SOURCE_FILE_ERROR_EXTERNALLY_MODIFIED,
@@ -105,32 +108,34 @@ GType                      gtk_source_file_get_type               (void) G_GNUC_CONST;
 
 GQuark                  gtk_source_file_error_quark            (void);
 
-GtkSourceFile          *gtk_source_file_new                    (GFile                   *location,
-                                                                GtkSourceBuffer         *buffer);
+GtkSourceFile          *gtk_source_file_new                    (GFile                    *location,
+                                                                GtkSourceBuffer          *buffer);
 
-GFile                  *gtk_source_file_get_location           (GtkSourceFile           *file);
+GFile                  *gtk_source_file_get_location           (GtkSourceFile            *file);
 
-GtkSourceBuffer                *gtk_source_file_get_buffer             (GtkSourceFile           *file);
+GtkSourceBuffer                *gtk_source_file_get_buffer             (GtkSourceFile            *file);
 
-const GtkSourceEncoding        *gtk_source_file_get_encoding           (GtkSourceFile           *file);
+const GtkSourceEncoding        *gtk_source_file_get_encoding           (GtkSourceFile            *file);
 
-void                    gtk_source_file_set_encoding           (GtkSourceFile           *file,
-                                                                const GtkSourceEncoding *encoding);
+void                    gtk_source_file_set_encoding           (GtkSourceFile            *file,
+                                                                const GtkSourceEncoding  *encoding);
 
-GtkSourceNewlineType    gtk_source_file_get_newline_type       (GtkSourceFile           *file);
+GtkSourceNewlineType    gtk_source_file_get_newline_type       (GtkSourceFile            *file);
 
-void                    gtk_source_file_set_newline_type       (GtkSourceFile           *file,
-                                                                GtkSourceNewlineType     newline_type);
+void                    gtk_source_file_set_newline_type       (GtkSourceFile            *file,
+                                                                GtkSourceNewlineType      newline_type);
 
-GtkSourceCompressionType gtk_source_file_get_compression_type  (GtkSourceFile           *file);
+GtkSourceCompressionType gtk_source_file_get_compression_type  (GtkSourceFile            *file);
 
 void                    gtk_source_file_set_compression_type   (GtkSourceFile            *file,
                                                                 GtkSourceCompressionType  compression_type);
 
-gboolean                gtk_source_file_get_ensure_trailing_newline    (GtkSourceFile    *file);
+gboolean                gtk_source_file_get_ensure_trailing_newline
+                                                               (GtkSourceFile            *file);
 
-void                    gtk_source_file_set_ensure_trailing_newline    (GtkSourceFile    *file,
-                                                                        gboolean          
ensure_trailing_newline);
+void                    gtk_source_file_set_ensure_trailing_newline
+                                                               (GtkSourceFile            *file,
+                                                                gboolean                  
ensure_trailing_newline);
 
 gboolean                gtk_source_file_load                   (GtkSourceFile            *file,
                                                                 GCancellable             *cancellable,
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 5f616cd..a3d8362 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -684,10 +684,7 @@ replace_file_cb (GFile              *location,
 static void
 begin_write (GtkSourceFileSaver *saver)
 {
-       gboolean make_backup;
-
-       make_backup = (saver->priv->flags & GTK_SOURCE_FILE_SAVE_IGNORE_BACKUP) == 0 &&
-                     (saver->priv->flags & GTK_SOURCE_FILE_SAVE_PRESERVE_BACKUP) == 0;
+       gboolean create_backup = (saver->priv->flags & GTK_SOURCE_FILE_SAVE_CREATE_BACKUP) != 0;
 
        DEBUG ({
               g_print ("Start replacing file contents\n");
@@ -696,7 +693,7 @@ begin_write (GtkSourceFileSaver *saver)
 
        g_file_replace_async (saver->priv->location,
                              NULL,
-                             make_backup,
+                             create_backup,
                              G_FILE_CREATE_NONE,
                              g_task_get_priority (saver->priv->task),
                              g_task_get_cancellable (saver->priv->task),


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