[kupfer] plugin.commands: Implement Shell Commands as TextLeaf



commit f01e1eec24b6e4948828f69ca9fd81200260a132
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Dec 10 15:04:09 2009 +0100

    plugin.commands: Implement Shell Commands as TextLeaf
    
    By making a typed shell command inherit from TextLeaf we solve two
    problems:
    
    * Users can now favorite command lines. Type in a long commandline
      once, favorite it, and now it will be found if you just type the
      beginning of it.
    
    * If you unintentionally start a text string with a command name (like
      test), you can still use the command object like a string, so you
      don't need to press down-arrow to select text. Just type ".",
      "test", Tab, "Search With..", Tab, "Google".

 kupfer/objects.py         |   12 +++++++-----
 kupfer/plugin/commands.py |   22 +++++++++++++---------
 2 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 778da98..17ed153 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -676,18 +676,19 @@ class Execute (Launch):
 	"""
 	Execute executable file (FileLeaf)
 	"""
-	def __init__(self, in_terminal=False, args=""):
+	rank_adjust = 5
+	def __init__(self, in_terminal=False, quoted=True):
 		name = _("Run in Terminal") if in_terminal else _("Run")
 		super(Execute, self).__init__(name)
 		self.in_terminal = in_terminal
-		self.args = args
+		self.quoted = quoted
 
 	def repr_key(self):
-		return self.in_terminal
+		return (self.in_terminal, self.quoted)
 	
 	def activate(self, leaf):
-		cli = "'%s' %s" % (leaf.object, self.args)
-		utils.launch_commandline(cli, in_terminal=self.in_terminal)
+		cmd = "'%s'" % leaf.object if self.quoted else leaf.object
+		utils.launch_commandline(cmd, in_terminal=self.in_terminal)
 
 	def get_description(self):
 		if self.in_terminal:
@@ -695,6 +696,7 @@ class Execute (Launch):
 		else:
 			return _("Run this program")
 
+
 class DummyAction (Action):
 	"""
 	Represents "No action", to be shown when there is no action
diff --git a/kupfer/plugin/commands.py b/kupfer/plugin/commands.py
index 9bdec41..3defec4 100644
--- a/kupfer/plugin/commands.py
+++ b/kupfer/plugin/commands.py
@@ -4,7 +4,8 @@ from os import access, R_OK, X_OK, path
 
 import gobject
 
-from kupfer.objects import TextSource, FileLeaf, Leaf, Execute
+from kupfer.objects import TextSource, Leaf
+from kupfer.objects import TextLeaf, Execute
 from kupfer import utils, icons
 
 __kupfer_name__ = _("Shell Commands")
@@ -14,19 +15,22 @@ __description__ = _("Run commandline programs")
 __version__ = ""
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
-class Command (Leaf):
-	def __init__(self, obj, name):
-		Leaf.__init__(self, obj, name)
-		self.args = " ".join(name.split(" ", 1)[1:])
+class Command (TextLeaf):
+	def __init__(self, exepath, name):
+		TextLeaf.__init__(self, name, name)
+		self.exepath = exepath
 
 	def get_actions(self):
-		yield Execute(args=self.args)
-		yield Execute(in_terminal=True, args=self.args)
+		yield Execute(quoted=False)
+		yield Execute(in_terminal=True, quoted=False)
 
 	def get_description(self):
-		return "%s %s" % (self.object, self.args)
+		args = u" ".join(unicode(self).split(None, 1)[1:])
+		return u"%s %s" % (self.exepath, args)
+
 	def get_gicon(self):
-		icons.get_gicon_for_file(self.object)
+		return icons.get_gicon_for_file(self.exepath)
+
 	def get_icon_name(self):
 		return "exec"
 



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