1
########################################################################
4
# Created: February 15, 2005
5
# Author: Ivan Vilata - reverse:com.carabos@ivilata
8
# $Id: undoredo.py 1009 2005-06-15 13:39:15Z faltet $
10
########################################################################
13
Support for undoing and redoing actions.
17
* undo(file, operation, *args)
18
* redo(file, operation, *args)
19
* moveToShadow(file, path)
20
* moveFromShadow(file, path)
21
* attrToShadow(file, path, name)
22
* attrFromShadow(file, path, name)
27
The format of documentation strings in this module.
29
Repository version of this file.
32
from tables.utils import splitPath
36
__docformat__ = 'reStructuredText'
37
"""The format of documentation strings in this module."""
39
__version__ = '$Revision: 1009 $'
40
"""Repository version of this file."""
44
def undo(file_, operation, *args):
45
if operation == 'CREATE':
46
undoCreate(file_, args[0])
47
elif operation == 'REMOVE':
48
undoRemove(file_, args[0])
49
elif operation == 'MOVE':
50
undoMove(file_, args[0], args[1])
51
elif operation == 'ADDATTR':
52
undoAddAttr(file_, args[0], args[1])
53
elif operation == 'DELATTR':
54
undoDelAttr(file_, args[0], args[1])
56
raise NotImplementedError("""\
57
the requested unknown operation %r can not be undone; \
58
please report this to the authors""" % operation)
61
def redo(file_, operation, *args):
62
if operation == 'CREATE':
63
redoCreate(file_, args[0])
64
elif operation == 'REMOVE':
65
redoRemove(file_, args[0])
66
elif operation == 'MOVE':
67
redoMove(file_, args[0], args[1])
68
elif operation == 'ADDATTR':
69
redoAddAttr(file_, args[0], args[1])
70
elif operation == 'DELATTR':
71
redoDelAttr(file_, args[0], args[1])
73
raise NotImplementedError("""\
74
the requested unknown operation %r can not be redone; \
75
please report this to the authors""" % operation)
78
def moveToShadow(file_, path):
79
node = file_.getNode(path)
81
(shparent, shname) = file_._shadowName()
82
node._g_move(shparent, shname)
85
def moveFromShadow(file_, path):
86
(shparent, shname) = file_._shadowName()
87
node = getattr(shparent, shname)
89
(pname, name) = splitPath(path)
90
parent = file_.getNode(pname)
91
node._g_move(parent, name)
94
def undoCreate(file_, path):
95
moveToShadow(file_, path)
97
def redoCreate(file_, path):
98
moveFromShadow(file_, path)
100
def undoRemove(file_, path):
101
moveFromShadow(file_, path)
103
def redoRemove(file_, path):
104
moveToShadow(file_, path)
106
def undoMove(file_, origpath, destpath):
107
(origpname, origname) = splitPath(origpath)
109
node = file_.getNode(destpath)
110
origparent = file_.getNode(origpname)
111
node._g_move(origparent, origname)
113
def redoMove(file_, origpath, destpath):
114
(destpname, destname) = splitPath(destpath)
116
node = file_.getNode(origpath)
117
destparent = file_.getNode(destpname)
118
node._g_move(destparent, destname)
121
def attrToShadow(file_, path, name):
122
attrs = file_.getNode(path)._v_attrs
123
value = getattr(attrs, name)
125
(shparent, shname) = file_._shadowName()
126
shattrs = shparent._v_attrs
128
# Set the attribute only if it has not been kept in the shadow.
129
# This avoids re-pickling complex attributes on REDO.
130
if not shname in shattrs:
131
shattrs._g__setattr(shname, value)
133
attrs._g__delattr(name)
136
def attrFromShadow(file_, path, name):
137
(shparent, shname) = file_._shadowName()
138
shattrs = shparent._v_attrs
139
value = getattr(shattrs, shname)
141
attrs = file_.getNode(path)._v_attrs
142
attrs._g__setattr(name, value)
144
# Keeping the attribute in the shadow allows reusing it on Undo/Redo.
145
##shattrs._g__delattr(shname)
148
def undoAddAttr(file_, path, name):
149
attrToShadow(file_, path, name)
151
def redoAddAttr(file_, path, name):
152
attrFromShadow(file_, path, name)
154
def undoDelAttr(file_, path, name):
155
attrFromShadow(file_, path, name)
157
def redoDelAttr(file_, path, name):
158
attrToShadow(file_, path, name)
164
## py-indent-offset: 4