[gtksourceview/wip/loader-saver: 10/28] GtkSourceFile, the come back



commit 4473031a8abcb88b6c7c4426906eb83a87e9796f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jun 5 22:45:42 2014 +0200

    GtkSourceFile, the come back

 docs/reference/gtksourceview-3.0-sections.txt |   41 ++-
 docs/reference/gtksourceview-docs.xml         |    1 +
 gtksourceview/Makefile.am                     |    2 +
 gtksourceview/gtksource.h                     |    1 +
 gtksourceview/gtksourcebuffer-private.h       |   20 +--
 gtksourceview/gtksourcebuffer.c               |  216 +-------------
 gtksourceview/gtksourcebuffer.h               |    8 -
 gtksourceview/gtksourcefile.c                 |  405 +++++++++++++++++++++++++
 gtksourceview/gtksourcefile.h                 |   87 ++++++
 gtksourceview/gtksourcefileloader.c           |  206 +++++++------
 gtksourceview/gtksourcefileloader.h           |   10 +-
 gtksourceview/gtksourcefilesaver.c            |  241 ++++++----------
 gtksourceview/gtksourcefilesaver.h            |   13 +-
 gtksourceview/gtksourcetypes.h                |   12 +-
 tests/test-file-loader.c                      |   28 +-
 tests/test-file-saver.c                       |   55 ++--
 16 files changed, 791 insertions(+), 555 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index c66745f..91976fb 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -6,10 +6,6 @@
 GtkSourceBuffer
 GtkSourceBracketMatchType
 GtkSourceChangeCaseType
-GtkSourceNewlineType
-GTK_SOURCE_NEWLINE_TYPE_DEFAULT
-GtkSourceCompressionType
-GtkSourceMountOperationFactory
 gtk_source_buffer_new
 gtk_source_buffer_new_with_language
 gtk_source_buffer_set_highlight_syntax
@@ -44,10 +40,6 @@ gtk_source_buffer_end_not_undoable_action
 gtk_source_buffer_get_undo_manager
 gtk_source_buffer_set_undo_manager
 <SUBSECTION>
-gtk_source_buffer_get_file
-gtk_source_buffer_get_encoding
-gtk_source_buffer_get_newline_type
-gtk_source_buffer_get_compression_type
 gtk_source_buffer_set_implicit_trailing_newline
 gtk_source_buffer_get_implicit_trailing_newline
 <SUBSECTION Standard>
@@ -237,6 +229,33 @@ gtk_source_encoding_get_type
 </SECTION>
 
 <SECTION>
+<FILE>file</FILE>
+<TITLE>GtkSourceFile</TITLE>
+GtkSourceFile
+GtkSourceNewlineType
+GTK_SOURCE_NEWLINE_TYPE_DEFAULT
+GtkSourceCompressionType
+GtkSourceMountOperationFactory
+<SUBSECTION>
+gtk_source_file_new
+gtk_source_file_get_buffer
+gtk_source_file_get_location
+gtk_source_file_get_encoding
+gtk_source_file_get_newline_type
+gtk_source_file_get_compression_type
+<SUBSECTION Standard>
+GTK_SOURCE_FILE
+GTK_SOURCE_FILE_CLASS
+GTK_SOURCE_FILE_GET_CLASS
+GTK_SOURCE_IS_FILE
+GTK_SOURCE_IS_FILE_CLASS
+GTK_SOURCE_TYPE_FILE
+GtkSourceFileClass
+GtkSourceFilePrivate
+gtk_source_file_get_type
+</SECTION>
+
+<SECTION>
 <FILE>fileloader</FILE>
 <TITLE>GtkSourceFileLoader</TITLE>
 GtkSourceFileLoader
@@ -246,8 +265,8 @@ 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
 gtk_source_file_loader_set_mount_operation_factory
 gtk_source_file_loader_load_async
@@ -272,10 +291,8 @@ gtk_source_file_loader_error_quark
 <TITLE>GtkSourceFileSaver</TITLE>
 GtkSourceFileSaver
 gtk_source_file_saver_new
-gtk_source_file_saver_get_buffer
 gtk_source_file_saver_get_file
-gtk_source_file_saver_set_main_file
-gtk_source_file_saver_get_main_file
+gtk_source_file_saver_get_location
 gtk_source_file_saver_set_encoding
 gtk_source_file_saver_get_encoding
 gtk_source_file_saver_set_newline_type
diff --git a/docs/reference/gtksourceview-docs.xml b/docs/reference/gtksourceview-docs.xml
index 6de50f4..9b0b58c 100644
--- a/docs/reference/gtksourceview-docs.xml
+++ b/docs/reference/gtksourceview-docs.xml
@@ -25,6 +25,7 @@
     <xi:include href="xml/completionprovider.xml"/>
     <xi:include href="xml/completionwords.xml"/>
     <xi:include href="xml/encoding.xml"/>
+    <xi:include href="xml/file.xml"/>
     <xi:include href="xml/fileloader.xml"/>
     <xi:include href="xml/filesaver.xml"/>
     <xi:include href="xml/gutter.xml"/>
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index 6444677..8eaa082 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -31,6 +31,7 @@ libgtksourceview_headers =                    \
        gtksourcecompletionproposal.h           \
        gtksourcecompletionprovider.h           \
        gtksourceencoding.h                     \
+       gtksourcefile.h                         \
        gtksourcefileloader.h                   \
        gtksourcefilesaver.h                    \
        gtksourcegutter.h                       \
@@ -105,6 +106,7 @@ libgtksourceview_c_files =          \
        gtksourcecompletionproposal.c   \
        gtksourcecompletionprovider.c   \
        gtksourceencoding.c             \
+       gtksourcefile.c                 \
        gtksourcefileloader.c           \
        gtksourcefilesaver.c            \
        gtksourcegutter.c               \
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 89644d1..0903003 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -29,6 +29,7 @@
 #include <gtksourceview/gtksourcecompletionproposal.h>
 #include <gtksourceview/gtksourcecompletionprovider.h>
 #include <gtksourceview/gtksourceencoding.h>
+#include <gtksourceview/gtksourcefile.h>
 #include <gtksourceview/gtksourcefileloader.h>
 #include <gtksourceview/gtksourcefilesaver.h>
 #include <gtksourceview/gtksourcegutter.h>
diff --git a/gtksourceview/gtksourcebuffer-private.h b/gtksourceview/gtksourcebuffer-private.h
index 96560d0..f24df08 100644
--- a/gtksourceview/gtksourcebuffer-private.h
+++ b/gtksourceview/gtksourcebuffer-private.h
@@ -52,24 +52,8 @@ void                  _gtk_source_buffer_add_search_context          (GtkSourceBuffer      
  *buffer,
 
 G_GNUC_INTERNAL
 void                    _gtk_source_buffer_set_as_invalid_character    (GtkSourceBuffer        *buffer,
-                                                                        GtkTextIter            *start,
-                                                                        GtkTextIter            *end);
-
-G_GNUC_INTERNAL
-void                    _gtk_source_buffer_set_file                    (GtkSourceBuffer        *buffer,
-                                                                        GFile                  *file);
-
-G_GNUC_INTERNAL
-void                    _gtk_source_buffer_set_encoding                (GtkSourceBuffer         *buffer,
-                                                                        const GtkSourceEncoding *encoding);
-
-G_GNUC_INTERNAL
-void                    _gtk_source_buffer_set_newline_type            (GtkSourceBuffer        *buffer,
-                                                                        GtkSourceNewlineType    
newline_type);
-
-G_GNUC_INTERNAL
-void                    _gtk_source_buffer_set_compression_type        (GtkSourceBuffer          *buffer,
-                                                                        GtkSourceCompressionType  
compression_type);
+                                                                        const GtkTextIter      *start,
+                                                                        const GtkTextIter      *end);
 
 G_END_DECLS
 
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 62c5cd5..3435351 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -42,7 +42,6 @@
 #include "gtksourcemark.h"
 #include "gtksourcemarkssequence.h"
 #include "gtksourcesearchcontext.h"
-#include "gtksourceencoding.h"
 #include "gtksourceview-i18n.h"
 #include "gtksourceview-marshal.h"
 #include "gtksourceview-typebuiltins.h"
@@ -142,10 +141,6 @@ enum {
        PROP_LANGUAGE,
        PROP_STYLE_SCHEME,
        PROP_UNDO_MANAGER,
-       PROP_FILE,
-       PROP_ENCODING,
-       PROP_NEWLINE_TYPE,
-       PROP_COMPRESSION_TYPE,
        PROP_IMPLICIT_TRAILING_NEWLINE
 };
 
