From 4427147544244e74404b298c88b79292a50453b1 Mon Sep 17 00:00:00 2001 From: Roman Rolinsky Date: Mon, 14 May 2007 12:24:44 +0000 Subject: [PATCH] - 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 --- wxPython/wx/tools/XRCed/tree.py | 6 ------ wxPython/wx/tools/XRCed/undo.py | 25 +++++++++++++++---------- wxPython/wx/tools/XRCed/xrced.py | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/wxPython/wx/tools/XRCed/tree.py b/wxPython/wx/tools/XRCed/tree.py index 5357edb907..363093ef49 100644 --- a/wxPython/wx/tools/XRCed/tree.py +++ b/wxPython/wx/tools/XRCed/tree.py @@ -1265,12 +1265,6 @@ class XML_Tree(wx.TreeCtrl): self.PopupMenu(menu, evt.GetPosition()) 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 def Apply(self, xxx, item): g.panel.Apply() diff --git a/wxPython/wx/tools/XRCed/undo.py b/wxPython/wx/tools/XRCed/undo.py index 4ad8909b2b..52b20ecf96 100644 --- a/wxPython/wx/tools/XRCed/undo.py +++ b/wxPython/wx/tools/XRCed/undo.py @@ -167,20 +167,23 @@ class UndoReplace: class UndoMove: 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.newParent = newParent + self.newParentIndex = g.tree.ItemFullIndex(newParent) self.newIndex = newIndex def destroy(self): pass 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) 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) - parent = g.tree.GetPyData(self.oldParent).treeObject() + parent = g.tree.GetPyData(oldParent).treeObject() # Check parent and child relationships. # If parent is sizer or notebook, child is of wrong class or @@ -208,7 +211,7 @@ class UndoMove: pageElem.appendChild(elem) elem = pageElem - selected = g.tree.InsertNode(self.oldParent, parent, elem, nextItem) + selected = g.tree.InsertNode(oldParent, parent, elem, nextItem) g.tree.EnsureVisible(selected) # Highlight is outdated if g.testWin and g.testWin.highLight: @@ -216,11 +219,13 @@ class UndoMove: g.tree.needUpdate = True g.tree.SelectItem(selected) 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) elem = g.tree.RemoveLeaf(item) - parent = g.tree.GetPyData(self.newParent).treeObject() + parent = g.tree.GetPyData(newParent).treeObject() # Check parent and child relationships. # If parent is sizer or notebook, child is of wrong class or @@ -248,9 +253,9 @@ class UndoMove: pageElem.appendChild(elem) 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) - selected = g.tree.InsertNode(self.newParent, parent, elem, nextItem) + selected = g.tree.InsertNode(newParent, parent, elem, nextItem) g.tree.EnsureVisible(selected) # Highlight is outdated if g.testWin and g.testWin.highLight: diff --git a/wxPython/wx/tools/XRCed/xrced.py b/wxPython/wx/tools/XRCed/xrced.py index 9a062af183..0cd38bc172 100644 --- a/wxPython/wx/tools/XRCed/xrced.py +++ b/wxPython/wx/tools/XRCed/xrced.py @@ -725,6 +725,8 @@ class Frame(wx.Frame): # Toolbar can be top-level of child of panel or frame if parent.__class__ not in [xxxMainNode, xxxPanel, xxxFrame] and \ not parent.isSizer: error = True + elif not parent.hasChildren: + error = True elif child.__class__ == xxxPanel and parent.__class__ == xxxMainNode: pass elif child.__class__ == xxxSpacer: @@ -835,12 +837,16 @@ class Frame(wx.Frame): if g.testWin and g.testWin.highLight: g.testWin.highLight.Remove() - tree.needUpdate = True + tree.needUpdate = True # Undo info self.lastOp = 'MOVELEFT' status = 'Made next sibling of parent' + # Prepare undo data + panel.Apply() + tree.UnselectAll() + oldIndex = tree.ItemIndex(selected) elem = tree.RemoveLeaf(selected) nextItem = tree.GetFirstChild(pparent)[0] @@ -901,7 +907,11 @@ class Frame(wx.Frame): # Remove highlight, update testWin if g.testWin and g.testWin.highLight: g.testWin.highLight.Remove() - tree.needUpdate = True + tree.needUpdate = True + + # Prepare undo data + panel.Apply() + tree.UnselectAll() # Undo info self.lastOp = 'MOVERIGHT' @@ -939,6 +949,7 @@ class Frame(wx.Frame): selected = tree.InsertNode(newParent, tree.GetPyData(newParent).treeObject(), elem, wx.TreeItemId()) newIndex = tree.ItemIndex(selected) + tree.Expand(selected) tree.SelectItem(selected) undoMan.RegisterUndo(UndoMove(oldParent, oldIndex, newParent, newIndex)) -- 2.47.2