[gtksourceview/wip/loader-saver] File: return an error if an operation is already running



commit d7c9d551b563a924f5118c79fe3f4e0b971b008c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Dec 24 12:48:31 2013 +0100

    File: return an error if an operation is already running

 gtksourceview/gtksourcefile.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index bef0a28..0f7a682 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -424,12 +424,18 @@ gtk_source_file_save_async (GtkSourceFile          *file,
 
        if (file->priv->saver != NULL)
        {
-               /* FIXME create a special GTask just for returning the error and
-                * cancel the operation?
-                * Return the G_IO_ERROR_PENDING error?
-                */
-               g_warning ("Another save operation is already running on the file \"%s\".",
-                          g_file_get_parse_name (file->priv->location));
+               GTask *task;
+
+               task = g_task_new (file, cancellable, callback, user_data);
+               g_task_set_source_tag (task, file);
+
+               g_task_return_new_error (task,
+                                        G_IO_ERROR,
+                                        G_IO_ERROR_PENDING,
+                                        "Another save operation is already running on the file \"%s\".",
+                                        g_file_get_parse_name (file->priv->location));
+
+               g_object_unref (task);
                return;
        }
 
@@ -461,6 +467,12 @@ gtk_source_file_save_finish (GtkSourceFile  *file,
 
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+       if (g_task_get_source_tag (G_TASK (result)) == file)
+       {
+               return g_task_propagate_boolean (G_TASK (result), error);
+       }
+
        g_return_val_if_fail (file->priv->saver != NULL, FALSE);
 
        ok = gtk_source_file_saver_save_finish (file->priv->saver, file, result, error);


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