[gnome-text-editor] document: remove drafts for files without changes



commit c953d4601ed860729c0dfaaa54f7d2b4345303b9
Author: Christian Hergert <chergert redhat com>
Date:   Mon Dec 13 16:58:04 2021 -0800

    document: remove drafts for files without changes
    
    If we have a draft around and the file is not modified, we want to remove
    the backing file so that we don't show the user a discard infobar after
    restarting the application.

 src/editor-document.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index f9d7798..2965c45 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -733,6 +733,17 @@ _editor_document_save_draft_async (EditorDocument      *self,
   if (self->encoding != NULL)
     gtk_source_file_saver_set_encoding (saver, self->encoding);
 
+  /* If there are no modifications, then delete any backing file
+   * for the draft so we don't risk reloading it.
+   */
+  if (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (self)) &&
+      editor_document_get_file (self) != NULL)
+    {
+      g_file_delete (draft_file, NULL, NULL);
+      g_task_return_boolean (task, TRUE);
+      return;
+    }
+
   /* TODO: Probably want to make this async. We can just create an
    * async variant in editor-utils.c for this.
    */


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