[Zope3-checkins] CVS: Zope3/src/zope/app - _app.py:1.6 configure.zcml:1.11 copy.py:1.3

Sidnei da Silva sidnei@x3ng.com.br
Tue, 11 Feb 2003 11:00:30 -0500


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

Modified Files:
	_app.py configure.zcml copy.py 
Log Message:
Merging paris-copypasterename-branch. Not very fun :(

=== Zope3/src/zope/app/_app.py 1.5 => 1.6 ===


=== Zope3/src/zope/app/configure.zcml 1.10 => 1.11 ===
--- Zope3/src/zope/app/configure.zcml:1.10	Fri Feb  7 10:59:35 2003
+++ Zope3/src/zope/app/configure.zcml	Tue Feb 11 10:59:28 2003
@@ -64,12 +64,20 @@
   <adapter
       factory="zope.app.copy.ObjectMover"
       provides="zope.app.interfaces.copy.IObjectMover"
+      permission="zope.ManageContent" 
       for="*" />
 
   <adapter
       factory="zope.app.copy.ObjectCopier"
       provides="zope.app.interfaces.copy.IObjectCopier"
+      permission="zope.ManageContent" 
       for="*" />
+
+  <adapter
+      factory="zope.app.copy.PrincipalClipboard"
+      provides="zope.app.interfaces.copy.IPrincipalClipboard"
+      permission="zope.ManageContent" 
+      for="zope.app.interfaces.annotation.IAnnotations" />
 
   <include package="zope.app.container" />
   <include package="zope.app.content" />


=== Zope3/src/zope/app/copy.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/copy.py:1.2	Tue Feb  4 04:58:28 2003
+++ Zope3/src/zope/app/copy.py	Tue Feb 11 10:59:28 2003
@@ -1,44 +1,113 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from zope.app.traversing import getParent, objectName
+from zope.component import getAdapter, queryAdapter
 from zope.app.interfaces.copy import IObjectMover
 from zope.app.interfaces.copy import IObjectCopier
+from zope.app.interfaces.container import IAddNotifiable
+from zope.app.interfaces.container import IDeleteNotifiable
+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, 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.'''
 
     __implements__ = IObjectMover
 
-    def __init__(self, container):
-        self.context = container
+    def __init__(self, object):
+        self.context = object
 
-    def moveTo(target, name=None):
+    def moveTo(self, target, name=None):
         '''Move this object to the target given.
         
         Returns the new name within the target
         Typically, the target is adapted to IPasteTarget.'''
 
-        object = self.context
-        if target.acceptsObject(object):
-            return target.pasteObject(object, name)
+        obj = self.context
+        container = getParent(obj)
+        orig_name = objectName(obj)
+        if name is None:
+            name = objectName(obj)
+        
+        movesource = getAdapter(container, IMoveSource)
+        physicaltarget = getAdapter(target, IPhysicallyLocatable)
+        target_path = physicaltarget.getPhysicalPath()
+
+        physicalsource = getAdapter(container, IPhysicallyLocatable)
+        source_path = physicalsource.getPhysicalPath()
+        
+        if queryAdapter(obj, IMoveNotifiable):
+            getAdapter(obj, IMoveNotifiable).manage_beforeDelete(obj, container, \
+                                    movingTo=target_path)
+        elif queryAdapter(obj, IDeleteNotifiable):
+            getAdapter(obj, IDeleteNotifiable).manage_beforeDelete(obj, container)
+
+        new_obj = movesource.removeObject(orig_name, target)
+        pastetarget = getAdapter(target, IPasteTarget)
+        # publish an ObjectCreatedEvent (perhaps...?)
+        new_name = pastetarget.pasteObject(name,new_obj)
+
+        # call manage_afterAdd hook
+        if queryAdapter(new_obj, IMoveNotifiable):
+            getAdapter(new_obj, IMoveNotifiable).manage_afterAdd(new_obj, container, \
+                                movedFrom=source_path)
+        elif queryAdapter(new_obj, IAddNotifiable):
+            getAdapter(new_obj, IAddNotifiable).manage_afterAdd(new_obj, container)
+
+        # publish ObjectMovedEvent
+        publish(container, ObjectMovedEvent(container, source_path, target_path))
+
+        return new_name
         
-    def moveable():
+    def moveable(self):
         '''Returns True if the object is moveable, otherwise False.'''
         return True
 
-    def moveableTo(target, name=None):
+    def moveableTo(self, target, name=None):
         '''Say whether the object can be moved to the given target.
 
         Returns True if it can be moved there. Otherwise, returns
         false.
         '''
-        return True
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        pastetarget = getAdapter(target, IPasteTarget)
+        return pastetarget.acceptsObject(name, obj)
     
 class ObjectCopier:
 
     __implements__ = IObjectCopier
 
-    def __init__(self, container):
-        self.context = container
+    def __init__(self, object):
+        self.context = object
 
-    def copyTo(target, name=None):
+    def copyTo(self, target, name=None):
         """Copy this object to the target given.
 
         Returns the new name within the target, or None
@@ -49,18 +118,76 @@
         If a new object is created as part of the copying process, then
         an IObjectCreated event should be published.
         """
-        object = self.context
-        if target.acceptsObject(object):
-            return target.pasteObject(object, name)
+        obj = self.context
+        container = getParent(obj)
+        if name is None:
+            name = objectName(obj)
+        
+        physicaltarget = getAdapter(target, IPhysicallyLocatable)
+        target_path = physicaltarget.getPhysicalPath()
 
-    def copyable():
+        physicalsource = getAdapter(container, IPhysicallyLocatable)
+        source_path = physicalsource.getPhysicalPath()
+        
+        copysource = getAdapter(container, ICopySource)
+        obj = copysource.copyObject(name, target_path)
+
+        pastetarget = getAdapter(target, IPasteTarget)
+        # publish an ObjectCreatedEvent (perhaps...?)
+        new_name = pastetarget.pasteObject(name, obj)
+
+        # call manage_afterAdd hook
+        if queryAdapter(obj, ICopyNotifiable):
+            getAdapter(obj, ICopyNotifiable).manage_afterAdd(obj, container, \
+                                copiedFrom=source_path)
+        elif queryAdapter(obj, IAddNotifiable):
+            getAdapter(obj, IAddNotifiable).manage_afterAdd(obj, container)
+
+        # publish ObjectCopiedEvent
+        publish(container, ObjectCopiedEvent(container, source_path, target_path))
+
+        return new_name
+
+    def copyable(self):
         '''Returns True if the object is copyable, otherwise False.'''
         return True
 
-    def copyableTo(target, name=None):
+    def copyableTo(self, target, name=None):
         '''Say whether the object can be copied to the given target.
         
         Returns True if it can be copied there. Otherwise, returns
         False.
         '''
-        return True
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        pastetarget = getAdapter(target, IPasteTarget)
+        return pastetarget.acceptsObject(name, obj)
+
+class PrincipalClipboard:
+    '''Clipboard information consists on tuples of {'action':action, 'target':target}.
+    '''
+
+    def __init__(self, annotation):
+        self.context = annotation
+
+    def clearContents(self):
+        '''Clear the contents of the clipboard'''
+        self.context['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.context['clipboard'] = contents + tuple(actions)
+
+    def setContents(self, clipboard):
+        '''Replace the contents of the clipboard by the given value'''
+        self.context['clipboard'] = clipboard
+
+    def getContents(self):
+        '''Return the contents of the clipboard'''
+        return removeAllProxies(self.context.get('clipboard', ()))
+