[gedit] external tools: look in browser root for files in tool output



commit bc54911e64de7f42baf2be2827ba619fd28a97ca
Author: Adam Dingle <adam yorba org>
Date:   Mon Apr 29 18:26:33 2013 -0400

    external tools: look in browser root for files in tool output
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699227

 plugins/externaltools/tools/filelookup.py  |   21 ++++++++++++++++++++-
 plugins/externaltools/tools/functions.py   |   28 +++++++++++++++++-----------
 plugins/externaltools/tools/outputpanel.py |    2 +-
 3 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/plugins/externaltools/tools/filelookup.py b/plugins/externaltools/tools/filelookup.py
index cc9fa3a..0d88d51 100644
--- a/plugins/externaltools/tools/filelookup.py
+++ b/plugins/externaltools/tools/filelookup.py
@@ -18,6 +18,7 @@
 
 import os
 from gi.repository import Gio, Gedit
+from .functions import *
 
 class FileLookup:
     """
@@ -26,9 +27,10 @@ class FileLookup:
     methods of trying to find the real file.
     """
 
-    def __init__(self):
+    def __init__(self, window):
         self.providers = []
         self.providers.append(AbsoluteFileLookupProvider())
+        self.providers.append(BrowserRootFileLookupProvider(window))
         self.providers.append(CwdFileLookupProvider())
         self.providers.append(OpenDocumentRelPathFileLookupProvider())
         self.providers.append(OpenDocumentFileLookupProvider())
@@ -76,6 +78,23 @@ class AbsoluteFileLookupProvider(FileLookupProvider):
         else:
             return None
 
+class BrowserRootFileLookupProvider(FileLookupProvider):
+    """
+    This lookup provider tries to find a file specified by the path relative to
+    the file browser root.
+    """
+    def __init__(self, window):
+        self.window = window
+
+    def lookup(self, path):
+        root = file_browser_root(self.window)
+        if root:
+            real_path = os.path.join(root, path)
+            if os.path.isfile(real_path):
+                return Gio.file_new_for_path(real_path)
+            
+        return None
+
 
 class CwdFileLookupProvider(FileLookupProvider):
     """
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index 92cedd0..47d3aa9 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -18,7 +18,6 @@
 
 import os
 from gi.repository import Gio, Gtk, Gdk, GtkSource, Gedit
-from .outputpanel import OutputPanel
 from .capture import *
 
 def default(val, d):
@@ -39,6 +38,20 @@ def current_word(document):
             
     return (start, piter)
 
+def file_browser_root(window):
+    bus = window.get_message_bus()
+
+    if bus.is_registered('/plugins/filebrowser', 'get_root'):
+        msg = bus.send_sync('/plugins/filebrowser', 'get_root')
+
+        if msg:
+            browser_root = msg.props.location
+
+            if browser_root and browser_root.is_native():
+                return browser_root.get_path()
+                
+    return None
+
 # ==== Capture related functions ====
 def run_external_tool(window, panel, node):
     # Configure capture environment
@@ -108,16 +121,9 @@ def run_external_tool(window, panel, node):
                         GEDIT_DOCUMENTS_PATH = ' '.join(documents_path))
 
     # set file browser root env var if possible
-    bus = window.get_message_bus()
-
-    if bus.is_registered('/plugins/filebrowser', 'get_root'):
-        msg = bus.send_sync('/plugins/filebrowser', 'get_root')
-
-        if msg:
-            file_browser_root = msg.props.location
-
-            if file_browser_root and file_browser_root.is_native():
-                capture.set_env(GEDIT_FILE_BROWSER_ROOT = file_browser_root.get_path())
+    browser_root = file_browser_root(window)
+    if browser_root:
+        capture.set_env(GEDIT_FILE_BROWSER_ROOT = browser_root)
 
     flags = capture.CAPTURE_BOTH
     
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index e22ed73..3f97c8c 100644
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -92,7 +92,7 @@ class OutputPanel(UniqueById):
         self.links = []
 
         self.link_parser = linkparsing.LinkParser()
-        self.file_lookup = filelookup.FileLookup()
+        self.file_lookup = filelookup.FileLookup(window)
 
     def get_profile_settings(self):
         #FIXME return either the gnome-terminal settings or the gedit one


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