[kupfer: 8/38] commatrick: Check valid iobjects in commandexec



commit 90166dc3cbf2579fb1f2f65f954fd0de52059646
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Jan 14 23:57:55 2010 +0100

    commatrick: Check valid iobjects in commandexec

 kupfer/commandexec.py |   28 ++++++++++++++++++++++++++++
 kupfer/core/data.py   |   22 ++++------------------
 2 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index 7e4d4e6..854db61 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -167,3 +167,31 @@ def actions_for_item(leaf, sourcecontroller):
 			actions.intersection_update(l_actions)
 	return actions
 
+def iobjects_valid_for_action(action, for_item):
+	"""
+	Return a filtering *function* that will let through
+	those leaves that are good iobjects for @action and @for_item.
+	"""
+	def valid_object(leaf, for_item):
+		_valid_object = action.valid_object
+		for L in _get_leaf_members(leaf):
+			for I in _get_leaf_members(for_item):
+				if not _valid_object(L, for_item=I):
+					return False
+		return True
+
+	types = tuple(action.object_types())
+	def type_obj_check(iobjs):
+		for i in iobjs:
+			if (isinstance(i, types) and valid_object(i, for_item=for_item)):
+				yield i
+	def type_check(itms):
+		for i in itms:
+			if isinstance(i, types):
+				yield i
+
+	if hasattr(action, "valid_object"):
+		return type_obj_check
+	else:
+		return type_check
+
diff --git a/kupfer/core/data.py b/kupfer/core/data.py
index 210c678..d6c2b5b 100644
--- a/kupfer/core/data.py
+++ b/kupfer/core/data.py
@@ -381,23 +381,8 @@ class SecondaryObjectPane (LeafPane):
 			textsrcs = sc.get_text_sources()
 			sources.extend(textsrcs)
 
-		types = tuple(self.current_action.object_types())
-		def type_obj_check(itms):
-			valid_object = self.current_action.valid_object
-			item = self.current_item
-			for i in itms:
-				if (isinstance(i, types) and valid_object(i, for_item=item)):
-					yield i
-		def type_check(itms):
-			for i in itms:
-				if isinstance(i, types):
-					yield i
-
-		if hasattr(self.current_action, "valid_object"):
-			item_check = type_obj_check
-		else:
-			item_check = type_check
-
+		item_check = commandexec.iobjects_valid_for_action(self.current_action,
+				self.current_item)
 		decorator = lambda seq: dress_leaves(seq, action=self.current_action)
 
 		match, match_iter = self.searcher.search(sources, key, score=True,
@@ -668,7 +653,8 @@ class DataController (gobject.GObject, pretty.OutputMixin):
 				self.emit("mode-changed", self.mode, item)
 			if self.mode is SourceActionObjectMode:
 				# populate third pane
-				self.object_pane.set_item_and_action(self.source_pane.get_selection(), item)
+				citem = self._get_pane_object_composed(self.source_pane)
+				self.object_pane.set_item_and_action(citem, item)
 				self.search(ObjectPane, lazy=True)
 		elif pane is ObjectPane:
 			assert not item or isinstance(item, base.Leaf), \



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