- undo/redo fixes for moving and cut/paste;

- compatibility check for non-container controls


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46018 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Roman Rolinsky 2007-05-14 12:24:44 +00:00
parent a297dec681
commit 4427147544
3 changed files with 28 additions and 18 deletions

View File

@ -1265,12 +1265,6 @@ class XML_Tree(wx.TreeCtrl):
self.PopupMenu(menu, evt.GetPosition()) self.PopupMenu(menu, evt.GetPosition())
menu.Destroy() menu.Destroy()
# Redefine to force the update of font dimentions on wxGTK
if wx.Platform == '__WXGTK__':
def SetItemBold(self, item, state=True):
wx.TreeCtrl.SetItemBold(self, item, state)
self.SetIndent(self.GetIndent())
# Apply changes # Apply changes
def Apply(self, xxx, item): def Apply(self, xxx, item):
g.panel.Apply() g.panel.Apply()

View File

@ -167,20 +167,23 @@ class UndoReplace:
class UndoMove: class UndoMove:
def __init__(self, oldParent, oldIndex, newParent, newIndex): def __init__(self, oldParent, oldIndex, newParent, newIndex):
self.oldParent = oldParent # Store indexes because items can be invalid already
self.oldParentIndex = g.tree.ItemFullIndex(oldParent)
self.oldIndex = oldIndex self.oldIndex = oldIndex
self.newParent = newParent self.newParentIndex = g.tree.ItemFullIndex(newParent)
self.newIndex = newIndex self.newIndex = newIndex
def destroy(self): def destroy(self):
pass pass
def undo(self): def undo(self):
item = g.tree.GetFirstChild(self.newParent)[0] oldParent = g.tree.ItemAtFullIndex(self.oldParentIndex)
newParent = g.tree.ItemAtFullIndex(self.newParentIndex)
item = g.tree.GetFirstChild(newParent)[0]
for i in range(self.newIndex): item = g.tree.GetNextSibling(item) for i in range(self.newIndex): item = g.tree.GetNextSibling(item)
elem = g.tree.RemoveLeaf(item) elem = g.tree.RemoveLeaf(item)
nextItem = g.tree.GetFirstChild(self.oldParent)[0] nextItem = g.tree.GetFirstChild(oldParent)[0]
for i in range(self.oldIndex): nextItem = g.tree.GetNextSibling(nextItem) for i in range(self.oldIndex): nextItem = g.tree.GetNextSibling(nextItem)
parent = g.tree.GetPyData(self.oldParent).treeObject() parent = g.tree.GetPyData(oldParent).treeObject()
# Check parent and child relationships. # Check parent and child relationships.
# If parent is sizer or notebook, child is of wrong class or # If parent is sizer or notebook, child is of wrong class or
@ -208,7 +211,7 @@ class UndoMove:
pageElem.appendChild(elem) pageElem.appendChild(elem)
elem = pageElem elem = pageElem
selected = g.tree.InsertNode(self.oldParent, parent, elem, nextItem) selected = g.tree.InsertNode(oldParent, parent, elem, nextItem)
g.tree.EnsureVisible(selected) g.tree.EnsureVisible(selected)
# Highlight is outdated # Highlight is outdated
if g.testWin and g.testWin.highLight: if g.testWin and g.testWin.highLight:
@ -216,11 +219,13 @@ class UndoMove:
g.tree.needUpdate = True g.tree.needUpdate = True
g.tree.SelectItem(selected) g.tree.SelectItem(selected)
def redo(self): def redo(self):
item = g.tree.GetFirstChild(self.oldParent)[0] oldParent = g.tree.ItemAtFullIndex(self.oldParentIndex)
newParent = g.tree.ItemAtFullIndex(self.newParentIndex)
item = g.tree.GetFirstChild(oldParent)[0]
for i in range(self.oldIndex): item = g.tree.GetNextSibling(item) for i in range(self.oldIndex): item = g.tree.GetNextSibling(item)
elem = g.tree.RemoveLeaf(item) elem = g.tree.RemoveLeaf(item)
parent = g.tree.GetPyData(self.newParent).treeObject() parent = g.tree.GetPyData(newParent).treeObject()
# Check parent and child relationships. # Check parent and child relationships.
# If parent is sizer or notebook, child is of wrong class or # If parent is sizer or notebook, child is of wrong class or
@ -248,9 +253,9 @@ class UndoMove:
pageElem.appendChild(elem) pageElem.appendChild(elem)
elem = pageElem elem = pageElem
nextItem = g.tree.GetFirstChild(self.newParent)[0] nextItem = g.tree.GetFirstChild(newParent)[0]
for i in range(self.newIndex): nextItem = g.tree.GetNextSibling(nextItem) for i in range(self.newIndex): nextItem = g.tree.GetNextSibling(nextItem)
selected = g.tree.InsertNode(self.newParent, parent, elem, nextItem) selected = g.tree.InsertNode(newParent, parent, elem, nextItem)
g.tree.EnsureVisible(selected) g.tree.EnsureVisible(selected)
# Highlight is outdated # Highlight is outdated
if g.testWin and g.testWin.highLight: if g.testWin and g.testWin.highLight:

