[gtksourceview/wip/loader-saver] FileLoader: fix corner case for updating the buffer properties



commit 44736376f081717e83ed10faee4377ad8cd03be1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Apr 3 19:27:09 2014 +0200

    FileLoader: fix corner case for updating the buffer properties

 gtksourceview/gtksourcefileloader.c |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 3d71781..cd8a42a 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -887,9 +887,9 @@ 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 successfully, the following #GtkSourceBuffer
- * properties will be updated: the file, the encoding, the newline type and the
- * compression type.
+ * If the file has been loaded, the following #GtkSourceBuffer properties will
+ * be updated: the file, the encoding, the newline type and the compression
+ * type.
  *
  * Returns: whether the file was loaded successfully.
  * Since: 3.14
@@ -900,14 +900,33 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                                    GError              **error)
 {
        gboolean ok;
+       gboolean update_buffer_properties;
+       GError *real_error = NULL;
 
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
        g_return_val_if_fail (g_task_is_valid (result, loader), FALSE);
 
-       ok = g_task_propagate_boolean (G_TASK (result), error);
+       ok = g_task_propagate_boolean (G_TASK (result), &real_error);
 
-       if (ok && loader->priv->source_buffer != NULL)
+       if (error != NULL)
+       {
+               *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_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)
        {
                _gtk_source_buffer_set_file (loader->priv->source_buffer,
                                             loader->priv->file);
@@ -924,6 +943,11 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
 
        reset (loader);
 
+       if (real_error != NULL)
+       {
+               g_error_free (real_error);
+       }
+
        return ok;
 }
 


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