]>
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>
15 def RegisterUndo(self
, undoObj
):
16 self
.undo
.append(undoObj
)
17 for i
in self
.redo
: i
.destroy()
20 undoObj
= self
.undo
.pop()
22 self
.redo
.append(undoObj
)
23 g
.frame
.modified
= True
24 g
.frame
.SetStatusText('Undone')
26 undoObj
= self
.redo
.pop()
28 self
.undo
.append(undoObj
)
29 g
.frame
.modified
= True
30 g
.frame
.SetStatusText('Redone')
32 for i
in self
.undo
: i
.destroy()
34 for i
in self
.redo
: i
.destroy()
37 return not not self
.undo
39 return not not self
.redo
42 def __init__(self
, itemIndex
, parent
, elem
):
43 self
.itemIndex
= itemIndex
47 if self
.elem
: self
.elem
.unlink()
49 item
= g
.tree
.InsertNode(g
.tree
.ItemAtFullIndex(self
.itemIndex
[:-1]),
50 self
.parent
, self
.elem
,
51 g
.tree
.ItemAtFullIndex(self
.itemIndex
))
52 # Scroll to show new item (!!! redundant?)
53 g
.tree
.EnsureVisible(item
)
54 g
.tree
.SelectItem(item
)
56 # Update testWin if needed
57 if g
.testWin
and g
.tree
.IsHighlatable(item
):
58 if g
.conf
.autoRefresh
:
59 g
.tree
.needUpdate
= True
60 g
.tree
.pendingHighLight
= item
62 g
.tree
.pendingHighLight
= None
64 item
= g
.tree
.ItemAtFullIndex(self
.itemIndex
)
67 # If deleting top-level item, delete testWin
68 if item
== g
.testWin
.item
:
72 # Remove highlight, update testWin
73 if g
.testWin
.highLight
:
74 g
.testWin
.highLight
.Remove()
75 g
.tree
.needUpdate
= True
76 self
.elem
= g
.tree
.RemoveLeaf(item
)
80 class UndoPasteCreate
:
81 def __init__(self
, itemParent
, parent
, item
, selected
):
82 self
.itemParentIndex
= g
.tree
.ItemFullIndex(itemParent
)
84 self
.itemIndex
= g
.tree
.ItemFullIndex(item
) # pasted item
85 self
.selectedIndex
= g
.tree
.ItemFullIndex(selected
) # maybe different from item
88 if self
.elem
: self
.elem
.unlink()
90 self
.elem
= g
.tree
.RemoveLeaf(g
.tree
.ItemAtFullIndex(self
.itemIndex
))
91 # Restore old selection
92 selected
= g
.tree
.ItemAtFullIndex(self
.selectedIndex
)
93 g
.tree
.EnsureVisible(selected
)
94 g
.tree
.SelectItem(selected
)
97 # If deleting top-level item, delete testWin
98 if selected
== g
.testWin
.item
:
102 # Remove highlight, update testWin
103 if g
.testWin
.highLight
:
104 g
.testWin
.highLight
.Remove()
105 g
.tree
.needUpdate
= True
107 item
= g
.tree
.InsertNode(g
.tree
.ItemAtFullIndex(self
.itemParentIndex
),
108 self
.parent
, self
.elem
,
109 g
.tree
.ItemAtFullIndex(self
.itemIndex
))
110 # Scroll to show new item
111 g
.tree
.EnsureVisible(item
)
112 g
.tree
.SelectItem(item
)
114 # Update testWin if needed
115 if g
.testWin
and g
.tree
.IsHighlatable(item
):
116 if g
.conf
.autoRefresh
:
117 g
.tree
.needUpdate
= True
118 g
.tree
.pendingHighLight
= item
120 g
.tree
.pendingHighLight
= None
124 self
.pages
= map(ParamPage
.GetState
, g
.panel
.pages
)
125 self
.selectedIndex
= g
.tree
.ItemFullIndex(g
.tree
.GetSelection())
129 def update(self
, selected
):
130 g
.tree
.Apply(g
.tree
.GetPyData(selected
), selected
)
133 if g
.testWin
.highLight
:
134 g
.testWin
.highLight
.Remove()
135 g
.tree
.pendingHighLight
= selected
137 g
.tree
.needUpdate
= True
140 selected
= g
.tree
.ItemAtFullIndex(self
.selectedIndex
)
141 if selected
!= g
.tree
.GetSelection():
142 g
.tree
.SelectItem(selected
)
143 # Save current state for redo
144 map(ParamPage
.SaveState
, g
.panel
.pages
)
145 pages
= map(ParamPage
.GetState
, g
.panel
.pages
)
146 map(ParamPage
.SetState
, g
.panel
.pages
, self
.pages
)
148 self
.update(selected
)
151 self
.update(g
.tree
.GetSelection())