]>
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
16 def RegisterUndo(self
, undoObj
):
17 self
.undo
.append(undoObj
)
18 for i
in self
.redo
: i
.destroy()
21 undoObj
= self
.undo
.pop()
23 self
.redo
.append(undoObj
)
25 g
.frame
.SetStatusText('Undone')
27 undoObj
= self
.redo
.pop()
29 self
.undo
.append(undoObj
)
31 g
.frame
.SetStatusText('Redone')
33 for i
in self
.undo
: i
.destroy()
35 for i
in self
.redo
: i
.destroy()
38 return not not self
.undo
40 return not not self
.redo
43 def __init__(self
, itemIndex
, parent
, elem
):
44 self
.itemIndex
= itemIndex
48 if self
.elem
: self
.elem
.unlink()
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
)
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
63 g
.tree
.pendingHighLight
= None
65 item
= g
.tree
.ItemAtFullIndex(self
.itemIndex
)
68 # If deleting top-level item, delete testWin
69 if item
== g
.testWin
.item
:
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
)
81 class UndoPasteCreate
:
82 def __init__(self
, itemParent
, parent
, item
, selected
):
83 self
.itemParentIndex
= g
.tree
.ItemFullIndex(itemParent
)
85 self
.itemIndex
= g
.tree
.ItemFullIndex(item
) # pasted item
86 self
.selectedIndex
= g
.tree
.ItemFullIndex(selected
) # maybe different from item
89 if self
.elem
: self
.elem
.unlink()
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
)
98 # If deleting top-level item, delete testWin
99 if selected
== g
.testWin
.item
:
103 # Remove highlight, update testWin
104 if g
.testWin
.highLight
:
105 g
.testWin
.highLight
.Remove()
106 g
.tree
.needUpdate
= True
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
)
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
121 g
.tree
.pendingHighLight
= None
124 def __init__(self
, item
):
125 self
.itemIndex
= g
.tree
.ItemFullIndex(item
)
126 self
.xxx
= g
.tree
.GetPyData(item
)
128 if self
.xxx
: self
.xxx
.element
.unlink()
130 print 'Sorry, UndoReplace is not yet implemented.'
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
)
139 parent
.replaceChild(self
.xxx
.element
, xxx
.element
)
140 self
.xxx
.parent
= xxx
.parent
142 g
.tree
.SetPyData(item
, xxx
)
143 g
.tree
.SetItemText(item
, xxx
.treeName())
144 g
.tree
.SetItemImage(item
, xxx
.treeImage())
150 g
.tree
.EnsureVisible(item
)
151 g
.tree
.SelectItem(item
)
154 # If deleting top-level item, delete testWin
155 if selected
== g
.testWin
.item
:
159 # Remove highlight, update testWin
160 if g
.testWin
.highLight
:
161 g
.testWin
.highLight
.Remove()
162 g
.tree
.needUpdate
= True
168 self
.pages
= map(ParamPage
.GetState
, g
.panel
.pages
)
169 self
.selectedIndex
= g
.tree
.ItemFullIndex(g
.tree
.GetSelection())
173 def update(self
, selected
):
174 g
.tree
.Apply(g
.tree
.GetPyData(selected
), selected
)
177 if g
.testWin
.highLight
:
178 g
.testWin
.highLight
.Remove()
179 g
.tree
.pendingHighLight
= selected
181 g
.tree
.needUpdate
= True
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
)
192 self
.update(selected
)
195 self
.update(g
.tree
.GetSelection())