summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-13 23:35:25 +0100
committerhut <hut@lavabit.com>2010-01-13 23:35:25 +0100
commit0bc410c523f397f9c46c04ded5b3da1da65a6242 (patch)
tree1bc418f59ad2d3cd5fccdc1e6dee8ae667a931e7 /ranger
parent1f9a86d1515416a03721be261ae8fc937f129e9d (diff)
downloadranger-0bc410c523f397f9c46c04ded5b3da1da65a6242.tar.gz
commandlist: aliases are now references rather than copies
Diffstat (limited to 'ranger')
-rw-r--r--ranger/container/commandlist.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py
index c40d0a5b..302564c9 100644
--- a/ranger/container/commandlist.py
+++ b/ranger/container/commandlist.py
@@ -132,14 +132,10 @@ class CommandList(object):
 		existing = self._str_to_tuple(existing)
 		new = tuple(map(self._str_to_tuple, new))
 
-		try:
-			cmd = self.paths[existing]
-		except KeyError:
-			self.unbind(*new)
-		else:
-			for key in new:
-				self.paths[key] = cmd
-				cmd.keys |= set([key])
+		obj = AliasedCommand(_make_getter(self.paths, existing), new)
+
+		for key in new:
+			self.paths[key] = obj
 
 	def unbind(self, *keys):
 		i = len(self.commandlist)
@@ -179,6 +175,16 @@ class Command(object):
 #	def __str__(self):
 #		return 'Cmd({0})'.format(str(self.keys))
 
+class AliasedCommand(Command):
+	def __init__(self, getter, keys):
+		self.getter = getter
+		self.keys = set(keys)
+
+	def get_execute(self):
+		return self.getter()
+
+	execute = property(get_execute)
+
 class Hint(object):
 	"""Hints display text without clearing the keybuffer"""
 
@@ -191,3 +197,11 @@ class Hint(object):
 
 #	def __str__(self):
 #		return 'Hint({0})'.format(str(self.keys))
+
+def _make_getter(paths, key):
+	def getter():
+		try:
+			return paths[key].execute
+		except:
+			return lambda: None
+	return getter