[meld/pathlabel: 2/10] melddoc: Support gfiles for opening externally




commit b4bc72d4af05000d252356fc4ed7fe19a1e42e6d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 24 06:56:14 2019 +1000

    melddoc: Support gfiles for opening externally

 meld/filediff.py |  8 ++++----
 meld/melddoc.py  | 16 +++++++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 5b83b388..c9e9d657 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1293,9 +1293,8 @@ class FileDiff(Gtk.VBox, MeldDoc):
         pos = self.textbuffer[pane].props.cursor_position
         cursor_it = self.textbuffer[pane].get_iter_at_offset(pos)
         line = cursor_it.get_line() + 1
-        # TODO: Support URI-based opens
-        path = self.textbuffer[pane].data.gfile.get_path()
-        open_files_external([path], line=line)
+        gfiles = [self.textbuffer[pane].data.gfile]
+        open_files_external(gfiles=gfiles, line=line)
 
     def update_text_actions_sensitivity(self, *args):
         widget = self.focus_pane
@@ -1551,12 +1550,13 @@ class FileDiff(Gtk.VBox, MeldDoc):
         start, end = buf.get_bounds()
         buffer_text = buf.get_text(start, end, False)
         if not loader.get_encoding() and '\\00' in buffer_text:
+            filename = GLib.markup_escape_text(gfile.get_parse_name())
             primary = _("File %s appears to be a binary file.") % filename
             secondary = _(
                 "Do you want to open the file using the default application?")
             self.msgarea_mgr[pane].add_action_msg(
                 'dialog-warning-symbolic', primary, secondary, _("Open"),
-                functools.partial(open_files_external, [gfile.get_path()]))
+                functools.partial(open_files_external, gfiles=[gfile]))
 
         self.update_buffer_writable(buf)
 
diff --git a/meld/melddoc.py b/meld/melddoc.py
index a7aa6914..f3ffd888 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -22,7 +22,7 @@ import shlex
 import string
 import subprocess
 import sys
-from typing import Iterable, Sequence
+from typing import Iterable, List, Optional, Sequence
 
 from gi.repository import Gdk, Gio, GLib, GObject, Gtk
 
@@ -50,9 +50,9 @@ def make_custom_editor_command(path: str, line: int = 0) -> Sequence[str]:
 
 
 def open_files_external(
-        self, selected: Iterable[str], *, line: int = 0) -> None:
-    query_attrs = ",".join((Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
-                            Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
+        paths: Optional[List[str]] = None, *,
+        gfiles: Optional[List[Gio.File]] = None,
+        line: int = 0) -> None:
 
     def os_open(path: str, uri: str):
         if not path:
@@ -100,7 +100,13 @@ def open_files_external(
             # TODO: Add some kind of 'failed to open' notification
             pass
 
-    for f in [Gio.File.new_for_path(s) for s in selected]:
+    query_attrs = ",".join((Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
+                            Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
+
+    if not gfiles:
+        gfiles = [Gio.File.new_for_path(s) for s in paths]
+
+    for f in gfiles:
         f.query_info_async(
             query_attrs, Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_LOW,
             None, open_cb, None)


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