[meld] filediff: Offer to open binary files externally (bgo#665154)



commit 32ab99ebf8afc37ff3bead2c9380a6a3897a9c14
Author: Pratik Dayama <pratik dayama63 gmail com>
Date:   Sat Sep 26 07:32:28 2015 +1000

    filediff: Offer to open binary files externally (bgo#665154)
    
    If we think we've got a binary file, currently Meld just refuses to
    display it. It's somewhat more useful to to offer to open this file in
    whatever program we think will be able to view it. This is primarily
    for file comparisons started from folder comparisons, though VC
    comparisons will also benefit somewhat.

 meld/filediff.py |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index ff461c6..0aabdba 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1084,9 +1084,24 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                     if nextbit.find("\x00") != -1:
                         t.buf.delete(*t.buf.get_bounds())
                         filename = GObject.markup_escape_text(t.filename)
-                        add_dismissable_msg(t.pane, Gtk.STOCK_DIALOG_ERROR,
-                            _("Could not read file"),
-                            _("%s appears to be a binary file.") % filename)
+
+                        primary = _("File %s appears to be a binary file.") % filename
+                        secondary = _("Do you want to open the file using the default application?")
+                        msgarea = self.msgarea_mgr[t.pane].new_from_text_and_icon(
+                                        Gtk.STOCK_DIALOG_WARNING, primary, secondary)
+                        msgarea.add_button(_("Open"), Gtk.ResponseType.ACCEPT)
+                        msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
+
+                        def make_binary_callback(pane, filename):
+                            def on_binary_file_open(msgarea, response_id, *args):
+                                self.msgarea_mgr[pane].clear()
+                                if response_id == Gtk.ResponseType.ACCEPT:
+                                    self._open_files([filename])
+                                return on_binary_file_open
+                            return on_binary_file_open
+
+                        msgarea.connect("response", make_binary_callback(t.pane, t.filename))
+                        msgarea.show_all()
                         tasks.remove(t)
                         continue
                 except ValueError as err:


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