[gnome-text-editor] savechangesdialog: avoid reloading during discard



commit 1e7152f17aedda086869ecbe5aeed5e5447d2ae3
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 6 12:05:54 2021 -0700

    savechangesdialog: avoid reloading during discard
    
    In the case of the save changes dialog, discard has a different meaning
    than where it is used elsewhere (to reload the backing file).
    
    Just skip the reloading phase and destroy the page/document instead.
    
    Fixes #176

 src/editor-page-private.h        |  1 +
 src/editor-page.c                | 19 ++++++++++++++-----
 src/editor-save-changes-dialog.c |  2 ++
 3 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/editor-page-private.h b/src/editor-page-private.h
index 506ab52..7ef145f 100644
--- a/src/editor-page-private.h
+++ b/src/editor-page-private.h
@@ -68,6 +68,7 @@ void          _editor_page_save                   (EditorPage           *self);
 void          _editor_page_save_as                (EditorPage           *self);
 void          _editor_page_raise                  (EditorPage           *self);
 void          _editor_page_discard_changes_async  (EditorPage           *self,
+                                                   gboolean              reload,
                                                    GCancellable         *cancellable,
                                                    GAsyncReadyCallback   callback,
                                                    gpointer              user_data);
diff --git a/src/editor-page.c b/src/editor-page.c
index 4df8f5f..e3fe1c1 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -1180,6 +1180,7 @@ editor_page_delete_draft_cb (GObject      *object,
   EditorSession *session = EDITOR_SESSION_DEFAULT;
   g_autoptr(GTask) task = user_data;
   g_autoptr(GError) error = NULL;
+  gboolean reload;
   EditorPage *self;
 
   g_assert (G_IS_FILE (file));
@@ -1187,6 +1188,7 @@ editor_page_delete_draft_cb (GObject      *object,
   g_assert (G_IS_TASK (task));
 
   self = g_task_get_source_object (task);
+  reload = GPOINTER_TO_INT (g_task_get_task_data (task));
 
   if (!g_file_delete_finish (file, result, &error))
     {
@@ -1208,6 +1210,11 @@ editor_page_delete_draft_cb (GObject      *object,
                                     _editor_document_get_draft_id (self->document));
       g_task_return_boolean (task, TRUE);
     }
+  else if (!reload)
+    {
+      editor_session_remove_page (session, self);
+      g_task_return_boolean (task, TRUE);
+    }
   else
     {
       _editor_document_load_async (self->document,
@@ -1219,10 +1226,11 @@ editor_page_delete_draft_cb (GObject      *object,
 }
 
 void
-_editor_page_discard_changes_async  (EditorPage          *self,
-                                     GCancellable        *cancellable,
-                                     GAsyncReadyCallback  callback,
-                                     gpointer             user_data)
+_editor_page_discard_changes_async (EditorPage          *self,
+                                    gboolean             reload,
+                                    GCancellable        *cancellable,
+                                    GAsyncReadyCallback  callback,
+                                    gpointer             user_data)
 {
   g_autoptr(GFile) draft_file = NULL;
   g_autoptr(GTask) task = NULL;
@@ -1232,6 +1240,7 @@ _editor_page_discard_changes_async  (EditorPage          *self,
 
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task, _editor_page_discard_changes_async);
+  g_task_set_task_data (task, GINT_TO_POINTER (reload), NULL);
 
   draft_file = _editor_document_get_draft_file (self->document);
 
@@ -1259,7 +1268,7 @@ _editor_page_discard_changes (EditorPage *self)
   g_return_if_fail (EDITOR_IS_PAGE (self));
 
   _editor_page_raise (self);
-  _editor_page_discard_changes_async (self, NULL, NULL, NULL);
+  _editor_page_discard_changes_async (self, TRUE, NULL, NULL, NULL);
 }
 
 void
diff --git a/src/editor-save-changes-dialog.c b/src/editor-save-changes-dialog.c
index b3bb2c9..8a50699 100644
--- a/src/editor-save-changes-dialog.c
+++ b/src/editor-save-changes-dialog.c
@@ -132,6 +132,7 @@ editor_save_changes_dialog_discard (GtkMessageDialog *dialog,
       const SaveRequest *sr = &g_array_index (requests, SaveRequest , i);
 
       _editor_page_discard_changes_async (sr->page,
+                                          FALSE,
                                           NULL,
                                           editor_save_changes_dialog_discard_cb,
                                           g_array_ref (requests));
@@ -171,6 +172,7 @@ editor_save_changes_dialog_save_cb (GObject      *object,
             editor_save_changes_dialog_remove (requests, i);
           else
             _editor_page_discard_changes_async (sr->page,
+                                                FALSE,
                                                 NULL,
                                                 editor_save_changes_dialog_discard_cb,
                                                 g_array_ref (requests));


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