[kupfer: 3/38] commatrick: Define action logic inside commandexec



commit 5905095de4a47018cec3b07934d996cc395b7429
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Jan 14 22:31:18 2010 +0100

    commatrick: Define action logic inside commandexec

 kupfer/commandexec.py |   12 ++++++++++++
 kupfer/core/data.py   |   10 +++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index 25934d9..04e93e4 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -121,3 +121,15 @@ gobject.signal_new("command-result", ActionExecutionContext,
 		gobject.TYPE_BOOLEAN, (gobject.TYPE_INT, gobject.TYPE_PYOBJECT))
 
 
+def action_valid_for_item(action, leaf):
+	return action.valid_for_item(leaf)
+
+def actions_for_item(leaf, sourcecontroller):
+	if leaf is None:
+		return []
+	actions = list(leaf.get_actions())
+	if leaf:
+		for act in sourcecontroller.get_actions_for_leaf(leaf):
+			actions.append(act)
+	return actions
+
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index 0c971b5..48fd2c4 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -313,19 +313,15 @@ class PrimaryActionPane (Pane):
 
 		self.latest_key = key
 		leaf = self.current_item
-		actions = list(leaf.get_actions()) if leaf else []
-		sc = GetSourceController()
-		if leaf:
-			for act in sc.get_actions_for_leaf(leaf):
-				actions.append(act)
+		actions = commandexec.actions_for_item(leaf, GetSourceController())
 
 		def is_valid_cached(action):
 			"""Check if @action is valid for current item"""
 			cache = self._action_valid_cache
 			valid = cache.get(action)
 			if valid is None:
-				valid = action.valid_for_item(self.current_item)
-			cache[action] = valid
+				valid = commandexec.action_valid_for_item(action, leaf)
+				cache[action] = valid
 			return valid
 
 		def valid_decorator(seq):



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