[gtksourceview/wip/file-loader-set-modified: 1/2] Revert "FileLoader: call gtk_text_buffer_set_modified()"



commit 9876f295a7fe48c5263b898a1421a1f38880bfc8
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 20 10:57:50 2015 +0200

    Revert "FileLoader: call gtk_text_buffer_set_modified()"
    
    This reverts commit db7a028d94e5a4f9bea089e0db5d0a06489c52d8.
    
    To follow the least surprise principle, it's better to always do the
    same thing, that is, set the modified bit to FALSE after a file loading.
    The FileLoader thus resets the buffer with a certain (unmodified)
    content.
    
    The rationale behind the commit was to have good defaults for the most
    common cases. That is, when loading from a GFile, the contents is
    usually stored on disk and we can mark the buffer in a "saved/safe"
    state (i.e. not modified). On the other hand when loading from a
    GInputStream, the common case is for stdin, in which case the app
    doesn't know if the contents is stored on disk or not, so it's better to
    set the buffer as modified to avoid data loss (when closing the buffer
    the user will typically get a dialog window asking for saving the
    content). So the idea was to explain in the docs that when loading from
    a GInputStream, the app must explicitly acknowledge that the buffer is
    in a saved state, while loading from a GFile the reverse must be done if
    the GFile is a temporary file. So the idea was to make the good way the
    easy way, by default the app would have nothing to do, it would just
    work.
    
    Anyway, even if it was not documented that
    gtk_text_buffer_set_modified(false) was called, changing that can be
    seen as an API break. The set_modified() was not part of the "interface"
    (the I in API), it was an implementation detail, so that's why the
    change can also be seen as acceptable. In an API, everything that is not
    documented can be considered as "undefined behavior".

 gtksourceview/gtksourcebufferoutputstream.c |    3 +++
 gtksourceview/gtksourcefileloader.c         |    9 +--------
 tests/test-buffer-output-stream.c           |    2 ++
 tests/test-file-loader.c                    |   11 +++--------
 4 files changed, 9 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index f1eecfa..a71e4e7 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -761,6 +761,9 @@ end_append_text_to_document (GtkSourceBufferOutputStream *stream)
                remove_trailing_newline (stream);
        }
 
+       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+                                     FALSE);
+
        gtk_source_buffer_end_not_undoable_action (stream->priv->source_buffer);
 }
 
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 2ef41d6..d8b8b8e 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -1079,8 +1079,7 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
  *
  * If the contents has been loaded, the following #GtkSourceFile properties will
  * be updated: the location, the encoding, the newline type and the compression
- * type. Additionally, gtk_text_buffer_set_modified() is called with %FALSE when
- * loading from a #GFile, and %TRUE when loading from a #GInputStream.
+ * type.
  *
  * Returns: whether the contents has been loaded successfully.
  * Since: 3.14
@@ -1157,12 +1156,6 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                }
        }
 
-       if (loader->priv->source_buffer != NULL)
-       {
-               gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (loader->priv->source_buffer),
-                                             loader->priv->input_stream_property != NULL);
-       }
-
        reset (loader);
 
        if (real_error != NULL)
diff --git a/tests/test-buffer-output-stream.c b/tests/test-buffer-output-stream.c
index dea512e..97e72c3 100644
--- a/tests/test-buffer-output-stream.c
+++ b/tests/test-buffer-output-stream.c
@@ -73,6 +73,8 @@ test_consecutive_write (const gchar          *inbuf,
        g_assert_cmpstr (outbuf, ==, b);
        g_free (b);
 
+       g_assert (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (source_buffer)) == FALSE);
+
        g_object_unref (source_buffer);
        g_object_unref (out);
 }
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index 74b1e6b..9d5d621 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -46,20 +46,20 @@ load_file_cb (GtkSourceFileLoader *loader,
              GAsyncResult        *result,
              LoaderTestData      *data)
 {
-       GtkSourceBuffer *buffer;
        GError *error = NULL;
 
        gtk_source_file_loader_load_finish (loader, result, &error);
        g_assert_no_error (error);
 
-       buffer = gtk_source_file_loader_get_buffer (loader);
-
        if (data->expected_buffer_contents != NULL)
        {
+               GtkSourceBuffer *buffer;
                GtkTextIter start;
                GtkTextIter end;
                gchar *buffer_contents;
 
+               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);
 
@@ -75,11 +75,6 @@ load_file_cb (GtkSourceFileLoader *loader,
                                 data->newline_type);
        }
 
-       /* The tests load from a GFile, so the buffer is set as not modified.
-        * But the result would be different if a unit test loads from a stream.
-        */
-       g_assert (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (buffer)));
-
        /* finished */
        gtk_main_quit ();
 }


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