[gtksourceview] FileLoader: call gtk_text_buffer_set_modified()



commit db7a028d94e5a4f9bea089e0db5d0a06489c52d8
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jun 14 13:57:11 2015 +0200

    FileLoader: call gtk_text_buffer_set_modified()
    
    Set the buffer as modified when loading from an input stream (e.g.
    stdin).
    
    GtkSourceBufferOutputStream doesn't know if the contents comes from a
    GFile or a GInputStream, GtkSourceFileLoader does.

 gtksourceview/gtksourcebufferoutputstream.c |    3 ---
 gtksourceview/gtksourcefileloader.c         |    9 ++++++++-
 tests/test-buffer-output-stream.c           |    2 --
 tests/test-file-loader.c                    |   11 ++++++++---
 4 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index a71e4e7..f1eecfa 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -761,9 +761,6 @@ 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 d8b8b8e..2ef41d6 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -1079,7 +1079,8 @@ 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.
+ * type. Additionally, gtk_text_buffer_set_modified() is called with %FALSE when
+ * loading from a #GFile, and %TRUE when loading from a #GInputStream.
  *
  * Returns: whether the contents has been loaded successfully.
  * Since: 3.14
@@ -1156,6 +1157,12 @@ 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 97e72c3..dea512e 100644
--- a/tests/test-buffer-output-stream.c
+++ b/tests/test-buffer-output-stream.c
@@ -73,8 +73,6 @@ 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 9d5d621..74b1e6b 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,6 +75,11 @@ 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]