View File

@ -725,6 +725,8 @@ class Frame(wx.Frame):
# Toolbar can be top-level of child of panel or frame # Toolbar can be top-level of child of panel or frame
if parent.__class__ not in [xxxMainNode, xxxPanel, xxxFrame] and \ if parent.__class__ not in [xxxMainNode, xxxPanel, xxxFrame] and \
not parent.isSizer: error = True not parent.isSizer: error = True
elif not parent.hasChildren:
error = True
elif child.__class__ == xxxPanel and parent.__class__ == xxxMainNode: elif child.__class__ == xxxPanel and parent.__class__ == xxxMainNode:
pass pass
elif child.__class__ == xxxSpacer: elif child.__class__ == xxxSpacer:
@ -835,12 +837,16 @@ class Frame(wx.Frame):
if g.testWin and g.testWin.highLight: if g.testWin and g.testWin.highLight:
g.testWin.highLight.Remove() g.testWin.highLight.Remove()
tree.needUpdate = True tree.needUpdate = True
# Undo info # Undo info
self.lastOp = 'MOVELEFT' self.lastOp = 'MOVELEFT'
status = 'Made next sibling of parent' status = 'Made next sibling of parent'
# Prepare undo data
panel.Apply()
tree.UnselectAll()
oldIndex = tree.ItemIndex(selected) oldIndex = tree.ItemIndex(selected)
elem = tree.RemoveLeaf(selected) elem = tree.RemoveLeaf(selected)
nextItem = tree.GetFirstChild(pparent)[0] nextItem = tree.GetFirstChild(pparent)[0]
@ -901,7 +907,11 @@ class Frame(wx.Frame):
# Remove highlight, update testWin # Remove highlight, update testWin
if g.testWin and g.testWin.highLight: if g.testWin and g.testWin.highLight:
g.testWin.highLight.Remove() g.testWin.highLight.Remove()
tree.needUpdate = True tree.needUpdate = True
# Prepare undo data
panel.Apply()
tree.UnselectAll()
# Undo info # Undo info
self.lastOp = 'MOVERIGHT' self.lastOp = 'MOVERIGHT'
@ -939,6 +949,7 @@ class Frame(wx.Frame):
selected = tree.InsertNode(newParent, tree.GetPyData(newParent).treeObject(), elem, wx.TreeItemId()) selected = tree.InsertNode(newParent, tree.GetPyData(newParent).treeObject(), elem, wx.TreeItemId())
newIndex = tree.ItemIndex(selected) newIndex = tree.ItemIndex(selected)
tree.Expand(selected)
tree.SelectItem(selected) tree.SelectItem(selected)
undoMan.RegisterUndo(UndoMove(oldParent, oldIndex, newParent, newIndex)) undoMan.RegisterUndo(UndoMove(oldParent, oldIndex, newParent, newIndex))