@@ -172,11 +167,6 @@ struct _GtkSourceBufferPrivate
 
        GtkTextTag            *invalid_char_tag;
 
-       GFile                    *file;
-       const GtkSourceEncoding  *encoding;
-       GtkSourceNewlineType      newline_type;
-       GtkSourceCompressionType  compression_type;
-
        guint                  highlight_syntax : 1;
        guint                  highlight_brackets : 1;
        guint                  constructed : 1;
@@ -372,69 +362,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
        /**
-        * GtkSourceBuffer:file:
-        *
-        * The associated #GFile.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_FILE,
-                                        g_param_spec_object ("file",
-                                                             _("File"),
-                                                             "",
-                                                             G_TYPE_FILE,
-                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-       /**
-        * GtkSourceBuffer:encoding:
-        *
-        * The #GtkSourceBuffer:file's encoding. Note that the #GtkSourceBuffer
-        * always has a UTF-8 encoding.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_ENCODING,
-                                        g_param_spec_boxed ("encoding",
-                                                            _("Encoding"),
-                                                            "",
-                                                            GTK_SOURCE_TYPE_ENCODING,
-                                                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-       /**
-        * GtkSourceBuffer:newline-type:
-        *
-        * The type of line ending.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_NEWLINE_TYPE,
-                                        g_param_spec_enum ("newline-type",
-                                                           _("Newline type"),
-                                                           "",
-                                                           GTK_SOURCE_TYPE_NEWLINE_TYPE,
-                                                           GTK_SOURCE_NEWLINE_TYPE_LF,
-                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-       /**
-        * GtkSourceBuffer:compression-type:
-        *
-        * The #GtkSourceBuffer:file's compression type.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_COMPRESSION_TYPE,
-                                        g_param_spec_enum ("compression-type",
-                                                           _("Compression type"),
-                                                           "",
-                                                           GTK_SOURCE_TYPE_COMPRESSION_TYPE,
-                                                           GTK_SOURCE_COMPRESSION_TYPE_NONE,
-                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
-       /**
         * GtkSourceBuffer:implicit-trailing-newline:
         *
         * Whether the buffer has an implicit trailing newline.
@@ -626,8 +553,6 @@ gtk_source_buffer_init (GtkSourceBuffer *buffer)
        {
                g_object_ref (priv->style_scheme);
        }
-
-       priv->encoding = gtk_source_encoding_get_utf8 ();
 }
 
 static void
@@ -781,22 +706,6 @@ gtk_source_buffer_get_property (GObject    *object,
                        g_value_set_object (value, source_buffer->priv->undo_manager);
                        break;
 
-               case PROP_FILE:
-                       g_value_set_object (value, source_buffer->priv->file);
-                       break;
-
-               case PROP_ENCODING:
-                       g_value_set_boxed (value, source_buffer->priv->encoding);
-                       break;
-
-               case PROP_NEWLINE_TYPE:
-                       g_value_set_enum (value, source_buffer->priv->newline_type);
-                       break;
-
-               case PROP_COMPRESSION_TYPE:
-                       g_value_set_enum (value, source_buffer->priv->compression_type);
-                       break;
-
                case PROP_IMPLICIT_TRAILING_NEWLINE:
                        g_value_set_boolean (value, source_buffer->priv->implicit_trailing_newline);
                        break;
@@ -2631,9 +2540,9 @@ text_tag_set_highest_priority (GtkTextTag    *tag,
 }
 
 void
-_gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer *buffer,
-                                            GtkTextIter     *start,
-                                            GtkTextIter     *end)
+_gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer   *buffer,
+                                            const GtkTextIter *start,
+                                            const GtkTextIter *end)
 {
        if (buffer->priv->invalid_char_tag == NULL)
        {
@@ -2661,125 +2570,6 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer *buffer,
                                   end);
 }
 
-void
-_gtk_source_buffer_set_file (GtkSourceBuffer *buffer,
-                            GFile           *file)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (buffer->priv->file != file)
-       {
-               g_clear_object (&buffer->priv->file);
-               buffer->priv->file = g_object_ref (file);
-               g_object_notify (G_OBJECT (buffer), "file");
-       }
-}
-
-/**
- * gtk_source_buffer_get_file:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: (transfer none): the associated #GFile.
- * Since: 3.14
- */
-GFile *
-gtk_source_buffer_get_file (GtkSourceBuffer *buffer)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
-       return buffer->priv->file;
-}
-
-void
-_gtk_source_buffer_set_encoding (GtkSourceBuffer         *buffer,
-                                const GtkSourceEncoding *encoding)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (encoding == NULL)
-       {
-               encoding = gtk_source_encoding_get_utf8 ();
-       }
-
-       if (buffer->priv->encoding != encoding)
-       {
-               buffer->priv->encoding = encoding;
-               g_object_notify (G_OBJECT (buffer), "encoding");
-       }
-}
-
-/**
- * gtk_source_buffer_get_encoding:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: the #GtkSourceBuffer:file's encoding. Note that the @buffer always
- * has a UTF-8 encoding.
- * Since: 3.14
- */
-const GtkSourceEncoding *
-gtk_source_buffer_get_encoding (GtkSourceBuffer *buffer)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
-       return buffer->priv->encoding;
-}
-
-void
-_gtk_source_buffer_set_newline_type (GtkSourceBuffer      *buffer,
-                                    GtkSourceNewlineType  newline_type)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (buffer->priv->newline_type != newline_type)
-       {
-               buffer->priv->newline_type = newline_type;
-               g_object_notify (G_OBJECT (buffer), "newline-type");
-       }
-}
-
-/**
- * gtk_source_buffer_get_newline_type:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: the #GtkSourceBuffer:file's newline type.
- * Since: 3.14
- */
-GtkSourceNewlineType
-gtk_source_buffer_get_newline_type (GtkSourceBuffer *buffer)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
-
-       return buffer->priv->newline_type;
-}
-
-void
-_gtk_source_buffer_set_compression_type (GtkSourceBuffer          *buffer,
-                                        GtkSourceCompressionType  compression_type)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (buffer->priv->compression_type != compression_type)
-       {
-               buffer->priv->compression_type = compression_type;
-               g_object_notify (G_OBJECT (buffer), "compression-type");
-       }
-}
-
-/**
- * gtk_source_buffer_get_compression_type:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: the #GtkSourceBuffer:file's compression type.
- * Since: 3.14
- */
-GtkSourceCompressionType
-gtk_source_buffer_get_compression_type (GtkSourceBuffer *buffer)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), GTK_SOURCE_COMPRESSION_TYPE_NONE);
-
-       return buffer->priv->compression_type;
-}
-
 /**
  * gtk_source_buffer_set_implicit_trailing_newline:
  * @buffer: a #GtkSourceBuffer.
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index f9c8f04..449cca3 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -203,14 +203,6 @@ GtkSourceUndoManager       *gtk_source_buffer_get_undo_manager                     
(GtkSourceBuffer        *buf
 void                    gtk_source_buffer_set_undo_manager                     (GtkSourceBuffer        
*buffer,
                                                                                 GtkSourceUndoManager   
*manager);
 
-GFile                  *gtk_source_buffer_get_file                             (GtkSourceBuffer        
*buffer);
-
-const GtkSourceEncoding *gtk_source_buffer_get_encoding                                (GtkSourceBuffer      
  *buffer);
-
-GtkSourceNewlineType    gtk_source_buffer_get_newline_type                     (GtkSourceBuffer        
*buffer);
-
-GtkSourceCompressionType gtk_source_buffer_get_compression_type                        (GtkSourceBuffer      
  *buffer);
-
 void                    gtk_source_buffer_set_implicit_trailing_newline        (GtkSourceBuffer        
*buffer,
                                                                                 gboolean                
implicit_trailing_newline);
 
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
new file mode 100644
index 0000000..6bc1253
--- /dev/null
+++ b/gtksourceview/gtksourcefile.c
@@ -0,0 +1,405 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* gtksourcefile.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "gtksourcefile.h"
+#include "gtksourcebuffer.h"
+#include "gtksourceencoding.h"
+#include "gtksourceview-typebuiltins.h"
+#include "gtksourceview-i18n.h"
+
+/**
+ * SECTION:file
+ * @Short_description: On-disk representation of a GtkSourceBuffer
+ * @Title: GtkSourceFile
+ * @See_also: #GtkSourceFileLoader, #GtkSourceFileSaver, #GtkSourceBuffer
+ *
+ * A #GtkSourceFile object is the on-disk representation of a #GtkSourceBuffer.
+ * With a #GtkSourceFile, you can create and configure a #GtkSourceFileLoader
+ * and #GtkSourceFileSaver which take by default the values of the
+ * #GtkSourceFile properties (except for the file loader which always
+ * auto-detect some properties). On a successful load or save operation, the
+ * #GtkSourceFile properties are updated. But an application cannot modify
+ * directly the #GtkSourceFile properties.
+ */
+
+enum
+{
+       PROP_0,
+       PROP_BUFFER,
+       PROP_LOCATION,
+       PROP_ENCODING,
+       PROP_NEWLINE_TYPE,
+       PROP_COMPRESSION_TYPE
+};
+
+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;
+       GtkSourceCompressionType compression_type;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFile, gtk_source_file, G_TYPE_OBJECT)
+
+static void
+gtk_source_file_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (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;
+
+               case PROP_ENCODING:
+                       g_value_set_boxed (value, file->priv->encoding);
+                       break;
+
+               case PROP_NEWLINE_TYPE:
+                       g_value_set_enum (value, file->priv->newline_type);
+                       break;
+
+               case PROP_COMPRESSION_TYPE:
+                       g_value_set_enum (value, file->priv->compression_type);
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gtk_source_file_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (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;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+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);
+
+       G_OBJECT_CLASS (gtk_source_file_parent_class)->dispose (object);
+}
+
+static void
+gtk_source_file_class_init (GtkSourceFileClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->get_property = gtk_source_file_get_property;
+       object_class->set_property = gtk_source_file_set_property;
+       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.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_LOCATION,
+                                        g_param_spec_object ("location",
+                                                             _("Location"),
+                                                             "",
+                                                             G_TYPE_FILE,
+                                                             G_PARAM_READABLE |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceFile:encoding:
+        *
+        * The character encoding.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_ENCODING,
+                                        g_param_spec_boxed ("encoding",
+                                                            _("Encoding"),
+                                                            "",
+                                                            GTK_SOURCE_TYPE_ENCODING,
+                                                            G_PARAM_READABLE |
+                                                            G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceFile:newline-type:
+        *
+        * The line ending type.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_NEWLINE_TYPE,
+                                        g_param_spec_enum ("newline-type",
+                                                           _("Newline type"),
+                                                           "",
+                                                           GTK_SOURCE_TYPE_NEWLINE_TYPE,
+                                                           GTK_SOURCE_NEWLINE_TYPE_LF,
+                                                           G_PARAM_READABLE |
+                                                           G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GtkSourceFile:compression-type:
+        *
+        * The compression type.
+        *
+        * Since: 3.14
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_COMPRESSION_TYPE,
+                                        g_param_spec_enum ("compression-type",
+                                                           _("Compression type"),
+                                                           "",
+                                                           GTK_SOURCE_TYPE_COMPRESSION_TYPE,
+                                                           GTK_SOURCE_COMPRESSION_TYPE_NONE,
+                                                           G_PARAM_READABLE |
+                                                           G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gtk_source_file_init (GtkSourceFile *file)
+{
+       file->priv = gtk_source_file_get_instance_private (file);
+
+       file->priv->encoding = gtk_source_encoding_get_utf8 ();
+}
+
+/**
+ * gtk_source_file_new:
+ * @buffer: a #GtkSourceBuffer.
+ *
+ * Returns: a new #GtkSourceFile object.
+ * Since: 3.14
+ */
+GtkSourceFile *
+gtk_source_file_new (GtkSourceBuffer *buffer)
+{
+       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;
+}
+
+void
+_gtk_source_file_set_location (GtkSourceFile *file,
+                              GFile         *location)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+       g_return_if_fail (G_IS_FILE (location));
+
+       if (file->priv->location != location)
+       {
+               g_clear_object (&file->priv->location);
+               file->priv->location = g_object_ref (location);
+               g_object_notify (G_OBJECT (file), "location");
+       }
+}
+
+/**
+ * gtk_source_file_get_location:
+ * @file: a #GtkSourceFile.
+ *
+ * Returns: (transfer none): the #GFile.
+ * Since: 3.14
+ */
+GFile *
+gtk_source_file_get_location (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
+
+       return file->priv->location;
+}
+
+void
+_gtk_source_file_set_encoding (GtkSourceFile           *file,
+                              const GtkSourceEncoding *encoding)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (encoding == NULL)
+       {
+               encoding = gtk_source_encoding_get_utf8 ();
+       }
+
+       if (file->priv->encoding != encoding)
+       {
+               file->priv->encoding = encoding;
+               g_object_notify (G_OBJECT (file), "encoding");
+       }
+}
+
+/**
+ * gtk_source_file_get_encoding:
+ * @file: a #GtkSourceFile.
+ *
+ * Returns: the character encoding.
+ * Since: 3.14
+ */
+const GtkSourceEncoding *
+gtk_source_file_get_encoding (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
+
+       return file->priv->encoding;
+}
+
+void
+_gtk_source_file_set_newline_type (GtkSourceFile        *file,
+                                  GtkSourceNewlineType  newline_type)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->newline_type != newline_type)
+       {
+               file->priv->newline_type = newline_type;
+               g_object_notify (G_OBJECT (file), "newline-type");
+       }
+}
+
+/**
+ * gtk_source_file_get_newline_type:
+ * @file: a #GtkSourceFile.
+ *
+ * Returns: the newline type.
+ * Since: 3.14
+ */
+GtkSourceNewlineType
+gtk_source_file_get_newline_type (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
+
+       return file->priv->newline_type;
+}
+
+void
+_gtk_source_file_set_compression_type (GtkSourceFile            *file,
+                                      GtkSourceCompressionType  compression_type)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+
+       if (file->priv->compression_type != compression_type)
+       {
+               file->priv->compression_type = compression_type;
+               g_object_notify (G_OBJECT (file), "compression-type");
+       }
+}
+
+/**
+ * gtk_source_file_get_compression_type:
+ * @file: a #GtkSourceFile.
+ *
+ * Returns: the compression type.
+ * Since: 3.14
+ */
+GtkSourceCompressionType
+gtk_source_file_get_compression_type (GtkSourceFile *file)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_COMPRESSION_TYPE_NONE);
+
+       return file->priv->compression_type;
+}
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
new file mode 100644
index 0000000..0748cbe
--- /dev/null
+++ b/gtksourceview/gtksourcefile.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* gtksourcefile.h
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GTK_SOURCE_FILE_H__
+#define __GTK_SOURCE_FILE_H__
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcetypes.h>
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_FILE             (gtk_source_file_get_type ())
+#define GTK_SOURCE_FILE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_FILE, 
GtkSourceFile))
+#define GTK_SOURCE_FILE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_FILE, 
GtkSourceFileClass))
+#define GTK_SOURCE_IS_FILE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_FILE))
+#define GTK_SOURCE_IS_FILE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_FILE))
+#define GTK_SOURCE_FILE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_FILE, 
GtkSourceFileClass))
+
+typedef struct _GtkSourceFileClass    GtkSourceFileClass;
+typedef struct _GtkSourceFilePrivate  GtkSourceFilePrivate;
+
+struct _GtkSourceFile
+{
+       GObject parent;
+
+       GtkSourceFilePrivate *priv;
+};
+
+struct _GtkSourceFileClass
+{
+       GObjectClass parent_class;
+};
+
+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);
+
+GFile          *gtk_source_file_get_location                   (GtkSourceFile *file);
+
+const GtkSourceEncoding *
+                gtk_source_file_get_encoding                   (GtkSourceFile *file);
+
+GtkSourceNewlineType
+                gtk_source_file_get_newline_type               (GtkSourceFile *file);
+
+GtkSourceCompressionType
+                gtk_source_file_get_compression_type           (GtkSourceFile *file);
+
+G_GNUC_INTERNAL
+void            _gtk_source_file_set_location                  (GtkSourceFile *file,
+                                                                GFile         *location);
+
+G_GNUC_INTERNAL
+void            _gtk_source_file_set_encoding                  (GtkSourceFile           *file,
+                                                                const GtkSourceEncoding *encoding);
+
+G_GNUC_INTERNAL
+void            _gtk_source_file_set_newline_type              (GtkSourceFile        *file,
+                                                                GtkSourceNewlineType  newline_type);
+
+G_GNUC_INTERNAL
+void            _gtk_source_file_set_compression_type          (GtkSourceFile            *file,
+                                                                GtkSourceCompressionType  compression_type);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_FILE_H__ */
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index de10f74..1b3c637 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -24,9 +24,9 @@
 
 #include <gio/gio.h>
 #include "gtksourcefileloader.h"
