[Zope3-checkins] CVS: Zope3/src/zope/app - copypastemove.py:1.1 configure.zcml:1.12 copy.py:NONE

Sidnei da Silva sidnei@x3ng.com.br
Mon, 17 Feb 2003 10:11:09 -0500


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

Modified Files:
	configure.zcml 
Added Files:
	copypastemove.py 
Removed Files:
	copy.py 
Log Message:
renamed copy.py to copypastemove.py. fixed rename via zope3 ui. fixed copy.

=== Added File Zope3/src/zope/app/copypastemove.py ===
##############################################################################
#
# 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: copypastemove.py,v 1.1 2003/02/17 15:10:38 sidnei Exp $
"""

from zope.app.traversing import getParent, objectName
from zope.component import getAdapter, queryAdapter
from zope.app.interfaces.copypastemove import IObjectMover
from zope.app.interfaces.copypastemove 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, object):
        self.context = object

    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.'''

        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(self):
        '''Returns True if the object is moveable, otherwise False.'''
        return True

    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.
        '''
        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, object):
        self.context = object

    def copyTo(self, target, name=None):
        """Copy this object to the target given.

        Returns the new name within the target, or None
        if the target doesn't do names.
        Typically, the target is adapted to IPasteTarget.
        After the copy is added to the target container, publish
        an IObjectCopied event in the context of the target container.
        If a new object is created as part of the copying process, then
        an IObjectCreated event should be published.
        """
        obj = self.context
        container = getParent(obj)
        if name is None:
            name = objectName(obj)
        
        physicaltarget = getAdapter(target, IPhysicallyLocatable)
        target_path = physicaltarget.getPhysicalPath()

        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(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.
        '''
        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', ()))
    


=== Zope3/src/zope/app/configure.zcml 1.11 => 1.12 ===
--- Zope3/src/zope/app/configure.zcml:1.11	Tue Feb 11 10:59:28 2003
+++ Zope3/src/zope/app/configure.zcml	Mon Feb 17 10:10:38 2003
@@ -62,20 +62,20 @@
       permission="zope.View" />
 
   <adapter
-      factory="zope.app.copy.ObjectMover"
-      provides="zope.app.interfaces.copy.IObjectMover"
+      factory="zope.app.copypastemove.ObjectMover"
+      provides="zope.app.interfaces.copypastemove.IObjectMover"
       permission="zope.ManageContent" 
       for="*" />
 
   <adapter
-      factory="zope.app.copy.ObjectCopier"
-      provides="zope.app.interfaces.copy.IObjectCopier"
+      factory="zope.app.copypastemove.ObjectCopier"
+      provides="zope.app.interfaces.copypastemove.IObjectCopier"
       permission="zope.ManageContent" 
       for="*" />
 
   <adapter
-      factory="zope.app.copy.PrincipalClipboard"
-      provides="zope.app.interfaces.copy.IPrincipalClipboard"
+      factory="zope.app.copypastemove.PrincipalClipboard"
+      provides="zope.app.interfaces.copypastemove.IPrincipalClipboard"
       permission="zope.ManageContent" 
       for="zope.app.interfaces.annotation.IAnnotations" />
 

=== Removed File Zope3/src/zope/app/copy.py ===