[kupfer: 6/38] commatrick: Multiple action dispatch
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 6/38] commatrick: Multiple action dispatch
- Date: Sat, 16 Jan 2010 17:12:18 +0000 (UTC)
commit 62f24b49733dc21a04880610b825d8f881bb2581
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Jan 14 23:06:52 2010 +0100
commatrick: Multiple action dispatch
kupfer/commandexec.py | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index cb9e7f9..7e4d4e6 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -21,12 +21,31 @@ class ActionExecutionError (Exception):
def activate_action(obj, action, iobj):
""" Activate @action in simplest manner """
+ if not _is_multiple(obj) and not _is_multiple(iobj):
+ return _activate_action_single(obj, action, iobj)
+ else:
+ return _activate_action_multiple(obj, action, iobj)
+
+def _activate_action_single(obj, action, iobj):
if action.requires_object():
ret = action.activate(obj, iobj)
else:
ret = action.activate(obj)
return ret
+def _activate_action_multiple(obj, action, iobj):
+ if not hasattr(action, "activate_multiple"):
+ ret = None
+ for leaf in _get_leaf_members(obj):
+ ret = _activate_action_single(leaf, action, iobj) or ret
+ return ret
+
+ if action.requires_object():
+ ret = action.activate_multiple(_get_leaf_members(obj), _get_leaf_members(iobj))
+ else:
+ ret = action.activate_multiple(_get_leaf_members(obj))
+ return ret
+
def parse_action_result(action, ret):
"""Return result type for @action and return value @ret"""
def valid_result(ret):
@@ -120,6 +139,9 @@ gobject.signal_new("command-result", ActionExecutionContext,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_BOOLEAN, (gobject.TYPE_INT, gobject.TYPE_PYOBJECT))
+def _is_multiple(leaf):
+ return hasattr(leaf, "get_multiple_leaf_representation")
+
def _get_leaf_members(leaf):
"""
Return an iterator to members of @leaf, if it is a multiple leaf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]