[gtksourceview/wip/loader-saver: 28/28] Move the buffer property to the FileLoader and FileSaver



commit d1c703c6f30c3cb7f6c4bea336336655fdd24332
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 5 14:00:01 2014 +0200

    Move the buffer property to the FileLoader and FileSaver

 docs/reference/gtksourceview-3.0-sections.txt |    3 +-
 gtksourceview/gtksourcefile.c                 |   71 +------------------
 gtksourceview/gtksourcefile.h                 |    4 +-
 gtksourceview/gtksourcefileloader.c           |   95 ++++++++++++++++++++-----
 gtksourceview/gtksourcefileloader.h           |    9 ++-
 gtksourceview/gtksourcefilesaver.c            |   85 ++++++++++++++++++----
 gtksourceview/gtksourcefilesaver.h            |    6 +-
 tests/test-file-loader.c                      |    8 +--
 tests/test-file-saver.c                       |    4 +-
 9 files changed, 169 insertions(+), 116 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 16bde97..c016477 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -238,7 +238,6 @@ GtkSourceCompressionType
 GtkSourceMountOperationFactory
 <SUBSECTION>
 gtk_source_file_new
-gtk_source_file_get_buffer
 gtk_source_file_get_location
 gtk_source_file_set_location
 gtk_source_file_get_encoding
@@ -267,6 +266,7 @@ GtkSourceFileLoaderError
 gtk_source_file_loader_new
 gtk_source_file_loader_new_from_stream
 gtk_source_file_loader_set_candidate_encodings
+gtk_source_file_loader_get_buffer
 gtk_source_file_loader_get_file
 gtk_source_file_loader_get_location
 gtk_source_file_loader_get_input_stream
@@ -296,6 +296,7 @@ GtkSourceFileSaverError
 GtkSourceFileSaverFlags
 <SUBSECTION>
 gtk_source_file_saver_new
+gtk_source_file_saver_get_buffer
 gtk_source_file_saver_get_file
 gtk_source_file_saver_get_location
 gtk_source_file_saver_set_encoding
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 3cde450..08195ba 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -20,7 +20,6 @@
  */
 
 #include "gtksourcefile.h"
-#include "gtksourcebuffer.h"
 #include "gtksourceencoding.h"
 #include "gtksourceview-typebuiltins.h"
 #include "gtksourceview-i18n.h"
@@ -29,7 +28,7 @@
  * SECTION:file
  * @Short_description: On-disk representation of a GtkSourceBuffer
  * @Title: GtkSourceFile
- * @See_also: #GtkSourceFileLoader, #GtkSourceFileSaver, #GtkSourceBuffer
+ * @See_also: #GtkSourceFileLoader, #GtkSourceFileSaver
  *
  * A #GtkSourceFile object is the on-disk representation of a #GtkSourceBuffer.
  * With a #GtkSourceFile, you can create and configure a #GtkSourceFileLoader
