[Zope3-checkins] CVS: Zope3/src/zope/app - copy.py:1.2.2.6

Sidnei da Silva sidnei@x3ng.com.br
Wed, 5 Feb 2003 05:09:45 -0500


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv3236/src/zope/app

Modified Files:
      Tag: paris-copypasterename-branch
	copy.py 
Log Message:
Fixing ObjectMover tests. Adding ObjectCopier tests. Adding AnnotatableUserClipboard with tests. That was a productive night :)

=== Zope3/src/zope/app/copy.py 1.2.2.5 => 1.2.2.6 ===
--- Zope3/src/zope/app/copy.py:1.2.2.5	Tue Feb  4 12:11:33 2003
+++ Zope3/src/zope/app/copy.py	Wed Feb  5 05:09:11 2003
@@ -26,10 +26,13 @@
 from zope.app.interfaces.container import IMoveNotifiable
 from zope.app.interfaces.container import ICopyNotifiable
 from zope.app.interfaces.container import IMoveSource
+from zope.app.interfaces.container import ICopySource
 from zope.app.interfaces.container import IPasteTarget
 from zope.app.interfaces.traversing import IPhysicallyLocatable
-from zope.app.event.objectevent import ObjectMovedEvent
+from zope.app.event.objectevent import ObjectMovedEvent, ObjectCopiedEvent
 from zope.app.event import publish
+from zope.proxy.introspection import removeAllProxies
+from zope.app.attributeannotations import AttributeAnnotations
 
 class ObjectMover:
     '''Use getAdapter(obj, IObjectMover) to move an object somewhere.'''
@@ -140,7 +143,7 @@
         elif queryAdapter(obj, IAddNotifiable):
             getAdapter(obj, IAddNotifiable).manage_afterAdd(obj, container)
 
-        # publish ObjectMovedEvent
+        # publish ObjectCopiedEvent
         publish(container, ObjectCopiedEvent(container, source_path, target_path))
 
         return new_name
@@ -160,3 +163,32 @@
             name = objectName(obj)
         pastetarget = getAdapter(target, IPasteTarget)
         return pastetarget.acceptsObject(name, obj)
+
+class AnnotatableUserClipboard:
+    '''Clipboard information consists on tuples of {'action':action, 'target':target}.
+    '''
+
+    def __init__(self, user):
+        self.context = user
+        self.annotations = AttributeAnnotations(user)
+
+    def clearContents(self):
+        '''Clear the contents of the clipboard'''
+        self.annotations['clipboard'] = ()
+
+    def addItems(self, action, targets):
+        '''Add new items to the clipboard'''
+        contents = self.getContents()
+        actions = []
+        for target in targets:
+            actions.append({'action':action, 'target':target})
+        self.annotations['clipboard'] = contents + tuple(actions)
+
+    def setContents(self, clipboard):
+        '''Replace the contents of the clipboard by the given value'''
+        self.annotations['clipboard'] = clipboard
+
+    def getContents(self):
+        '''Return the contents of the clipboard'''
+        return removeAllProxies(self.annotations.get('clipboard', ()))
+