[meld] Handle opening files on non-GNOME, non-gconf platforms
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Handle opening files on non-GNOME, non-gconf platforms
- Date: Sun, 20 Mar 2011 03:30:47 +0000 (UTC)
commit 7aca25ad08caa488454fed8166a2f28a27df5728
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Mar 5 16:45:19 2011 +1000
Handle opening files on non-GNOME, non-gconf platforms
meld/melddoc.py | 26 +++++++++++++++-----------
meld/preferences.py | 47 +++++++++++++++++++++++++++--------------------
2 files changed, 42 insertions(+), 31 deletions(-)
---
diff --git a/meld/melddoc.py b/meld/melddoc.py
index 776532b..55718ae 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -64,20 +64,24 @@ class MeldDoc(gobject.GObject):
def _open_files(self, selected):
files = [f for f in selected if os.path.isfile(f)]
dirs = [d for d in selected if os.path.isdir(d)]
+
+ def os_open(paths):
+ for path in paths:
+ if sys.platform == "win32":
+ subprocess.Popen(["start", path], shell=True)
+ elif sys.platform == "darwin":
+ subprocess.Popen(["open", path])
+ else:
+ subprocess.Popen(["xdg-open", path])
+
if len(files):
- if self.prefs.edit_command_type == "custom":
- cmd = self.prefs.get_custom_editor_command(files)
+ cmd = self.prefs.get_editor_command(files)
+ if cmd:
os.spawnvp(os.P_NOWAIT, cmd[0], cmd)
- else: # self.prefs.edit_command_type == "gnome" or "internal"
- cmd = self.prefs.get_gnome_editor_command(files)
- os.spawnvp(os.P_NOWAIT, cmd[0], cmd)
- for d in dirs:
- if sys.platform == "win32":
- subprocess.Popen(["start", d], shell=True)
- elif sys.platform == "darwin":
- subprocess.Popen(["open", d])
else:
- subprocess.Popen(["xdg-open", d])
+ os_open(files)
+
+ os_open(dirs)
def on_undo_activate(self):
if self.undosequence.can_undo():
diff --git a/meld/preferences.py b/meld/preferences.py
index 3a4f4d6..7c10bb7 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -124,7 +124,8 @@ class PreferencesDialog(gnomeglade.Component):
self.prefs.edit_command_type == "gnome"
self.system_editor_checkbutton.set_active(use_default)
self.custom_edit_command_entry.set_sensitive(not use_default)
- self.custom_edit_command_entry.set_text( " ".join(self.prefs.get_custom_editor_command([])) )
+ custom_command = " ".join(self.prefs.get_editor_command([], "custom"))
+ self.custom_edit_command_entry.set_text(custom_command)
# file filters
self.filefilter = FilterList(self.prefs, "filters",
@@ -275,23 +276,29 @@ class MeldPreferences(prefs.Preferences):
}[style]
return style
- def get_gnome_editor_command(self, files):
- if not hasattr(self, "_gconf"):
- return []
- argv = []
- editor = self._gconf.get_string('/desktop/gnome/applications/editor/exec') or "gedit"
- if self._gconf.get_bool("/desktop/gnome/applications/editor/needs_term"):
- texec = self._gconf.get_string("/desktop/gnome/applications/terminal/exec")
- if texec:
- argv.append(texec)
- targ = self._gconf.get_string("/desktop/gnome/applications/terminal/exec_arg")
- if targ:
- argv.append(targ)
- argv.append( "%s %s" % (editor, " ".join( [f.replace(" ","\\ ") for f in files]) ) )
- else:
- argv = [editor] + files
- return argv
-
- def get_custom_editor_command(self, files):
- return self.edit_command_custom.split() + files
+ def get_editor_command(self, files, command_type=None):
+ if command_type is None:
+ command_type = self.edit_command_type
+ if command_type == "custom":
+ return self.edit_command_custom.split() + files
+ else:
+ if not hasattr(self, "_gconf"):
+ return []
+
+ editor_path = "/desktop/gnome/applications/editor/"
+ terminal_path = "/desktop/gnome/applications/terminal/"
+ editor = self._gconf.get_string(editor_path + "exec") or "gedit"
+ if self._gconf.get_bool(editor_path + "needs_term"):
+ argv = []
+ texec = self._gconf.get_string(terminal_path + "exec")
+ if texec:
+ argv.append(texec)
+ targ = self._gconf.get_string(terminal_path + "exec_arg")
+ if targ:
+ argv.append(targ)
+ escaped_files = [f.replace(" ", "\\ ") for f in files]
+ argv.append("%s %s" % (editor, " ".join(escaped_files)))
+ return argv
+ else:
+ return [editor] + files
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]