[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container -
contents.py:1.28
Garrett Smith
garrett at mojave-corp.com
Thu Oct 2 12:23:50 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/browser/container
In directory cvs.zope.org:/tmp/cvs-serv1046/src/zope/app/browser/container
Modified Files:
contents.py
Log Message:
Added defensive code to contents UI that handes missing clipboard items.
This fixes a series of problems that arise when a copied item is deleted.
There are still some minor issues remaining:
- It's possible that the clipboard contain items that are deleted. It seems to
me that clipboard items should be removed when their source items are
removed.
- One cannot paste multiple times from a cut object since the clipboard
contains only a reference to the source item, which is made invalid by
the first paste/move operation.
=== Zope3/src/zope/app/browser/container/contents.py 1.27 => 1.28 ===
--- Zope3/src/zope/app/browser/container/contents.py:1.27 Sun Sep 21 13:30:26 2003
+++ Zope3/src/zope/app/browser/container/contents.py Thu Oct 2 12:23:19 2003
@@ -29,6 +29,7 @@
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.browser.container.adding import BasicAdding
from zope.app.copypastemove import rename
+from zope.exceptions import NotFoundError
class Contents(BrowserView):
@@ -265,20 +266,25 @@
clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
items = clipboard.getContents()
for item in items:
- obj = zapi.traverse(target, item['target'])
- if item['action'] == 'cut':
- mover = zapi.getAdapter(obj, IObjectMover)
- if not mover.moveableTo(target):
- return False
- elif item['action'] == 'copy':
- copier = zapi.getAdapter(obj, IObjectCopier)
- if not copier.copyableTo(target):
- return False
+ try:
+ obj = zapi.traverse(target, item['target'])
+ except NotFoundError:
+ pass
else:
- raise
+ if item['action'] == 'cut':
+ mover = zapi.getAdapter(obj, IObjectMover)
+ if not mover.moveableTo(target):
+ return False
+ elif item['action'] == 'copy':
+ copier = zapi.getAdapter(obj, IObjectCopier)
+ if not copier.copyableTo(target):
+ return False
+ else:
+ raise
return True
+
def pasteObjects(self):
"""Paste ojects in the user clipboard to the container
"""
@@ -290,23 +296,26 @@
items = clipboard.getContents()
moved = False
for item in items:
- obj = zapi.traverse(target, item['target'])
- if item['action'] == 'cut':
- mover = zapi.getAdapter(obj, IObjectMover)
- mover.moveTo(target)
- moved = True
- elif item['action'] == 'copy':
- copier = zapi.getAdapter(obj, IObjectCopier)
- copier.copyTo(target)
+ try:
+ obj = zapi.traverse(target, item['target'])
+ except NotFoundError:
+ pass
else:
- raise
+ if item['action'] == 'cut':
+ mover = zapi.getAdapter(obj, IObjectMover)
+ mover.moveTo(target)
+ moved = True
+ elif item['action'] == 'copy':
+ copier = zapi.getAdapter(obj, IObjectCopier)
+ copier.copyTo(target)
+ else:
+ raise
if moved:
# Clear the clipboard if we do a move, but not if we only do a copy
clipboard.clearContents()
-
def hasClipboardContents(self):
""" interogates the PrinicipalAnnotation to see if
clipboard contents exist """
@@ -319,10 +328,16 @@
annotationsvc = zapi.getService(self.context, 'PrincipalAnnotation')
annotations = annotationsvc.getAnnotations(user)
+ # touch at least one item to in clipboard confirm contents
clipboard = zapi.getAdapter(annotations, IPrincipalClipboard)
-
- if clipboard.getContents():
- return True
+ items = clipboard.getContents()
+ for item in items:
+ try:
+ zapi.traverse(self.context, item['target'])
+ except NotFoundError:
+ pass
+ else:
+ return True
return False
More information about the Zope3-Checkins
mailing list