]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/XRCed/undo.py
made XPM data const
[wxWidgets.git] / wxPython / wx / tools / XRCed / undo.py
1 # Name: undo.py
2 # Purpose: XRC editor, undo/redo module
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
4 # Created: 01.12.2002
5 # RCS-ID: $Id$
6
7 from globals import *
8 from xxx import MakeXXXFromDOM
9 #from panel import *
10
11 # Undo/redo classes
12 class UndoManager:
13 # Undo/redo stacks
14 undo = []
15 redo = []
16 def RegisterUndo(self, undoObj):
17 self.undo.append(undoObj)
18 for i in self.redo: i.destroy()
19 self.redo = []
20 def Undo(self):
21 undoObj = self.undo.pop()
22 undoObj.undo()
23 self.redo.append(undoObj)
24 g.frame.SetModified()
25 g.frame.SetStatusText('Undone')
26 def Redo(self):
27 undoObj = self.redo.pop()
28 undoObj.redo()
29 self.undo.append(undoObj)
30 g.frame.SetModified()
31 g.frame.SetStatusText('Redone')
32 def Clear(self):
33 for i in self.undo: i.destroy()
34 self.undo = []
35 for i in self.redo: i.destroy()
36 self.redo = []
37 def CanUndo(self):
38 return not not self.undo
39 def CanRedo(self):
40 return not not self.redo
41
42 class UndoCutDelete:
43 def __init__(self, itemIndex, parent, elem):
44 self.itemIndex = itemIndex
45 self.parent = parent
46 self.elem = elem
47 def destroy(self):
48 if self.elem: self.elem.unlink()
49 def undo(self):
50 item = g.tree.InsertNode(g.tree.ItemAtFullIndex(self.itemIndex[:-1]),
51 self.parent, self.elem,
52 g.tree.ItemAtFullIndex(self.itemIndex))
53 # Scroll to show new item (!!! redundant?)
54 g.tree.EnsureVisible(item)
55 g.tree.SelectItem(item)
56 self.elem = None
57 # Update testWin if needed
58 if g.testWin and g.tree.IsHighlatable(item):
59 if g.conf.autoRefresh:
60 g.tree.needUpdate = True
61 g.tree.pendingHighLight = item
62 else:
63 g.tree.pendingHighLight = None
64 def redo(self):
65 item = g.tree.ItemAtFullIndex(self.itemIndex)
66 # Delete testWin?
67 if g.testWin:
68 # If deleting top-level item, delete testWin
69 if item == g.testWin.item:
70 g.testWin.Destroy()
71 g.testWin = None
72 else:
73 # Remove highlight, update testWin
74 if g.testWin.highLight:
75 g.testWin.highLight.Remove()
76 g.tree.needUpdate = True
77 self.elem = g.tree.RemoveLeaf(item)
78 g.tree.UnselectAll()
79 g.panel.Clear()
80
81 class UndoPasteCreate:
82 def __init__(self, itemParent, parent, item, selected):
83 self.itemParentIndex = g.tree.ItemFullIndex(itemParent)
84 self.parent = parent
85 self.itemIndex = g.tree.ItemFullIndex(item) # pasted item
86 self.selectedIndex = g.tree.ItemFullIndex(selected) # maybe different from item
87 self.elem = None
88 def destroy(self):
89 if self.elem: self.elem.unlink()
90 def undo(self):
91 self.elem = g.tree.RemoveLeaf(g.tree.ItemAtFullIndex(self.itemIndex))
92 # Restore old selection
93 selected = g.tree.ItemAtFullIndex(self.selectedIndex)
94 g.tree.EnsureVisible(selected)
95 g.tree.SelectItem(selected)
96 # Delete testWin?
97 if g.testWin:
98 # If deleting top-level item, delete testWin
99 if selected == g.testWin.item:
100 g.testWin.Destroy()
101 g.testWin = None
102 else:
103 # Remove highlight, update testWin
104 if g.testWin.highLight:
105 g.testWin.highLight.Remove()
106 g.tree.needUpdate = True
107 def redo(self):
108 item = g.tree.InsertNode(g.tree.ItemAtFullIndex(self.itemParentIndex),
109 self.parent, self.elem,
110 g.tree.ItemAtFullIndex(self.itemIndex))
111 # Scroll to show new item
112 g.tree.EnsureVisible(item)
113 g.tree.SelectItem(item)
114 self.elem = None
115 # Update testWin if needed
116 if g.testWin and g.tree.IsHighlatable(item):
117 if g.conf.autoRefresh:
118 g.tree.needUpdate = True
119 g.tree.pendingHighLight = item
120 else:
121 g.tree.pendingHighLight = None
122
123 class UndoReplace:
124 def __init__(self, item):
125 self.itemIndex = g.tree.ItemFullIndex(item)
126 self.xxx = g.tree.GetPyData(item)
127 def destroy(self):
128 if self.xxx: self.xxx.element.unlink()
129 def undo(self):
130 print 'Sorry, UndoReplace is not yet implemented.'
131 return
132 item = g.tree.ItemAtFullIndex(self.itemIndex)
133 xxx = g.tree.GetPyData(item)
134 # Replace with old element
135 parent = xxx.parent.element
136 if xxx is self.xxx: # sizeritem or notebookpage - replace child
137 parent.replaceChild(self.xxx.child.element, xxx.child.element)
138 else:
139 parent.replaceChild(self.xxx.element, xxx.element)
140 self.xxx.parent = xxx.parent
141 xxx = self.xxx
142 g.tree.SetPyData(item, xxx)
143 g.tree.SetItemText(item, xxx.treeName())
144 g.tree.SetItemImage(item, xxx.treeImage())
145
146 # Update panel
147 g.panel.SetData(xxx)
148 # Update tools
149 g.tools.UpdateUI()
150 g.tree.EnsureVisible(item)
151 g.tree.SelectItem(item)
152 # Delete testWin?
153 if g.testWin:
154 # If deleting top-level item, delete testWin
155 if selected == g.testWin.item:
156 g.testWin.Destroy()
157 g.testWin = None
158 else:
159 # Remove highlight, update testWin
160 if g.testWin.highLight:
161 g.testWin.highLight.Remove()
162 g.tree.needUpdate = True
163 def redo(self):
164 return
165
166 class UndoEdit:
167 def __init__(self):
168 self.pages = map(ParamPage.GetState, g.panel.pages)
169 self.selectedIndex = g.tree.ItemFullIndex(g.tree.GetSelection())
170 def destroy(self):
171 pass
172 # Update test view
173 def update(self, selected):
174 g.tree.Apply(g.tree.GetPyData(selected), selected)
175 # Update view
176 if g.testWin:
177 if g.testWin.highLight:
178 g.testWin.highLight.Remove()
179 g.tree.pendingHighLight = selected
180 if g.testWin:
181 g.tree.needUpdate = True
182 def undo(self):
183 # Restore selection
184 selected = g.tree.ItemAtFullIndex(self.selectedIndex)
185 if selected != g.tree.GetSelection():
186 g.tree.SelectItem(selected)
187 # Save current state for redo
188 map(ParamPage.SaveState, g.panel.pages)
189 pages = map(ParamPage.GetState, g.panel.pages)
190 map(ParamPage.SetState, g.panel.pages, self.pages)
191 self.pages = pages
192 self.update(selected)
193 def redo(self):
194 self.undo()
195 self.update(g.tree.GetSelection())