]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/XRCed/undo.py
2 # Purpose: XRC editor, undo/redo module
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
8 from xxx
import MakeXXXFromDOM
17 def RegisterUndo(self
, undoObj
):
18 self
.undo
.append(undoObj
)
19 for i
in self
.redo
: i
.destroy()
22 undoObj
= self
.undo
.pop()
24 self
.redo
.append(undoObj
)
26 g
.frame
.SetStatusText('Undone')
28 undoObj
= self
.redo
.pop()
30 self
.undo
.append(undoObj
)
32 g
.frame
.SetStatusText('Redone')
34 for i
in self
.undo
: i
.destroy()
36 for i
in self
.redo
: i
.destroy()
39 return not not self
.undo
41 return not not self
.redo
44 def __init__(self
, itemIndex
, parent
, elem
):
45 self
.itemIndex
= itemIndex
49 if self
.elem
: self
.elem
.unlink()
51 item
= g
.tree
.InsertNode(g
.tree
.ItemAtFullIndex(self
.itemIndex
[:-1]),
52 self
.parent
, self
.elem
,
53 g
.tree
.ItemAtFullIndex(self
.itemIndex
))
54 # Scroll to show new item (!!! redundant?)
55 g
.tree
.EnsureVisible(item
)
56 g
.tree
.SelectItem(item
)
58 # Update testWin if needed
59 if g
.testWin
and g
.tree
.IsHighlatable(item
):
60 if g
.conf
.autoRefresh
:
61 g
.tree
.needUpdate
= True
62 g
.tree
.pendingHighLight
= item
64 g
.tree
.pendingHighLight
= None
66 item
= g
.tree
.ItemAtFullIndex(self
.itemIndex
)
69 # If deleting top-level item, delete testWin
70 if item
== g
.testWin
.item
:
74 # Remove highlight, update testWin
75 if g
.testWin
.highLight
:
76 g
.testWin
.highLight
.Remove()
77 g
.tree
.needUpdate
= True
78 self
.elem
= g
.tree
.RemoveLeaf(item
)
82 class UndoPasteCreate
:
83 def __init__(self
, itemParent
, parent
, item
, selected
):
84 self
.itemParentIndex
= g
.tree
.ItemFullIndex(itemParent
)
86 self
.itemIndex
= g
.tree
.ItemFullIndex(item
) # pasted item
87 self
.selectedIndex
= g
.tree
.ItemFullIndex(selected
) # maybe different from item
90 if self
.elem
: self
.elem
.unlink()
92 self
.elem
= g
.tree
.RemoveLeaf(g
.tree
.ItemAtFullIndex(self
.itemIndex
))
93 # Restore old selection
94 selected
= g
.tree
.ItemAtFullIndex(self
.selectedIndex
)
95 g
.tree
.EnsureVisible(selected
)
96 g
.tree
.SelectItem(selected
)
99 # If deleting top-level item, delete testWin
100 if selected
== g
.testWin
.item
:
104 # Remove highlight, update testWin
105 if g
.testWin
.highLight
:
106 g
.testWin
.highLight
.Remove()
107 g
.tree
.needUpdate
= True
109 item
= g
.tree
.InsertNode(g
.tree
.ItemAtFullIndex(self
.itemParentIndex
),
110 self
.parent
, self
.elem
,
111 g
.tree
.ItemAtFullIndex(self
.itemIndex
))
112 # Scroll to show new item
113 g
.tree
.EnsureVisible(item
)
114 g
.tree
.SelectItem(item
)
116 # Update testWin if needed
117 if g
.testWin
and g
.tree
.IsHighlatable(item
):
118 if g
.conf
.autoRefresh
:
119 g
.tree
.needUpdate
= True
120 g
.tree
.pendingHighLight
= item
122 g
.tree
.pendingHighLight
= None
125 def __init__(self
, item
):
126 self
.itemIndex
= g
.tree
.ItemFullIndex(item
)
127 #self.xxx = g.tree.GetPyData(item)
130 if self
.elem
: self
.elem
.unlink()
132 print 'Sorry, UndoReplace is not yet implemented.'
134 item
= g
.tree
.ItemAtFullIndex(self
.itemIndex
)
135 xxx
= g
.tree
.GetPyData(item
)
136 # Replace with old element
137 parent
= xxx
.parent
.node
138 if xxx
is self
.xxx
: # sizeritem or notebookpage - replace child
139 parent
.replaceChild(self
.xxx
.child
.node
, xxx
.child
.node
)
141 parent
.replaceChild(self
.xxx
.node
, xxx
.node
)
142 self
.xxx
.parent
= xxx
.parent
144 g
.tree
.SetPyData(item
, xxx
)
145 g
.tree
.SetItemText(item
, xxx
.treeName())
146 g
.tree
.SetItemImage(item
, xxx
.treeImage())
152 g
.tree
.EnsureVisible(item
)
153 g
.tree
.SelectItem(item
)
156 # If deleting top-level item, delete testWin
157 if selected
== g
.testWin
.item
:
161 # Remove highlight, update testWin
162 if g
.testWin
.highLight
:
163 g
.testWin
.highLight
.Remove()
164 g
.tree
.needUpdate
= True
169 def __init__(self
, oldParent
, oldIndex
, newParent
, newIndex
):
170 self
.oldParent
= oldParent
171 self
.oldIndex
= oldIndex
172 self
.newParent
= newParent
173 self
.newIndex
= newIndex
177 item
= g
.tree
.GetFirstChild(self
.newParent
)[0]
178 for i
in range(self
.newIndex
): item
= g
.tree
.GetNextSibling(item
)
179 elem
= g
.tree
.RemoveLeaf(item
)
180 nextItem
= g
.tree
.GetFirstChild(self
.oldParent
)[0]
181 for i
in range(self
.oldIndex
): nextItem
= g
.tree
.GetNextSibling(nextItem
)
183 parent
= g
.tree
.GetPyData(self
.oldParent
).treeObject()
185 # Check parent and child relationships.
186 # If parent is sizer or notebook, child is of wrong class or
187 # parent is normal window, child is child container then detach child.
188 xxx
= MakeXXXFromDOM(parent
, elem
)
189 isChildContainer
= isinstance(xxx
, xxxChildContainer
)
190 if isChildContainer
and \
191 ((parent
.isSizer
and not isinstance(xxx
, xxxSizerItem
)) or \
192 (isinstance(parent
, xxxNotebook
) and not isinstance(xxx
, xxxNotebookPage
)) or \
193 not (parent
.isSizer
or isinstance(parent
, xxxNotebook
))):
194 elem
.removeChild(xxx
.child
.node
) # detach child
195 elem
.unlink() # delete child container
196 elem
= xxx
.child
.node
# replace
197 # This may help garbage collection
198 xxx
.child
.parent
= None
199 isChildContainer
= False
200 # Parent is sizer or notebook, child is not child container
201 if parent
.isSizer
and not isChildContainer
and not isinstance(xxx
, xxxSpacer
):
202 # Create sizer item element
203 sizerItemElem
= MakeEmptyDOM('sizeritem')
204 sizerItemElem
.appendChild(elem
)
206 elif isinstance(parent
, xxxNotebook
) and not isChildContainer
:
207 pageElem
= MakeEmptyDOM('notebookpage')
208 pageElem
.appendChild(elem
)
211 selected
= g
.tree
.InsertNode(self
.oldParent
, parent
, elem
, nextItem
)
212 g
.tree
.EnsureVisible(selected
)
213 g
.tree
.SelectItem(selected
)
215 item
= g
.tree
.GetFirstChild(self
.oldParent
)[0]
216 for i
in range(self
.oldIndex
): item
= g
.tree
.GetNextSibling(item
)
217 elem
= g
.tree
.RemoveLeaf(item
)
219 parent
= g
.tree
.GetPyData(self
.newParent
).treeObject()
221 # Check parent and child relationships.
222 # If parent is sizer or notebook, child is of wrong class or
223 # parent is normal window, child is child container then detach child.
224 xxx
= MakeXXXFromDOM(parent
, elem
)
225 isChildContainer
= isinstance(xxx
, xxxChildContainer
)
226 if isChildContainer
and \
227 ((parent
.isSizer
and not isinstance(xxx
, xxxSizerItem
)) or \
228 (isinstance(parent
, xxxNotebook
) and not isinstance(xxx
, xxxNotebookPage
)) or \
229 not (parent
.isSizer
or isinstance(parent
, xxxNotebook
))):
230 elem
.removeChild(xxx
.child
.node
) # detach child
231 elem
.unlink() # delete child container
232 elem
= xxx
.child
.node
# replace
233 # This may help garbage collection
234 xxx
.child
.parent
= None
235 isChildContainer
= False
236 # Parent is sizer or notebook, child is not child container
237 if parent
.isSizer
and not isChildContainer
and not isinstance(xxx
, xxxSpacer
):
238 # Create sizer item element
239 sizerItemElem
= MakeEmptyDOM('sizeritem')
240 sizerItemElem
.appendChild(elem
)
242 elif isinstance(parent
, xxxNotebook
) and not isChildContainer
:
243 pageElem
= MakeEmptyDOM('notebookpage')
244 pageElem
.appendChild(elem
)
247 nextItem
= g
.tree
.GetFirstChild(self
.newParent
)[0]
248 for i
in range(self
.newIndex
): nextItem
= g
.tree
.GetNextSibling(nextItem
)
249 selected
= g
.tree
.InsertNode(self
.newParent
, parent
, elem
, nextItem
)
250 g
.tree
.EnsureVisible(selected
)
251 g
.tree
.SelectItem(selected
)
255 self
.pages
= map(ParamPage
.GetState
, g
.panel
.pages
)
256 self
.selectedIndex
= g
.tree
.ItemFullIndex(g
.tree
.GetSelection())
260 def update(self
, selected
):
261 g
.tree
.Apply(g
.tree
.GetPyData(selected
), selected
)
264 if g
.testWin
.highLight
:
265 g
.testWin
.highLight
.Remove()
266 g
.tree
.pendingHighLight
= selected
268 g
.tree
.needUpdate
= True
271 selected
= g
.tree
.ItemAtFullIndex(self
.selectedIndex
)
272 if selected
!= g
.tree
.GetSelection():
273 g
.tree
.SelectItem(selected
)
274 # Save current state for redo
275 map(ParamPage
.SaveState
, g
.panel
.pages
)
276 pages
= map(ParamPage
.GetState
, g
.panel
.pages
)
277 map(ParamPage
.SetState
, g
.panel
.pages
, self
.pages
)
279 self
.update(selected
)
282 self
.update(g
.tree
.GetSelection())