[kupfer] puid: Resolve actions by reference



commit 35e45647094be1bd8cb3bba89d9f993e836a66f4
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 5 03:57:09 2010 +0100

    puid: Resolve actions by reference
    
    Resolve actions by reference: it's quite simple, the catalog is very
    small. Support resolving builtin actions if a leaf is given, else we
    look in the action decorator "library", which also will just look at
    currently loaded plugins.
    
    This is so that less objects are serialized by general. This way, we
    never need to serialize actions.

 kupfer/objects.py |   10 ++++++----
 kupfer/puid.py    |   18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 83b48e8..921faa7 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -451,7 +451,6 @@ class Action (KupferObject):
 		"""
 		return True
 	'''
-	serilizable = True
 
 	def repr_key(self):
 		"""by default, actions of one type are all the same"""
@@ -1174,10 +1173,13 @@ class ComposedLeaf (RunnableLeaf):
 	def __setstate__(self, state):
 		from kupfer import puid
 		vars(self).update(state)
-		self.object[:] = [puid.resolve_unique_id(I) for I in state["object"]]
-		if (not self.object[0] or not self.object[1] or
-				(I is None) != (self.object[2] is None)):
+		objid, actid, iobjid = state["object"]
+		obj = puid.resolve_unique_id(objid)
+		act = puid.resolve_action_id(actid, obj)
+		iobj = puid.resolve_unique_id(iobjid)
+		if (not obj or not act) or (iobj is None) != (iobjid is None):
 			raise InvalidDataError("Parts of %s not restored" % unicode(self))
+		self.object[:] = [obj, act, iobj]
 
 	def get_actions(self):
 		yield Do()
diff --git a/kupfer/puid.py b/kupfer/puid.py
index d1ccc87..0754c68 100644
--- a/kupfer/puid.py
+++ b/kupfer/puid.py
@@ -101,3 +101,21 @@ def resolve_unique_id(puid, excluding=None):
 	pretty.print_debug(__name__, "Resolving %s to %s" % (puid, obj))
 	return obj
 
+def resolve_action_id(puid, for_item=None):
+	if puid is None:
+		return None
+	if isinstance(puid, SerializedObject):
+		return resolve_unique_id(puid)
+	get_action_id = repr
+	if for_item is not None:
+		for action in for_item.get_actions():
+			if get_unique_id(action) == puid:
+				pretty.print_debug(__name__, "Resolving (Builtin)", puid)
+				return action
+	sc = data.GetSourceController()
+	for item_type, actions in sc.action_decorators.iteritems():
+		for action in actions:
+			if get_action_id(action) == puid:
+				pretty.print_debug(__name__, "Resolving (Decorator)", puid)
+				return action
+	return None



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