[gtksourceview/wip/loader-saver: 2/2] File: use the FileSaver



commit e0dc8ef684a35324db63334aff324242de217243
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Dec 17 17:01:45 2013 +0100

    File: use the FileSaver

 gtksourceview/gtksourcefile.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 13a619e..fb6ab35 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -20,6 +20,7 @@
  */
 
 #include "gtksourcefile.h"
+#include "gtksourcefilesaver.h"
 #include "gtksourcebuffer.h"
 #include "gtksourceencoding.h"
 #include "gtksourceview-typebuiltins.h"
@@ -43,6 +44,8 @@ struct _GtkSourceFilePrivate
        GtkSourceNewlineType newline_type;
        GtkSourceCompressionType compression_type;
 
+       GtkSourceFileSaver *saver;
+
        guint ensure_trailing_newline : 1;
 };
 
@@ -420,6 +423,39 @@ gtk_source_file_save_async (GtkSourceFile          *file,
                            gpointer                user_data)
 {
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->saver != NULL)
+       {
+               if (cancellable != NULL)
+               {
+                       /* FIXME create another saver? */
+                       g_cancellable_cancel (cancellable);
+                       return;
+               }
+               else
+               {
+                       g_warning ("Another save operation is already running on the file \"%s\".",
+                                  g_file_get_parse_name (file->priv->location));
+                       return;
+               }
+       }
+
+       file->priv->saver = gtk_source_file_saver_new (GTK_TEXT_BUFFER (file->priv->buffer),
+                                                      file->priv->location,
+                                                      file->priv->encoding,
+                                                      file->priv->newline_type,
+                                                      file->priv->compression_type,
+                                                      flags,
+                                                      file->priv->ensure_trailing_newline);
+
+       gtk_source_file_saver_save_async (file->priv->saver,
+                                         io_priority,
+                                         NULL,
+                                         cancellable,
+                                         progress_callback,
+                                         progress_callback_data,
+                                         callback,
+                                         user_data);
 }
 
 gboolean
@@ -429,6 +465,7 @@ gtk_source_file_save_finish (GtkSourceFile  *file,
 {
        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 TRUE;
+       return gtk_source_file_saver_save_finish (file->priv->saver, result, error);
 }


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