[meld] filediff: Move users of check-save workflow to confirm-discard instead



commit 1c0c298592a00481c7b9c2f9929cd723cd4151be
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Jan 1 11:13:23 2019 +1000

    filediff: Move users of check-save workflow to confirm-discard instead
    
    The benefit here is that while state in check-save is async (because we
    use the async saving of GtkSource.FileSaver), confirm-discard has no
    state and is a straight up modal confirm with no complications.
    
    The places we're now doing this is when the user changes the file
    selector, and when they drag-n-drop a new file on to the pane. In both
    cases, I think these aren't situations where the user is likely to
    actually have accidentally forgotten to save (since they're extremely
    deliberate manipulations of the current comparison), so the simple
    confirm seems like a reasonable complexity trade-off.

 meld/filediff.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 154df5de..08f12093 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -777,12 +777,12 @@ class FileDiff(MeldDoc, Component):
             gfiles = [Gio.File.new_for_uri(uri) for uri in uris]
 
             if len(gfiles) == self.num_panes:
-                if self.check_save_modified() == Gtk.ResponseType.OK:
+                if self.check_unsaved_changes():
                     self.set_files(gfiles)
             elif len(gfiles) == 1:
                 pane = self.textview.index(widget)
                 buffer = self.textbuffer[pane]
-                if self.check_save_modified([buffer]) == Gtk.ResponseType.OK:
+                if self.check_unsaved_changes([buffer]):
                     self.set_file(pane, gfiles[0])
             return True
 
@@ -1684,7 +1684,7 @@ class FileDiff(MeldDoc, Component):
     def on_fileentry_file_set(self, entry):
         pane = self.fileentry[:self.num_panes].index(entry)
         buffer = self.textbuffer[pane]
-        if self.check_save_modified([buffer]) == Gtk.ResponseType.OK:
+        if self.check_unsaved_changes():
             # TODO: Use encoding file selectors in FileDiff
             self.set_file(pane, entry.get_file())
         else:
@@ -1698,6 +1698,14 @@ class FileDiff(MeldDoc, Component):
         return -1
 
     def check_unsaved_changes(self, buffers=None):
+        """Confirm discard of any unsaved changes
+
+        Unlike `check_save_modified`, this does *not* prompt the user
+        to save, but rather just confirms whether they want to discard
+        changes. This simplifies call sites a *lot* because they don't
+        then need to deal with the async state/callback issues
+        associated with saving a file.
+        """
         buffers = buffers or self.textbuffer
         unsaved = [b.data.label for b in buffers if b.get_modified()]
         if not unsaved:


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