[meld] filediff: Break out the file-changed check on Revert for reuse
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff: Break out the file-changed check on Revert for reuse
- Date: Fri, 19 Jan 2018 20:06:56 +0000 (UTC)
commit 46372b1b3e15b7ed8ea30fc471d49be26790033c
Author: Kai Willadsen <kai willadsen gmail com>
Date: Fri Jan 19 06:23:01 2018 +1000
filediff: Break out the file-changed check on Revert for reuse
meld/filediff.py | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index a98a3921..e04dc496 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1695,24 +1695,29 @@ class FileDiff(MeldDoc, Component):
return i
return -1
- def on_revert_activate(self, *extra):
- response = Gtk.ResponseType.OK
+ def check_unsaved_changes(self):
unsaved = [b.data.label for b in self.textbuffer if b.get_modified()]
- if unsaved:
- dialog = Component("filediff.ui", "revert_dialog")
- dialog.widget.set_transient_for(self.widget.get_toplevel())
- # FIXME: Should be packed into dialog.widget.get_message_area(),
- # but this is unbound on currently required PyGTK.
- filelist = "\n".join(["\t" + f for f in unsaved])
- dialog.widget.props.secondary_text += filelist
- response = dialog.widget.run()
- dialog.widget.destroy()
+ if not unsaved:
+ return True
- if response == Gtk.ResponseType.OK:
- buffers = self.textbuffer[:self.num_panes]
- gfiles = [b.data.gfile for b in buffers]
- encodings = [b.data.encoding for b in buffers]
- self.set_files(gfiles, encodings=encodings)
+ dialog = Component("filediff.ui", "revert_dialog")
+ dialog.widget.set_transient_for(self.widget.get_toplevel())
+ # FIXME: Should be packed into dialog.widget.get_message_area(),
+ # but this is unbound on currently required PyGTK.
+ filelist = "\n".join(["\t" + f for f in unsaved])
+ dialog.widget.props.secondary_text += filelist
+ response = dialog.widget.run()
+ dialog.widget.destroy()
+ return response == Gtk.ResponseType.OK
+
+ def on_revert_activate(self, *extra):
+ if not self.check_unsaved_changes():
+ return
+
+ buffers = self.textbuffer[:self.num_panes]
+ gfiles = [b.data.gfile for b in buffers]
+ encodings = [b.data.encoding for b in buffers]
+ self.set_files(gfiles, encodings=encodings)
def on_refresh_activate(self, *extra):
self.refresh_comparison()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]