@@ -43,7 +42,6 @@
 enum
 {
        PROP_0,
-       PROP_BUFFER,
        PROP_LOCATION,
        PROP_ENCODING,
        PROP_NEWLINE_TYPE,
@@ -52,12 +50,6 @@ enum
 
 struct _GtkSourceFilePrivate
 {
-       /* Weak ref to the buffer. A strong ref could create a reference cycle
-        * in an application. For example a subclass of GtkSourceBuffer can have
-        * a strong ref to the GtkSourceFile.
-        */
-       GtkSourceBuffer *buffer;
-
        GFile *location;
        const GtkSourceEncoding *encoding;
        GtkSourceNewlineType newline_type;
@@ -91,10 +83,6 @@ gtk_source_file_get_property (GObject    *object,
 
        switch (prop_id)
        {
-               case PROP_BUFFER:
-                       g_value_set_object (value, file->priv->buffer);
-                       break;
-
                case PROP_LOCATION:
                        g_value_set_object (value, file->priv->location);
                        break;
@@ -131,13 +119,6 @@ gtk_source_file_set_property (GObject      *object,
 
        switch (prop_id)
        {
-               case PROP_BUFFER:
-                       g_assert (file->priv->buffer == NULL);
-                       file->priv->buffer = g_value_get_object (value);
-                       g_object_add_weak_pointer (G_OBJECT (file->priv->buffer),
-                                                  (gpointer *) &file->priv->buffer);
-                       break;
-
                case PROP_LOCATION:
                        gtk_source_file_set_location (file, g_value_get_object (value));
                        break;
@@ -153,14 +134,6 @@ gtk_source_file_dispose (GObject *object)
 {
        GtkSourceFile *file = GTK_SOURCE_FILE (object);
 
-       if (file->priv->buffer != NULL)
-       {
-               g_object_remove_weak_pointer (G_OBJECT (file->priv->buffer),
-                                             (gpointer *) &file->priv->buffer);
-
-               file->priv->buffer = NULL;
-       }
-
        g_clear_object (&file->priv->location);
 
        if (file->priv->mount_operation_notify != NULL)
@@ -182,24 +155,6 @@ gtk_source_file_class_init (GtkSourceFileClass *klass)
        object_class->dispose = gtk_source_file_dispose;
 
        /**
-        * GtkSourceFile:buffer:
-        *
-        * The buffer. The #GtkSourceFile object has a weak reference to the
-        * buffer.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_BUFFER,
-                                        g_param_spec_object ("buffer",
-                                                             "GtkSourceBuffer",
-                                                             "",
-                                                             GTK_SOURCE_TYPE_BUFFER,
-                                                             G_PARAM_READWRITE |
-                                                             G_PARAM_CONSTRUCT_ONLY |
-                                                             G_PARAM_STATIC_STRINGS));
-
-       /**
         * GtkSourceFile:location:
         *
         * The location.
@@ -276,34 +231,14 @@ gtk_source_file_init (GtkSourceFile *file)
 
 /**
  * gtk_source_file_new:
- * @buffer: a #GtkSourceBuffer.
  *
  * Returns: a new #GtkSourceFile object.
  * Since: 3.14
  */
 GtkSourceFile *
-gtk_source_file_new (GtkSourceBuffer *buffer)
+gtk_source_file_new (void)
 {
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
-       return g_object_new (GTK_SOURCE_TYPE_FILE,
-                            "buffer", buffer,
-                            NULL);
-}
-
-/**
- * gtk_source_file_get_buffer:
- * @file: a #GtkSourceFile.
- *
- * Returns: (transfer none): the buffer.
- * Since: 3.14
- */
-GtkSourceBuffer *
-gtk_source_file_get_buffer (GtkSourceFile *file)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
-
-       return file->priv->buffer;
+       return g_object_new (GTK_SOURCE_TYPE_FILE, NULL);
 }
 
 /**
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index c384d58..e4859f1 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -66,9 +66,7 @@ struct _GtkSourceFileClass
 
 GType           gtk_source_file_get_type                       (void) G_GNUC_CONST;
 
-GtkSourceFile  *gtk_source_file_new                            (GtkSourceBuffer *buffer);
-
-GtkSourceBuffer        *gtk_source_file_get_buffer                     (GtkSourceFile *file);
+GtkSourceFile  *gtk_source_file_new                            (void);
 
 GFile          *gtk_source_file_get_location                   (GtkSourceFile *file);
 
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index b3e073f..08bcbc1 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -22,8 +22,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <gio/gio.h>
 #include "gtksourcefileloader.h"
+#include "gtksourcebuffer.h"
 #include "gtksourcefile.h"
 #include "gtksourcebufferoutputstream.h"
 #include "gtksourceencoding.h"
@@ -49,6 +49,7 @@
 enum
 {
        PROP_0,
+       PROP_BUFFER,
        PROP_FILE,
        PROP_LOCATION,
        PROP_INPUT_STREAM
@@ -63,6 +64,12 @@ enum
 
 struct _GtkSourceFileLoaderPrivate
 {
+       /* Weak ref to the GtkSourceBuffer. A strong ref could create a
+        * reference cycle in an application. For example a subclass of
+        * GtkSourceBuffer can have a strong ref to the FileLoader.
+        */
+       GtkSourceBuffer *source_buffer;
+
        /* Weak ref to the GtkSourceFile. A strong ref could create a reference
         * cycle in an application. For example a subclass of GtkSourceFile can
         * have a strong ref to the FileLoader.
@@ -135,6 +142,13 @@ gtk_source_file_loader_set_property (GObject      *object,
 
        switch (prop_id)
        {
+               case PROP_BUFFER:
+                       g_assert (loader->priv->source_buffer == NULL);
+                       loader->priv->source_buffer = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (loader->priv->source_buffer),
+                                                  (gpointer *)&loader->priv->source_buffer);
+                       break;
+
                case PROP_FILE:
                        g_assert (loader->priv->file == NULL);
                        loader->priv->file = g_value_get_object (value);
@@ -168,6 +182,10 @@ gtk_source_file_loader_get_property (GObject    *object,
 
        switch (prop_id)
        {
+               case PROP_BUFFER:
+                       g_value_set_object (value, loader->priv->source_buffer);
+                       break;
+
                case PROP_FILE:
                        g_value_set_object (value, loader->priv->file);
                        break;
@@ -211,6 +229,14 @@ gtk_source_file_loader_dispose (GObject *object)
 
        reset (loader);
 
+       if (loader->priv->source_buffer != NULL)
+       {
+               g_object_remove_weak_pointer (G_OBJECT (loader->priv->source_buffer),
+                                             (gpointer *)&loader->priv->source_buffer);
+
+               loader->priv->source_buffer = NULL;
+       }
+
        if (loader->priv->file != NULL)
        {
                g_object_remove_weak_pointer (G_OBJECT (loader->priv->file),
@@ -257,6 +283,23 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
        object_class->constructed = gtk_source_file_loader_constructed;
 
        /**
+        * GtkSourceFileLoader:buffer:
+        *
+        * The #GtkSourceBuffer to load the contents into. The
+        * #GtkSourceFileLoader object has a weak reference to the :buffer.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class, PROP_BUFFER,
+                                        g_param_spec_object ("buffer",
+                                                             "GtkSourceBuffer",
+                                                             "",
+                                                             GTK_SOURCE_TYPE_BUFFER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       /**
         * GtkSourceFileLoader:file:
         *
         * The #GtkSourceFile. The #GtkSourceFileLoader object has a weak
@@ -709,6 +752,7 @@ gtk_source_file_loader_error_quark (void)
 
 /**
  * gtk_source_file_loader_new:
+ * @buffer: the #GtkSourceBuffer to load the contents into.
  * @file: the #GtkSourceFile.
  * @location: the #GFile to load.
  *
@@ -716,13 +760,16 @@ gtk_source_file_loader_error_quark (void)
  * Since: 3.14
  */
 GtkSourceFileLoader *
-gtk_source_file_loader_new (GtkSourceFile *file,
-                           GFile         *location)
+gtk_source_file_loader_new (GtkSourceBuffer *buffer,
+                           GtkSourceFile   *file,
+                           GFile           *location)
 {
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
        g_return_val_if_fail (G_IS_FILE (location), NULL);
 
        return g_object_new (GTK_SOURCE_TYPE_FILE_LOADER,
+                            "buffer", buffer,
                             "file", file,
                             "location", location,
                             NULL);
@@ -730,6 +777,7 @@ gtk_source_file_loader_new (GtkSourceFile *file,
 
 /**
  * gtk_source_file_loader_new_from_stream:
+ * @buffer: the #GtkSourceBuffer to load the contents into.
  * @file: the #GtkSourceFile.
  * @stream: the #GInputStream to load, e.g. stdin.
  *
@@ -737,13 +785,16 @@ gtk_source_file_loader_new (GtkSourceFile *file,
  * Since: 3.14
  */
 GtkSourceFileLoader *
-gtk_source_file_loader_new_from_stream (GtkSourceFile *file,
-                                       GInputStream  *stream)
+gtk_source_file_loader_new_from_stream (GtkSourceBuffer *buffer,
+                                       GtkSourceFile   *file,
+                                       GInputStream    *stream)
 {
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
        g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
 
        return g_object_new (GTK_SOURCE_TYPE_FILE_LOADER,
+                            "buffer", buffer,
                             "file", file,
                             "input-stream", stream,
                             NULL);
@@ -772,6 +823,21 @@ gtk_source_file_loader_set_candidate_encodings (GtkSourceFileLoader *loader,
 }
 
 /**
+ * gtk_source_file_loader_get_buffer:
+ * @loader: a #GtkSourceFileLoader.
+ *
+ * Returns: (transfer none): the #GtkSourceBuffer to load the contents into.
+ * Since: 3.14
+ */
+GtkSourceBuffer *
+gtk_source_file_loader_get_buffer (GtkSourceFileLoader *loader)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
+
+       return loader->priv->source_buffer;
+}
+
+/**
  * gtk_source_file_loader_get_file:
  * @loader: a #GtkSourceFileLoader.
  *
@@ -835,8 +901,8 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
  * @user_data: user data to pass to @callback.
  *
  * Loads asynchronously the file or input stream contents into the
- * #GtkSourceBuffer (see gtk_source_file_get_buffer()). See the #GAsyncResult
- * documentation to know how to use this function.
+ * #GtkSourceBuffer. See the #GAsyncResult documentation to know how to use this
+ * function.
  *
  * Since: 3.14
  */
@@ -854,20 +920,13 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
                                   GAsyncReadyCallback    callback,
                                   gpointer               user_data)
 {
-       GtkSourceBuffer *buffer;
        gboolean implicit_trailing_newline;
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
        g_return_if_fail (loader->priv->task == NULL);
 
-       if (loader->priv->file == NULL)
-       {
-               return;
-       }
-
-       buffer = gtk_source_file_get_buffer (loader->priv->file);
-
-       if (buffer == NULL)
+       if (loader->priv->source_buffer == NULL ||
+           loader->priv->file == NULL)
        {
                return;
        }
@@ -902,13 +961,13 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
                                              loader->priv->location);
        }
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(loader->priv->source_buffer);
 
        /* The BufferOutputStream has a strong reference to the buffer.
          * We create the BufferOutputStream here so we are sure that the
          * buffer will not be destroyed during the file loading.
          */
-       loader->priv->output_stream = gtk_source_buffer_output_stream_new (buffer,
+       loader->priv->output_stream = gtk_source_buffer_output_stream_new (loader->priv->source_buffer,
                                                                           loader->priv->candidate_encodings,
                                                                           implicit_trailing_newline);
 
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index df7f1d3..2ca1167 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -27,7 +27,6 @@
 
 #include <gtk/gtk.h>
 #include <gtksourceview/gtksourcetypes.h>
-#include <gtksourceview/gtksourcebuffer.h>
 
 G_BEGIN_DECLS
 
@@ -78,16 +77,20 @@ GType                        gtk_source_file_loader_get_type        (void) G_GNUC_CONST;
 
 GQuark                  gtk_source_file_loader_error_quark     (void);
 
-GtkSourceFileLoader    *gtk_source_file_loader_new             (GtkSourceFile           *file,
+GtkSourceFileLoader    *gtk_source_file_loader_new             (GtkSourceBuffer         *buffer,
+                                                                GtkSourceFile           *file,
                                                                 GFile                   *location);
 
-GtkSourceFileLoader    *gtk_source_file_loader_new_from_stream (GtkSourceFile           *file,
+GtkSourceFileLoader    *gtk_source_file_loader_new_from_stream (GtkSourceBuffer         *buffer,
+                                                                GtkSourceFile           *file,
                                                                 GInputStream            *stream);
 
 void                    gtk_source_file_loader_set_candidate_encodings
                                                                (GtkSourceFileLoader     *loader,
                                                                 GSList                  
*candidate_encodings);
 
+GtkSourceBuffer                *gtk_source_file_loader_get_buffer      (GtkSourceFileLoader     *loader);
+
 GtkSourceFile          *gtk_source_file_loader_get_file        (GtkSourceFileLoader     *loader);
 
 GFile                  *gtk_source_file_loader_get_location    (GtkSourceFileLoader     *loader);
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 28136af..115ea7d 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -26,6 +26,7 @@
 #include "gtksourcefile.h"
 #include "gtksourcebufferinputstream.h"
 #include "gtksourceencoding.h"
+#include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
 #include "gtksourceview-typebuiltins.h"
 #include "gtksourceview-i18n.h"
@@ -59,6 +60,7 @@
 enum
 {
        PROP_0,
+       PROP_BUFFER,
        PROP_FILE,
        PROP_LOCATION,
        PROP_ENCODING,
@@ -69,6 +71,12 @@ enum
 
 struct _GtkSourceFileSaverPrivate
 {
+       /* Weak ref to the GtkSourceBuffer. A strong ref could create a
+        * reference cycle in an application. For example a subclass of
+        * GtkSourceBuffer can have a strong ref to the FileSaver.
+        */
+       GtkSourceBuffer *source_buffer;
+
        /* Weak ref to the GtkSourceFile. A strong ref could create a reference
         * cycle in an application. For example a subclass of GtkSourceFile can
         * have a strong ref to the FileSaver.
@@ -130,6 +138,13 @@ gtk_source_file_saver_set_property (GObject      *object,
 
        switch (prop_id)
        {
+               case PROP_BUFFER:
+                       g_assert (saver->priv->source_buffer == NULL);
+                       saver->priv->source_buffer = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (saver->priv->source_buffer),
+                                                  (gpointer *)&saver->priv->source_buffer);
+                       break;
+
                case PROP_FILE:
                        g_assert (saver->priv->file == NULL);
                        saver->priv->file = g_value_get_object (value);
@@ -174,6 +189,10 @@ gtk_source_file_saver_get_property (GObject    *object,
 
        switch (prop_id)
        {
+               case PROP_BUFFER:
+                       g_value_set_object (value, saver->priv->source_buffer);
+                       break;
+
                case PROP_FILE:
                        g_value_set_object (value, saver->priv->file);
                        break;
@@ -230,6 +249,14 @@ gtk_source_file_saver_dispose (GObject *object)
 
        reset (saver);
 
+       if (saver->priv->source_buffer != NULL)
+       {
+               g_object_remove_weak_pointer (G_OBJECT (saver->priv->source_buffer),
+                                             (gpointer *)&saver->priv->source_buffer);
+
+               saver->priv->source_buffer = NULL;
+       }
+
        if (saver->priv->file != NULL)
        {
                g_object_remove_weak_pointer (G_OBJECT (saver->priv->file),
@@ -278,6 +305,24 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
        object_class->constructed = gtk_source_file_saver_constructed;
 
        /**
+        * GtkSourceFileSaver:buffer:
+        *
+        * The #GtkSourceBuffer to save. The #GtkSourceFileSaver object has a
+        * weak reference to the :buffer.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_BUFFER,
+                                        g_param_spec_object ("buffer",
+                                                             "GtkSourceBuffer",
+                                                             "",
+                                                             GTK_SOURCE_TYPE_BUFFER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       /**
         * GtkSourceFileSaver:file:
         *
         * The #GtkSourceFile. The #GtkSourceFileSaver object has a weak
@@ -933,6 +978,7 @@ gtk_source_file_saver_error_quark (void)
 
 /**
  * gtk_source_file_saver_new:
+ * @buffer: the #GtkSourceBuffer to save.
  * @file: the #GtkSourceFile.
  * @location: the #GFile where to save the buffer to.
  *
@@ -940,19 +986,37 @@ gtk_source_file_saver_error_quark (void)
  * Since: 3.14
  */
 GtkSourceFileSaver *
-gtk_source_file_saver_new (GtkSourceFile *file,
-                          GFile         *location)
+gtk_source_file_saver_new (GtkSourceBuffer *buffer,
+                          GtkSourceFile   *file,
+                          GFile           *location)
 {
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
        g_return_val_if_fail (G_IS_FILE (location), NULL);
 
        return g_object_new (GTK_SOURCE_TYPE_FILE_SAVER,
+                            "buffer", buffer,
                             "file", file,
                             "location", location,
                             NULL);
 }
 
 /**
+ * gtk_source_file_saver_get_buffer:
+ * @saver: a #GtkSourceFileSaver.
+ *
+ * Returns: (transfer none): the #GtkSourceBuffer to save.
+ * Since: 3.14
+ */
+GtkSourceBuffer *
+gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
+
+       return saver->priv->source_buffer;
+}
+
+/**
  * gtk_source_file_saver_get_file:
  * @saver: a #GtkSourceFileSaver.
  *
@@ -1176,21 +1240,14 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
                                  GAsyncReadyCallback     callback,
                                  gpointer                user_data)
 {
-       GtkSourceBuffer *buffer;
        gboolean check_invalid_chars;
        gboolean implicit_trailing_newline;
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
        g_return_if_fail (saver->priv->task == NULL);
 
-       if (saver->priv->file == NULL)
-       {
-               return;
-       }
-
-       buffer = gtk_source_file_get_buffer (saver->priv->file);
-
-       if (buffer == NULL)
+       if (saver->priv->source_buffer == NULL ||
+           saver->priv->file == NULL)
        {
                return;
        }
@@ -1206,7 +1263,7 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
 
        check_invalid_chars = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
 
-       if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (buffer))
+       if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (saver->priv->source_buffer))
        {
                g_task_return_new_error (saver->priv->task,
                                         GTK_SOURCE_FILE_SAVER_ERROR,
@@ -1219,13 +1276,13 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
               g_print ("Start saving\n");
        });
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(saver->priv->source_buffer);
 
        /* The BufferInputStream has a strong reference to the buffer.
         * We create the BufferInputStream here so we are sure that the
         * buffer will not be destroyed during the file saving.
         */
-       saver->priv->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER (buffer),
+       saver->priv->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER 
(saver->priv->source_buffer),
                                                                         saver->priv->newline_type,
                                                                         implicit_trailing_newline);
 
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index f2e10b6..6040064 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -27,7 +27,6 @@
 
 #include <gtk/gtk.h>
 #include <gtksourceview/gtksourcetypes.h>
-#include <gtksourceview/gtksourcebuffer.h>
 
 G_BEGIN_DECLS
 
@@ -95,9 +94,12 @@ GType                         gtk_source_file_saver_get_type         (void) G_GNUC_CONST;
 
 GQuark                  gtk_source_file_saver_error_quark      (void);
 
-GtkSourceFileSaver     *gtk_source_file_saver_new              (GtkSourceFile            *file,
+GtkSourceFileSaver     *gtk_source_file_saver_new              (GtkSourceBuffer          *buffer,
+                                                                GtkSourceFile            *file,
                                                                 GFile                    *location);
 
+GtkSourceBuffer                *gtk_source_file_saver_get_buffer       (GtkSourceFileSaver       *saver);
+
 GtkSourceFile          *gtk_source_file_saver_get_file         (GtkSourceFileSaver       *saver);
 
 GFile                  *gtk_source_file_saver_get_location     (GtkSourceFileSaver       *saver);
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index 5cd5d34..fe9cfa8 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -53,14 +53,12 @@ load_file_cb (GtkSourceFileLoader *loader,
 
        if (data->expected_buffer_contents != NULL)
        {
-               GtkSourceFile *file;
                GtkSourceBuffer *buffer;
                GtkTextIter start;
                GtkTextIter end;
                gchar *buffer_contents;
 
-               file = gtk_source_file_loader_get_file (loader);
-               buffer = gtk_source_file_get_buffer (file);
+               buffer = gtk_source_file_loader_get_buffer (loader);
 
                gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
                buffer_contents = gtk_text_iter_get_slice (&start, &end);
@@ -100,8 +98,8 @@ test_loader (const gchar *filename,
 
        location = g_file_new_for_path (filename);
        buffer = gtk_source_buffer_new (NULL);
-       file = gtk_source_file_new (buffer);
-       loader = gtk_source_file_loader_new (file, location);
+       file = gtk_source_file_new ();
+       loader = gtk_source_file_loader_new (buffer, file, location);
 
        candidate_encodings = g_slist_prepend (NULL, (gpointer) gtk_source_encoding_get_utf8 ());
        gtk_source_file_loader_set_candidate_encodings (loader, candidate_encodings);
diff --git a/tests/test-file-saver.c b/tests/test-file-saver.c
index 889a262..5b0783b 100644
--- a/tests/test-file-saver.c
+++ b/tests/test-file-saver.c
@@ -194,8 +194,8 @@ test_saver (const gchar            *filename_or_uri,
        buffer = gtk_source_buffer_new (NULL);
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), buffer_contents, -1);
 
-       file = gtk_source_file_new (buffer);
-       saver = gtk_source_file_saver_new (file, location);
+       file = gtk_source_file_new ();
+       saver = gtk_source_file_saver_new (buffer, file, location);
 
        gtk_source_file_saver_set_newline_type (saver, newline_type);
        gtk_source_file_saver_set_encoding (saver, gtk_source_encoding_get_utf8 ());


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