[meld] Enable opening files externally at a particular line number



commit 398c7251f3d945ca3d14a673bf33d2dc0f8de4cd
Author: Konstantin Starojitski <starojitski gmail com>
Date:   Thu Apr 11 05:39:36 2013 +1000

    Enable opening files externally at a particular line number

 meld/filediff.py    |  5 ++++-
 meld/melddoc.py     |  7 ++++---
 meld/preferences.py | 15 +++++++++++++--
 3 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 50714aa..de73765 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -870,7 +870,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         pane = self._get_focused_pane()
         if pane >= 0:
             if self.textbuffer[pane].data.filename:
-                self._open_files([self.textbuffer[pane].data.filename])
+                pos = self.textbuffer[pane].props.cursor_position
+                cursor_it = self.textbuffer[pane].get_iter_at_offset(pos)
+                line = cursor_it.get_line() + 1
+                self._open_files([self.textbuffer[pane].data.filename], line)
 
     def get_selected_text(self):
         """Returns selected text of active pane"""
diff --git a/meld/melddoc.py b/meld/melddoc.py
index 04bab52..6427007 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -77,7 +77,7 @@ class MeldDoc(gobject.GObject):
         if self.scheduler.tasks_pending():
             self.scheduler.remove_task(self.scheduler.get_current_task())
 
-    def _open_files(self, selected):
+    def _open_files(self, selected, line=0):
         query_attrs = ",".join((gio.FILE_ATTRIBUTE_STANDARD_TYPE,
                                 gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
 
@@ -99,8 +99,9 @@ class MeldDoc(gobject.GObject):
             elif file_type == gio.FILE_TYPE_REGULAR:
                 content_type = info.get_content_type()
                 path = source.get_path()
-                if gio.content_type_is_a(content_type, "text/plain"):
-                    editor = self.prefs.get_editor_command([path])
+                # content_type_is_a does not seem to work on windows
+                if gio.content_type_is_a(content_type, "text/plain") or sys.platform == "win32":
+                    editor = self.prefs.get_editor_command([path], line)
                     if editor:
                         subprocess.Popen(editor)
                     else:
diff --git a/meld/preferences.py b/meld/preferences.py
index 244bbff..a2bb74b 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -20,6 +20,7 @@
 from gettext import gettext as _
 
 import gtk
+import re
 
 from . import filters
 from . import misc
@@ -366,9 +367,19 @@ class MeldPreferences(prefs.Preferences):
         }
         return toolbar_styles[style]
 
-    def get_editor_command(self, files):
+    def get_editor_command(self, files, line=0):
         if self.edit_command_type == "custom":
-            return self.edit_command_custom.split() + files
+            custom_command = self.edit_command_custom
+            matches = re.search('(?P<editor>.+)(?:\s+)(?P<param>.*)', custom_command)
+            if matches:
+                # first part is the editor itself
+                custom_command = matches.group('editor')
+                # second part may contain optional parameters
+                # if it contains "{file}" than process it and modify files array
+                if matches.group('param').count('{file}') > 0:
+                    files[0] = matches.group('param').replace("{file}", files[0])
+                    files[0] = files[0].replace("{line}", str(line))
+            return [custom_command] + files
         else:
             if not hasattr(self, "_gconf"):
                 return []


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