+#include "gtksourcefile.h"
 #include "gtksourcebufferoutputstream.h"
 #include "gtksourceencoding.h"
-#include "gtksourcebuffer-private.h"
 #include "gtksourceview-typebuiltins.h"
 #include "gtksourceview-i18n.h"
 
@@ -34,7 +34,7 @@
  * SECTION:fileloader
  * @Short_description: Load a file into a GtkSourceBuffer
  * @Title: GtkSourceFileLoader
- * @See_also: #GtkSourceFileSaver, #GtkSourceBuffer
+ * @See_also: #GtkSourceFile, #GtkSourceFileSaver
  *
  * A #GtkSourceFileLoader object permits to load the content of a #GFile or a
  * #GInputStream into a #GtkSourceBuffer.
@@ -49,8 +49,8 @@
 enum
 {
        PROP_0,
-       PROP_BUFFER,
        PROP_FILE,
+       PROP_LOCATION,
        PROP_INPUT_STREAM
 };
 
@@ -63,17 +63,13 @@ enum
 
 struct _GtkSourceFileLoaderPrivate
 {
-       /* Weak reference to the source_buffer. A subclass of GtkSourceBuffer
-        * can have the ownership of the FileLoader. And a FileLoader can be
-        * used several times, so the object can be kept around until the
-        * subclass of GtkSourceBuffer is disposed.
-        * The GtkSourceBufferOutputStream has a strong reference to the
-        * source_buffer, so the buffer will not be finalized when the file is
-        * being loaded. So there can be a temporary reference cycle.
-         */
-       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.
+        */
+       GtkSourceFile *file;
 
-       GFile *file;
+       GFile *location;
 
        /* The value of the "input-stream" property. */
        GInputStream *input_stream_property;
@@ -141,16 +137,16 @@ 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_dup_object (value);
+                       loader->priv->file = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (loader->priv->file),
+                                                  (gpointer *)&loader->priv->file);
+                       break;
+
+               case PROP_LOCATION:
+                       g_assert (loader->priv->location == NULL);
+                       loader->priv->location = g_value_dup_object (value);
                        break;
 
                case PROP_INPUT_STREAM:
@@ -174,14 +170,14 @@ 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;
 
+               case PROP_LOCATION:
+                       g_value_set_object (value, loader->priv->location);
+                       break;
+
                case PROP_INPUT_STREAM:
                        g_value_set_object (value, loader->priv->input_stream_property);
                        break;
@@ -208,15 +204,15 @@ gtk_source_file_loader_dispose (GObject *object)
 
        reset (loader);
 
-       if (loader->priv->source_buffer != NULL)
+       if (loader->priv->file != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (loader->priv->source_buffer),
-                                             (gpointer *)&loader->priv->source_buffer);
+               g_object_remove_weak_pointer (G_OBJECT (loader->priv->file),
+                                             (gpointer *)&loader->priv->file);
 
-               loader->priv->source_buffer = NULL;
+               loader->priv->file = NULL;
        }
 
-       g_clear_object (&loader->priv->file);
+       g_clear_object (&loader->priv->location);
        g_clear_object (&loader->priv->input_stream_property);
 
        g_slist_free (loader->priv->candidate_encodings);
@@ -230,11 +226,11 @@ gtk_source_file_loader_constructed (GObject *object)
 {
        GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (object);
 
-       if (loader->priv->source_buffer != NULL)
+       if (loader->priv->file != NULL)
        {
                const GtkSourceEncoding *encoding;
 
-               encoding = gtk_source_buffer_get_encoding (loader->priv->source_buffer);
+               encoding = gtk_source_file_get_encoding (loader->priv->file);
 
                g_slist_free (loader->priv->candidate_encodings);
                loader->priv->candidate_encodings = g_slist_prepend (NULL, (gpointer) encoding);
@@ -249,36 +245,37 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->dispose = gtk_source_file_loader_dispose;
-       object_class->get_property = gtk_source_file_loader_get_property;
        object_class->set_property = gtk_source_file_loader_set_property;
+       object_class->get_property = gtk_source_file_loader_get_property;
        object_class->constructed = gtk_source_file_loader_constructed;
 
        /**
-        * GtkSourceFileLoader:buffer:
+        * GtkSourceFileLoader:file:
         *
-        * The output #GtkSourceBuffer.
+        * The #GtkSourceFile. The #GtkSourceFileLoader object has a weak
+        * reference to the :file.
         *
         * Since: 3.14
         */
-       g_object_class_install_property (object_class, PROP_BUFFER,
-                                        g_param_spec_object ("buffer",
-                                                             "GtkSourceBuffer",
+       g_object_class_install_property (object_class, PROP_FILE,
+                                        g_param_spec_object ("file",
+                                                             "GtkSourceFile",
                                                              "",
-                                                             GTK_SOURCE_TYPE_BUFFER,
+                                                             GTK_SOURCE_TYPE_FILE,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
 
        /**
-        * GtkSourceFileLoader:file:
+        * GtkSourceFileLoader:location:
         *
         * The #GFile to load.
         *
         * Since: 3.14
         */
-       g_object_class_install_property (object_class, PROP_FILE,
-                                        g_param_spec_object ("file",
-                                                             _("File"),
+       g_object_class_install_property (object_class, PROP_LOCATION,
+                                        g_param_spec_object ("location",
+                                                             _("Location"),
                                                              "",
                                                              G_TYPE_FILE,
                                                              G_PARAM_READWRITE |
@@ -288,9 +285,8 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
        /**
         * GtkSourceFileLoader:input-stream:
         *
-        * The #GInputStream to load. Useful for reading e.g. stdin. If this
-        * property is set, it has a higher priority than
-        * the #GtkSourceFileLoader:file property.
+        * The #GInputStream to load. Useful for reading stdin. If this property
+        * is set, the #GtkSourceFileLoader:location property is ignored.
         *
         * Since: 3.14
         */
@@ -636,7 +632,7 @@ recover_not_mounted (GtkSourceFileLoader *loader)
 
        loader->priv->tried_mount = TRUE;
 
-       g_file_mount_enclosing_volume (loader->priv->file,
+       g_file_mount_enclosing_volume (loader->priv->location,
                                       G_MOUNT_MOUNT_NONE,
                                       mount_operation,
                                       g_task_get_cancellable (loader->priv->task),
@@ -690,7 +686,7 @@ open_file_cb (GFile               *file,
 static void
 open_file (GtkSourceFileLoader *loader)
 {
-       g_file_read_async (loader->priv->file,
+       g_file_read_async (loader->priv->location,
                           g_task_get_priority (loader->priv->task),
                           g_task_get_cancellable (loader->priv->task),
                           (GAsyncReadyCallback) open_file_cb,
@@ -712,42 +708,42 @@ gtk_source_file_loader_error_quark (void)
 
 /**
  * gtk_source_file_loader_new:
- * @buffer: the output #GtkSourceBuffer.
- * @file: the #GFile to load.
+ * @file: the #GtkSourceFile.
+ * @location: the #GFile to load.
  *
  * Returns: a new #GtkSourceFileLoader object.
  * Since: 3.14
  */
 GtkSourceFileLoader *
-gtk_source_file_loader_new (GtkSourceBuffer *buffer,
-                           GFile           *file)
+gtk_source_file_loader_new (GtkSourceFile *file,
+                           GFile         *location)
 {
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-       g_return_val_if_fail (G_IS_FILE (file), 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);
 }
 
 /**
  * gtk_source_file_loader_new_from_stream:
- * @buffer: the output #GtkSourceBuffer.
+ * @file: the #GtkSourceFile.
  * @stream: the #GInputStream to load, e.g. stdin.
  *
  * Returns: a new #GtkSourceFileLoader object.
  * Since: 3.14
  */
 GtkSourceFileLoader *
-gtk_source_file_loader_new_from_stream (GtkSourceBuffer *buffer,
-                                       GInputStream    *stream)
+gtk_source_file_loader_new_from_stream (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);
 }
@@ -774,22 +770,22 @@ gtk_source_file_loader_set_candidate_encodings (GtkSourceFileLoader *loader,
 }
 
 /**
- * gtk_source_file_loader_get_buffer:
+ * gtk_source_file_loader_get_file:
  * @loader: a #GtkSourceFileLoader.
  *
- * Returns: (transfer none): the #GtkSourceBuffer to load the content into.
+ * Returns: (transfer none): the #GtkSourceFile.
  * Since: 3.14
  */
-GtkSourceBuffer *
-gtk_source_file_loader_get_buffer (GtkSourceFileLoader *loader)
+GtkSourceFile *
+gtk_source_file_loader_get_file (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->priv->source_buffer;
+       return loader->priv->file;
 }
 
 /**
- * gtk_source_file_loader_get_file:
+ * gtk_source_file_loader_get_location:
  * @loader: a #GtkSourceFileLoader.
  *
  * Returns: (transfer none): the #GFile to load, or %NULL if an input stream is
@@ -797,18 +793,18 @@ gtk_source_file_loader_get_buffer (GtkSourceFileLoader *loader)
  * Since: 3.14
  */
 GFile *
-gtk_source_file_loader_get_file (GtkSourceFileLoader *loader)
+gtk_source_file_loader_get_location (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->priv->file;
+       return loader->priv->location;
 }
 
 /**
  * gtk_source_file_loader_get_input_stream:
  * @loader: a #GtkSourceFileLoader.
  *
- * Returns: (transfer none): the #GInputStream to load, or %NULL if a file is
+ * Returns: (transfer none): the #GInputStream to load, or %NULL if a #GFile is
  *   used.
  * Since: 3.14
  */
@@ -833,9 +829,9 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
  *   satisfied.
  * @user_data: user data to pass to @callback.
  *
- * Loads asynchronously the #GtkSourceFileLoader:file into the
- * #GtkSourceFileLoader:buffer. See the #GAsyncResult documentation to know how to
- * use this function.
+ * 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.
  *
  * Since: 3.14
  */
@@ -848,11 +844,24 @@ 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)
+       {
+               return;
+       }
+
        reset (loader);
 
        loader->priv->task = g_task_new (loader, cancellable, callback, user_data);
@@ -865,13 +874,13 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
               g_print ("Start loading\n");
        });
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(loader->priv->source_buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (buffer);
 
-       /* The BufferOutputStream has a strong reference to the source_buffer.
+       /* The BufferOutputStream has a strong reference to the buffer.
          * We create the BufferOutputStream here so we are sure that the
-         * source_buffer will not be destroyed during the file loading.
+         * buffer will not be destroyed during the file loading.
          */
-       loader->priv->output_stream = gtk_source_buffer_output_stream_new (loader->priv->source_buffer,
+       loader->priv->output_stream = gtk_source_buffer_output_stream_new (buffer,
                                                                           loader->priv->candidate_encodings,
                                                                           implicit_trailing_newline);
 
@@ -896,11 +905,11 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
  *
  * Finishes a file loading started with gtk_source_file_loader_load_async().
  *
- * If the file has been loaded, the following #GtkSourceBuffer properties will
- * be updated: the file, the encoding, the newline type and the compression
+ * If the contents has been loaded, the following #GtkSourceFile properties will
+ * be updated: the location, the encoding, the newline type and the compression
  * type.
  *
- * Returns: whether the file was loaded successfully.
+ * Returns: whether the contents has been loaded successfully.
  * Since: 3.14
  */
 gboolean
@@ -923,31 +932,38 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                *error = g_error_copy (real_error);
        }
 
-       /* Update the buffer properties if the file has been loaded. The file
-        * can be loaded successfully, or there can be encoding conversion
-        * errors with fallback characters. In the latter case, the encoding may
-        * be wrong, but since the file has anyway be loaded, the buffer
-        * properties must be updated.
-        * With the other errors, normally the file hasn't been loaded into the
-        * buffer, i.e. the buffer is still empty.
+       /* Update the file properties if the contents has been loaded. The
+        * contents can be loaded successfully, or there can be encoding
+        * conversion errors with fallback characters. In the latter case, the
+        * encoding may be wrong, but since the contents has anyway be loaded,
+        * the file properties must be updated.
+        * With the other errors, normally the contents hasn't been loaded into
+        * the buffer, i.e. the buffer is still empty.
         */
        update_buffer_properties = ok || (real_error != NULL &&
                                          real_error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
                                          real_error->code == 
GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK);
 
-       if (update_buffer_properties && loader->priv->source_buffer != NULL)
+       if (update_buffer_properties && loader->priv->file != NULL)
        {
-               _gtk_source_buffer_set_file (loader->priv->source_buffer,
-                                            loader->priv->file);
+               if (loader->priv->input_stream_property != NULL)
+               {
+                       _gtk_source_file_set_location (loader->priv->file, NULL);
+               }
+               else
+               {
+                       _gtk_source_file_set_location (loader->priv->file,
+                                                      loader->priv->location);
+               }
 
-               _gtk_source_buffer_set_encoding (loader->priv->source_buffer,
-                                                loader->priv->auto_detected_encoding);
+               _gtk_source_file_set_encoding (loader->priv->file,
+                                              loader->priv->auto_detected_encoding);
 
-               _gtk_source_buffer_set_newline_type (loader->priv->source_buffer,
-                                                    loader->priv->auto_detected_newline_type);
+               _gtk_source_file_set_newline_type (loader->priv->file,
+                                                  loader->priv->auto_detected_newline_type);
 
-               _gtk_source_buffer_set_compression_type (loader->priv->source_buffer,
-                                                        loader->priv->auto_detected_compression_type);
+               _gtk_source_file_set_compression_type (loader->priv->file,
+                                                      loader->priv->auto_detected_compression_type);
        }
 
        reset (loader);
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index e6cd1e1..2ac3ced 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -77,19 +77,19 @@ 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             (GtkSourceBuffer         *buffer,
-                                                                GFile                   *file);
+GtkSourceFileLoader    *gtk_source_file_loader_new             (GtkSourceFile           *file,
+                                                                GFile                   *location);
 
-GtkSourceFileLoader    *gtk_source_file_loader_new_from_stream (GtkSourceBuffer         *buffer,
+GtkSourceFileLoader    *gtk_source_file_loader_new_from_stream (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_file        (GtkSourceFileLoader     *loader);
+GFile                  *gtk_source_file_loader_get_location    (GtkSourceFileLoader     *loader);
 
 GInputStream           *gtk_source_file_loader_get_input_stream
                                                                (GtkSourceFileLoader     *loader);
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index e89fbe2..439ae5b 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -23,9 +23,9 @@
  */
 
 #include "gtksourcefilesaver.h"
+#include "gtksourcefile.h"
 #include "gtksourcebufferinputstream.h"
 #include "gtksourceencoding.h"
-#include "gtksourcebuffer-private.h"
 #include "gtksourceview-typebuiltins.h"
 #include "gtksourceview-i18n.h"
 
@@ -33,7 +33,7 @@
  * SECTION:filesaver
  * @Short_description: Save a GtkSourceBuffer into a file
  * @Title: GtkSourceFileSaver
- * @See_also: #GtkSourceFileLoader, #GtkSourceBuffer
+ * @See_also: #GtkSourceFile, #GtkSourceFileLoader
  *
  * A #GtkSourceFileSaver object permits to save a #GtkSourceBuffer into a
  * #GFile.
@@ -58,9 +58,8 @@
 enum
 {
        PROP_0,
-       PROP_BUFFER,
        PROP_FILE,
-       PROP_MAIN_FILE,
+       PROP_LOCATION,
        PROP_ENCODING,
        PROP_NEWLINE_TYPE,
        PROP_COMPRESSION_TYPE,
@@ -69,16 +68,13 @@ enum
 
 struct _GtkSourceFileSaverPrivate
 {
-       /* Weak reference to the source_buffer. A subclass of GtkSourceBuffer
-        * can have the ownership of the FileSaver. And a FileSaver can be used
-        * several times, so the object can be kept around until the subclass of
-        * GtkSourceBuffer is disposed.
-        * The GtkSourceBufferInputStream has a strong reference to the
-        * source_buffer, so the buffer will not be finalized when the file is
-        * being saved. So there can be a temporary reference cycle.
+       /* 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.
         */
-       GtkSourceBuffer *source_buffer;
-       GFile *file;
+       GtkSourceFile *file;
+
+       GFile *location;
 
        const GtkSourceEncoding *encoding;
        GtkSourceNewlineType newline_type;
@@ -115,7 +111,6 @@ struct _GtkSourceFileSaverPrivate
 
        GFileInfo *info;
 
-       guint main_file : 1;
        guint create_backup : 1;
        guint tried_mount : 1;
 };
@@ -136,20 +131,16 @@ 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_dup_object (value);
+                       saver->priv->file = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (saver->priv->file),
+                                                  (gpointer *)&saver->priv->file);
                        break;
 
-               case PROP_MAIN_FILE:
-                       gtk_source_file_saver_set_main_file (saver, g_value_get_boolean (value));
+               case PROP_LOCATION:
+                       g_assert (saver->priv->location == NULL);
+                       saver->priv->location = g_value_dup_object (value);
                        break;
 
                case PROP_ENCODING:
@@ -184,16 +175,12 @@ 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;
 
-               case PROP_MAIN_FILE:
-                       g_value_set_boolean (value, saver->priv->main_file);
+               case PROP_LOCATION:
+                       g_value_set_object (value, saver->priv->location);
                        break;
 
                case PROP_ENCODING:
@@ -235,15 +222,15 @@ gtk_source_file_saver_dispose (GObject *object)
 
        reset (saver);
 
-       if (saver->priv->source_buffer != NULL)
+       if (saver->priv->file != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (saver->priv->source_buffer),
-                                             (gpointer *)&saver->priv->source_buffer);
+               g_object_remove_weak_pointer (G_OBJECT (saver->priv->file),
+                                             (gpointer *)&saver->priv->file);
 
-               saver->priv->source_buffer = NULL;
+               saver->priv->file = NULL;
        }
 
-       g_clear_object (&saver->priv->file);
+       g_clear_object (&saver->priv->location);
 
        G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->dispose (object);
 }
@@ -253,19 +240,19 @@ gtk_source_file_saver_constructed (GObject *object)
 {
        GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
 
-       if (saver->priv->source_buffer != NULL)
+       if (saver->priv->file != NULL)
        {
                const GtkSourceEncoding *encoding;
                GtkSourceNewlineType newline_type;
                GtkSourceCompressionType compression_type;
 
-               encoding = gtk_source_buffer_get_encoding (saver->priv->source_buffer);
+               encoding = gtk_source_file_get_encoding (saver->priv->file);
                gtk_source_file_saver_set_encoding (saver, encoding);
 
-               newline_type = gtk_source_buffer_get_newline_type (saver->priv->source_buffer);
+               newline_type = gtk_source_file_get_newline_type (saver->priv->file);
                gtk_source_file_saver_set_newline_type (saver, newline_type);
 
-               compression_type = gtk_source_buffer_get_compression_type (saver->priv->source_buffer);
+               compression_type = gtk_source_file_get_compression_type (saver->priv->file);
                gtk_source_file_saver_set_compression_type (saver, compression_type);
        }
 
@@ -283,33 +270,34 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
        object_class->constructed = gtk_source_file_saver_constructed;
 
        /**
-        * GtkSourceFileSaver:buffer:
+        * GtkSourceFileSaver:file:
         *
-        * The #GtkSourceBuffer to save.
+        * The #GtkSourceFile. The #GtkSourceFileSaver object has a weak
+        * reference to the :file.
         *
         * Since: 3.14
         */
        g_object_class_install_property (object_class,
-                                        PROP_BUFFER,
-                                        g_param_spec_object ("buffer",
-                                                             "GtkSourceBuffer",
+                                        PROP_FILE,
+                                        g_param_spec_object ("file",
+                                                             "GtkSourceFile",
                                                              "",
-                                                             GTK_SOURCE_TYPE_BUFFER,
+                                                             GTK_SOURCE_TYPE_FILE,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
 
        /**
-        * GtkSourceFileSaver:file:
+        * GtkSourceFileSaver:location:
         *
         * The #GFile where to save the buffer.
         *
         * Since: 3.14
         */
        g_object_class_install_property (object_class,
-                                        PROP_FILE,
-                                        g_param_spec_object ("file",
-                                                             _("File"),
+                                        PROP_LOCATION,
+                                        g_param_spec_object ("location",
+                                                             _("Location"),
                                                              "",
                                                              G_TYPE_FILE,
                                                              G_PARAM_READWRITE |
@@ -317,24 +305,6 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
                                                              G_PARAM_STATIC_STRINGS));
 
        /**
-        * GtkSourceFileSaver:main-file:
-        *
-        * Whether the #GtkSourceFileSaver:file is the main file of the
-        * #GtkSourceFileSaver:buffer.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_MAIN_FILE,
-                                        g_param_spec_boolean ("main-file",
-                                                              _("Main file"),
-                                                              "",
-                                                              TRUE,
-                                                              G_PARAM_READWRITE |
-                                                              G_PARAM_CONSTRUCT |
-                                                              G_PARAM_STATIC_STRINGS));
-
-       /**
         * GtkSourceFileSaver:encoding:
         *
         * The file's encoding.
@@ -535,7 +505,7 @@ close_output_stream_cb (GOutputStream      *output_stream,
               g_print ("Query info on file\n");
        });
 
-       g_file_query_info_async (saver->priv->file,
+       g_file_query_info_async (saver->priv->location,
                                 QUERY_ATTRIBUTES,
                                 G_FILE_QUERY_INFO_NONE,
                                 g_task_get_priority (saver->priv->task),
@@ -785,7 +755,7 @@ begin_write (GtkSourceFileSaver *saver)
               g_print ("Make backup: %s\n", make_backup ? "yes" : "no");
        });
 
-       g_file_replace_async (saver->priv->file,
+       g_file_replace_async (saver->priv->location,
                              NULL,
                              saver->priv->create_backup,
                              G_FILE_CREATE_NONE,
@@ -835,7 +805,7 @@ recover_not_mounted (GtkSourceFileSaver *saver)
 
        saver->priv->tried_mount = TRUE;
 
-       g_file_mount_enclosing_volume (saver->priv->file,
+       g_file_mount_enclosing_volume (saver->priv->location,
                                       G_MOUNT_MOUNT_NONE,
                                       mount_operation,
                                       g_task_get_cancellable (saver->priv->task),
@@ -847,48 +817,33 @@ recover_not_mounted (GtkSourceFileSaver *saver)
 
 /**
  * gtk_source_file_saver_new:
- * @buffer: the #GtkSourceBuffer to save.
- * @file: the #GFile where to save the @buffer to.
+ * @file: the #GtkSourceFile.
+ * @location: the #GFile where to save the buffer to.
  *
  * Returns: a new #GtkSourceFileSaver object.
  * Since: 3.14
  */
 GtkSourceFileSaver *
-gtk_source_file_saver_new (GtkSourceBuffer *buffer,
-                          GFile           *file)
+gtk_source_file_saver_new (GtkSourceFile *file,
+                          GFile         *location)
 {
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-       g_return_val_if_fail (G_IS_FILE (file), 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.
  *
- * Returns: (transfer none): the #GFile where to save the buffer to.
+ * Returns: (transfer none): the #GtkSourceFile.
  * Since: 3.14
  */
-GFile *
+GtkSourceFile *
 gtk_source_file_saver_get_file (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
@@ -897,48 +852,18 @@ gtk_source_file_saver_get_file (GtkSourceFileSaver *saver)
 }
 
 /**
- * gtk_source_file_saver_set_main_file:
- * @saver: a #GtkSourceFileSaver.
- * @main_file: whether the file is the main file of the buffer.
- *
- * Sets whether the #GtkSourceFileSaver:file is the main file of the
- * #GtkSourceFileSaver:buffer. If so, the following buffer properties will be
- * updated on a successful save: the file, the encoding, the newline type and
- * the compression type.
- *
- * If @main_file is %FALSE, it means that you are saving the buffer to a
- * secondary file, and therefore the buffer properties will not be affected.
- *
- * Since: 3.14
- */
-void
-gtk_source_file_saver_set_main_file (GtkSourceFileSaver *saver,
-                                    gboolean            main_file)
-{
-       g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
-
-       main_file = main_file != FALSE;
-
-       if (saver->priv->main_file != main_file)
-       {
-               saver->priv->main_file = main_file;
-               g_object_notify (G_OBJECT (saver), "main-file");
-       }
-}
-
-/**
- * gtk_source_file_saver_get_main_file:
+ * gtk_source_file_saver_get_location:
  * @saver: a #GtkSourceFileSaver.
  *
- * Returns: whether the file is the main file of the buffer.
+ * Returns: (transfer none): the #GFile where to save the buffer to.
  * Since: 3.14
  */
-gboolean
-gtk_source_file_saver_get_main_file (GtkSourceFileSaver *saver)
+GFile *
+gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
 {
-       g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), TRUE);
+       g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
 
-       return saver->priv->main_file;
+       return saver->priv->location;
 }
 
 /**
@@ -992,9 +917,7 @@ gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
  * @saver: a #GtkSourceFileSaver.
  * @newline_type: the new newline type.
  *
- * Changes the #GtkSourceFileSaver:file newline type that will be used for the
- * next file saving. It doesn't change the newline type of the
- * #GtkSourceFileSaver:buffer.
+ * Changes the newline type that will be used for the next file saving.
  *
  * Since: 3.14
  */
@@ -1117,9 +1040,8 @@ gtk_source_file_saver_get_create_backup (GtkSourceFileSaver *saver)
  *   satisfied.
  * @user_data: user data to pass to @callback.
  *
- * Saves asynchronously the #GtkSourceFileSaver:buffer into the
- * #GtkSourceFileSaver:file. See the #GAsyncResult documentation to know how to
- * use this function.
+ * Saves asynchronously the buffer into the file. See the #GAsyncResult
+ * documentation to know how to use this function.
  *
  * Since: 3.14
  */
@@ -1132,11 +1054,23 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
                                  GAsyncReadyCallback     callback,
                                  gpointer                user_data)
 {
+       GtkSourceBuffer *buffer;
        gboolean implicit_trailing_newline;
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
        g_return_if_fail (saver->priv->task == NULL);
-       g_return_if_fail (saver->priv->source_buffer != NULL);
+
+       if (saver->priv->file == NULL)
+       {
+               return;
+       }
+
+       buffer = gtk_source_file_get_buffer (saver->priv->file);
+
+       if (buffer == NULL)
+       {
+               return;
+       }
 
        reset (saver);
 
@@ -1150,13 +1084,13 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
               g_print ("Start saving\n");
        });
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(saver->priv->source_buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (buffer);
 
-       /* The BufferInputStream has a strong reference to the source_buffer.
+       /* The BufferInputStream has a strong reference to the buffer.
         * We create the BufferInputStream here so we are sure that the
-        * source_buffer will not be destroyed during the file saving.
+        * buffer will not be destroyed during the file saving.
         */
-       saver->priv->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER 
(saver->priv->source_buffer),
+       saver->priv->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER (buffer),
                                                                         saver->priv->newline_type,
                                                                         implicit_trailing_newline);
 
@@ -1171,10 +1105,9 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
  *
  * Finishes a file saving started with gtk_source_file_saver_save_async().
  *
- * If the file has been saved successfully, and if the
- * #GtkSourceFileSaver:main-file property is %TRUE, the following
- * #GtkSourceBuffer properties will be updated: the file, the encoding, the
- * newline type and the compression type.
+ * If the file has been saved successfully, the following #GtkSourceFile
+ * properties will be updated: the location, the encoding, the newline type and
+ * the compression type.
  *
  * Returns: whether the file was saved successfully.
  * Since: 3.14
@@ -1192,19 +1125,19 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver  *saver,
 
        ok = g_task_propagate_boolean (G_TASK (result), error);
 
-       if (ok && saver->priv->main_file && saver->priv->source_buffer != NULL)
+       if (ok && saver->priv->file != NULL)
        {
-               _gtk_source_buffer_set_file (saver->priv->source_buffer,
-                                            saver->priv->file);
+               _gtk_source_file_set_location (saver->priv->file,
+                                              saver->priv->location);
 
-               _gtk_source_buffer_set_encoding (saver->priv->source_buffer,
-                                                saver->priv->encoding);
+               _gtk_source_file_set_encoding (saver->priv->file,
+                                              saver->priv->encoding);
 
-               _gtk_source_buffer_set_newline_type (saver->priv->source_buffer,
-                                                    saver->priv->newline_type);
+               _gtk_source_file_set_newline_type (saver->priv->file,
+                                                  saver->priv->newline_type);
 
-               _gtk_source_buffer_set_compression_type (saver->priv->source_buffer,
-                                                        saver->priv->compression_type);
+               _gtk_source_file_set_compression_type (saver->priv->file,
+                                                      saver->priv->compression_type);
        }
 
        reset (saver);
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index fbb5d27..9c7399b 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -55,17 +55,12 @@ struct _GtkSourceFileSaverClass
 
 GType                   gtk_source_file_saver_get_type         (void) G_GNUC_CONST;
 
-GtkSourceFileSaver     *gtk_source_file_saver_new              (GtkSourceBuffer          *buffer,
-                                                                GFile                    *file);
+GtkSourceFileSaver     *gtk_source_file_saver_new              (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_file         (GtkSourceFileSaver       *saver);
-
-void                    gtk_source_file_saver_set_main_file    (GtkSourceFileSaver       *saver,
-                                                                gboolean                  main_file);
-
-gboolean                gtk_source_file_saver_get_main_file    (GtkSourceFileSaver       *saver);
+GFile                  *gtk_source_file_saver_get_location     (GtkSourceFileSaver       *saver);
 
 void                    gtk_source_file_saver_set_encoding     (GtkSourceFileSaver       *saver,
                                                                 const GtkSourceEncoding  *encoding);
diff --git a/gtksourceview/gtksourcetypes.h b/gtksourceview/gtksourcetypes.h
index b0ce6bd..c2bfa87 100644
--- a/gtksourceview/gtksourcetypes.h
+++ b/gtksourceview/gtksourcetypes.h
@@ -34,6 +34,7 @@ typedef struct _GtkSourceCompletionItem               GtkSourceCompletionItem;
 typedef struct _GtkSourceCompletionProposal    GtkSourceCompletionProposal;
 typedef struct _GtkSourceCompletionProvider    GtkSourceCompletionProvider;
 typedef struct _GtkSourceEncoding              GtkSourceEncoding;
+typedef struct _GtkSourceFile                  GtkSourceFile;
 typedef struct _GtkSourceFileLoader            GtkSourceFileLoader;
 typedef struct _GtkSourceFileSaver             GtkSourceFileSaver;
 typedef struct _GtkSourceGutter                        GtkSourceGutter;
@@ -69,6 +70,13 @@ typedef enum
        GTK_SOURCE_NEWLINE_TYPE_CR_LF
 } GtkSourceNewlineType;
 
+/**
+ * GTK_SOURCE_NEWLINE_TYPE_DEFAULT:
+ *
+ * The default newline type on the current OS.
+ *
+ * Since: 3.14
+ */
 #ifdef G_OS_WIN32
 #define GTK_SOURCE_NEWLINE_TYPE_DEFAULT GTK_SOURCE_NEWLINE_TYPE_CR_LF
 #else
@@ -77,8 +85,8 @@ typedef enum
 
 /**
  * GtkSourceCompressionType:
- * @GTK_SOURCE_COMPRESSION_TYPE_NONE: save file in plain text.
- * @GTK_SOURCE_COMPRESSION_TYPE_GZIP: save file using gzip compression.
+ * @GTK_SOURCE_COMPRESSION_TYPE_NONE: plain text.
+ * @GTK_SOURCE_COMPRESSION_TYPE_GZIP: gzip compression.
  *
  * Since: 3.14
  */
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index 6f4ac84..3a14d59 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -30,13 +30,13 @@ typedef struct
 } LoaderTestData;
 
 static void
-delete_file (GFile *file)
+delete_file (GFile *location)
 {
-       if (g_file_query_exists (file, NULL))
+       if (g_file_query_exists (location, NULL))
        {
                GError *error = NULL;
 
-               g_file_delete (file, NULL, &error);
+               g_file_delete (location, NULL, &error);
                g_assert_no_error (error);
        }
 }
@@ -53,14 +53,16 @@ load_file_cb (GtkSourceFileLoader *loader,
 
        if (data->expected_buffer_contents != NULL)
        {
-               GtkTextBuffer *buffer;
+               GtkSourceFile *file;
+               GtkSourceBuffer *buffer;
                GtkTextIter start;
                GtkTextIter end;
                gchar *buffer_contents;
 
-               g_object_get (loader, "buffer", &buffer, NULL);
+               file = gtk_source_file_loader_get_file (loader);
+               buffer = gtk_source_file_get_buffer (file);
 
-               gtk_text_buffer_get_bounds (buffer, &start, &end);
+               gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
                buffer_contents = gtk_text_iter_get_slice (&start, &end);
 
                g_assert_cmpstr (buffer_contents, ==, data->expected_buffer_contents);
@@ -85,8 +87,9 @@ test_loader (const gchar *filename,
              const gchar *expected_buffer_contents,
              gint         newline_type)
 {
-       GFile *file;
+       GFile *location;
        GtkSourceBuffer *buffer;
+       GtkSourceFile *file;
        GtkSourceFileLoader *loader;
        GSList *candidate_encodings;
        LoaderTestData *data;
@@ -95,10 +98,10 @@ test_loader (const gchar *filename,
        g_file_set_contents (filename, contents, -1, &error);
        g_assert_no_error (error);
 
-       file = g_file_new_for_path (filename);
+       location = g_file_new_for_path (filename);
        buffer = gtk_source_buffer_new (NULL);
-
-       loader = gtk_source_file_loader_new (buffer, file);
+       file = gtk_source_file_new (buffer);
+       loader = gtk_source_file_loader_new (file, location);
 
        candidate_encodings = g_slist_prepend (NULL, (gpointer) gtk_source_encoding_get_utf8 ());
        gtk_source_file_loader_set_candidate_encodings (loader, candidate_encodings);
@@ -118,9 +121,10 @@ test_loader (const gchar *filename,
        gtk_main ();
 
        g_slice_free (LoaderTestData, data);
-       delete_file (file);
-       g_object_unref (file);
+       delete_file (location);
+       g_object_unref (location);
        g_object_unref (buffer);
+       g_object_unref (file);
        g_object_unref (loader);
        g_slist_free (candidate_encodings);
 }
diff --git a/tests/test-file-saver.c b/tests/test-file-saver.c
index cf4b0c5..06f09f8 100644
--- a/tests/test-file-saver.c
+++ b/tests/test-file-saver.c
@@ -52,7 +52,7 @@ typedef void (*SavedCallback) (SaverTestData *data);
 struct _SaverTestData
 {
        GtkSourceFileSaver *saver;
-       GFile *file;
+       GFile *location;
        const gchar *expected_file_contents;
        SavedCallback saved_callback;
        gpointer userdata;
@@ -95,7 +95,7 @@ save_file_cb (GtkSourceFileSaver *saver,
 
        g_assert_no_error (error);
 
-       g_assert_cmpstr (data->expected_file_contents, ==, read_file (data->file));
+       g_assert_cmpstr (data->expected_file_contents, ==, read_file (data->location));
 
        if (data->saved_callback != NULL)
        {
@@ -104,7 +104,7 @@ save_file_cb (GtkSourceFileSaver *saver,
 
        if (!data->file_existed)
        {
-               g_file_delete (data->file, NULL, NULL);
+               g_file_delete (data->location, NULL, NULL);
        }
 
        /* finished */
@@ -114,7 +114,7 @@ save_file_cb (GtkSourceFileSaver *saver,
 static void
 save_file (SaverTestData *data)
 {
-       data->file_existed = g_file_query_exists (data->file, NULL);
+       data->file_existed = g_file_query_exists (data->location, NULL);
 
        gtk_source_file_saver_save_async (data->saver,
                                          G_PRIORITY_DEFAULT,
@@ -126,13 +126,13 @@ save_file (SaverTestData *data)
 }
 
 static void
-mount_cb (GFile         *file,
+mount_cb (GFile         *location,
          GAsyncResult  *result,
          SaverTestData *data)
 {
        GError *error = NULL;
 
-       g_file_mount_enclosing_volume_finish (file, result, &error);
+       g_file_mount_enclosing_volume_finish (location, result, &error);
 
        if (error != NULL && error->code == G_IO_ERROR_ALREADY_MOUNTED)
        {
@@ -159,7 +159,7 @@ check_mounted (SaverTestData *data)
 {
        GMountOperation *mount_operation;
 
-       if (g_file_is_native (data->file))
+       if (g_file_is_native (data->location))
        {
                save_file (data);
                return;
@@ -167,7 +167,7 @@ check_mounted (SaverTestData *data)
 
        mount_operation = gtk_mount_operation_new (NULL);
 
-       g_file_mount_enclosing_volume (data->file,
+       g_file_mount_enclosing_volume (data->location,
                                       G_MOUNT_MOUNT_NONE,
                                       mount_operation,
                                       NULL,
@@ -185,26 +185,26 @@ test_saver (const gchar            *filename_or_uri,
            SavedCallback           saved_callback,
            gpointer                userdata)
 {
-       GFile *file;
+       GFile *location;
        GtkSourceBuffer *buffer;
+       GtkSourceFile *file;
        GtkSourceFileSaver *saver;
        SaverTestData *data;
 
-       file = g_file_new_for_commandline_arg (filename_or_uri);
+       location = g_file_new_for_commandline_arg (filename_or_uri);
 
        buffer = gtk_source_buffer_new (NULL);
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), buffer_contents, -1);
 
-       saver = gtk_source_file_saver_new (buffer, file);
+       file = gtk_source_file_new (buffer);
+       saver = gtk_source_file_saver_new (file, location);
 
-       g_object_set (saver,
-                     "newline-type", newline_type,
-                     "encoding", gtk_source_encoding_get_utf8 (),
-                     NULL);
+       gtk_source_file_saver_set_newline_type (saver, newline_type);
+       gtk_source_file_saver_set_encoding (saver, gtk_source_encoding_get_utf8 ());
 
        data = g_slice_new (SaverTestData);
        data->saver = saver;
-       data->file = file;
+       data->location = location;
        data->expected_file_contents = expected_file_contents;
        data->saved_callback = saved_callback;
        data->userdata = userdata;
@@ -212,8 +212,9 @@ test_saver (const gchar            *filename_or_uri,
        check_mounted (data);
        gtk_main ();
 
-       g_object_unref (file);
+       g_object_unref (location);
        g_object_unref (buffer);
+       g_object_unref (file);
        g_object_unref (saver);
        g_slice_free (SaverTestData, data);
 }
@@ -366,7 +367,7 @@ check_permissions_saved (SaverTestData *data)
 {
        guint permissions = (guint)GPOINTER_TO_INT (data->userdata);
 
-       check_permissions (data->file, permissions);
+       check_permissions (data->location, permissions);
 }
 
 static void
@@ -374,13 +375,13 @@ test_permissions (const gchar *uri,
                   guint        permissions)
 {
        GError *error = NULL;
-       GFile *file = g_file_new_for_commandline_arg (uri);
+       GFile *location = g_file_new_for_commandline_arg (uri);
        GFileOutputStream *stream;
        GFileInfo *info;
        guint mode;
 
-       g_file_delete (file, NULL, NULL);
-       stream = g_file_create (file, 0, NULL, &error);
+       g_file_delete (location, NULL, NULL);
+       stream = g_file_create (location, 0, NULL, &error);
 
        if (error && error->code == G_IO_ERROR_NOT_SUPPORTED)
        {
@@ -393,7 +394,7 @@ test_permissions (const gchar *uri,
        g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL);
        g_object_unref (stream);
 
-       info = g_file_query_info (file,
+       info = g_file_query_info (location,
                                  G_FILE_ATTRIBUTE_UNIX_MODE,
                                  G_FILE_QUERY_INFO_NONE,
                                  NULL,
@@ -404,7 +405,7 @@ test_permissions (const gchar *uri,
        mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
        g_object_unref (info);
 
-       g_file_set_attribute_uint32 (file,
+       g_file_set_attribute_uint32 (location,
                                     G_FILE_ATTRIBUTE_UNIX_MODE,
                                     (mode & ~ACCESSPERMS) | permissions,
                                     G_FILE_QUERY_INFO_NONE,
@@ -412,7 +413,7 @@ test_permissions (const gchar *uri,
                                     &error);
        g_assert_no_error (error);
 
-       check_permissions (file, permissions);
+       check_permissions (location, permissions);
 
        test_saver (uri,
                    DEFAULT_CONTENT,
@@ -421,8 +422,8 @@ test_permissions (const gchar *uri,
                    check_permissions_saved,
                    GINT_TO_POINTER ((gint)permissions));
 
-       g_file_delete (file, NULL, NULL);
-       g_object_unref (file);
+       g_file_delete (location, NULL, NULL);
+       g_object_unref (location);
 }
 
 static void
@@ -474,7 +475,7 @@ test_unowned_group_permissions (SaverTestData *data)
        const gchar *group;
        guint32 mode;
 
-       GFileInfo *info = g_file_query_info (data->file,
+       GFileInfo *info = g_file_query_info (data->location,
                                             G_FILE_ATTRIBUTE_OWNER_GROUP ","
                                             G_FILE_ATTRIBUTE_UNIX_MODE,
                                             G_FILE_QUERY_INFO_NONE,


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