0.1.6-4: replace working for sizeritems and spacers

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35192 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Roman Rolinsky
2005-08-15 19:53:33 +00:00
parent f02a4ffa5f
commit baba4aa5ec
4 changed files with 90 additions and 17 deletions

View File

@@ -1,3 +1,9 @@
0.1.6-4
-------
Fixed replacing op for sizer children and spacer objects.
UndoReplace is not yet implemented.
0.1.6-3 0.1.6-3
------- -------

View File

@@ -15,7 +15,7 @@ import sys
# Global constants # Global constants
progname = 'XRCed' progname = 'XRCed'
version = '0.1.6-3' version = '0.1.6-4'
# Can be changed to set other default encoding different # Can be changed to set other default encoding different
#defaultEncoding = '' #defaultEncoding = ''
# you comment above and can uncomment this: # you comment above and can uncomment this:

View File

@@ -5,6 +5,7 @@
# RCS-ID: $Id$ # RCS-ID: $Id$
from globals import * from globals import *
from xxx import MakeXXXFromDOM
#from panel import * #from panel import *
# Undo/redo classes # Undo/redo classes
@@ -119,6 +120,49 @@ class UndoPasteCreate:
else: else:
g.tree.pendingHighLight = None g.tree.pendingHighLight = None
class UndoReplace:
def __init__(self, item):
self.itemIndex = g.tree.ItemFullIndex(item)
self.xxx = g.tree.GetPyData(item)
def destroy(self):
if self.xxx: self.xxx.element.unlink()
def undo(self):
print 'Sorry, UndoReplace is not yet implemented.'
return
item = g.tree.ItemAtFullIndex(self.itemIndex)
xxx = g.tree.GetPyData(item)
# Replace with old element
parent = xxx.parent.element
if xxx is self.xxx: # sizeritem or notebookpage - replace child
parent.replaceChild(self.xxx.child.element, xxx.child.element)
else:
parent.replaceChild(self.xxx.element, xxx.element)
self.xxx.parent = xxx.parent
xxx = self.xxx
g.tree.SetPyData(item, xxx)
g.tree.SetItemText(item, xxx.treeName())
g.tree.SetItemImage(item, xxx.treeImage())
# Update panel
g.panel.SetData(xxx)
# Update tools
g.tools.UpdateUI()
g.tree.EnsureVisible(item)
g.tree.SelectItem(item)
# Delete testWin?
if g.testWin:
# If deleting top-level item, delete testWin
if selected == g.testWin.item:
g.testWin.Destroy()
g.testWin = None
else:
# Remove highlight, update testWin
if g.testWin.highLight:
g.testWin.highLight.Remove()
g.tree.needUpdate = True
def redo(self):
return
class UndoEdit: class UndoEdit:
def __init__(self): def __init__(self):
self.pages = map(ParamPage.GetState, g.panel.pages) self.pages = map(ParamPage.GetState, g.panel.pages)

View File

@@ -800,21 +800,25 @@ Homepage: http://xrced.sourceforge.net\
tree.SetFocus() tree.SetFocus()
self.SetModified() self.SetModified()
# Replace one object with another # Replace one object with another
def OnReplace(self, evt): def OnReplace(self, evt):
selected = tree.selection selected = tree.selection
xxx = tree.GetPyData(selected).treeObject() xxx = tree.GetPyData(selected).treeObject()
elem = xxx.element elem = xxx.element
parent = elem.parentNode parent = elem.parentNode
parentXXX = xxx.parent undoMan.RegisterUndo(UndoReplace(selected))
# New class # New class
className = pullDownMenu.createMap[evt.GetId() - 1000] className = pullDownMenu.createMap[evt.GetId() - 1000]
# Create temporary empty node (with default values) # Create temporary empty node (with default values)
dummy = MakeEmptyDOM(className) dummy = MakeEmptyDOM(className)
xxxClass = xxxDict[className] if className == 'spacer' and xxx.className != 'spacer':
klass = xxxSpacer
elif xxx.className == 'spacer' and className != 'spacer':
klass = xxxSizerItem
else:
klass = xxxDict[className]
# Remove non-compatible children # Remove non-compatible children
if tree.ItemHasChildren(selected) and not xxxClass.hasChildren: if tree.ItemHasChildren(selected) and not klass.hasChildren:
tree.DeleteChildren(selected) tree.DeleteChildren(selected)
nodes = elem.childNodes[:] nodes = elem.childNodes[:]
tags = [] tags = []
@@ -823,10 +827,9 @@ Homepage: http://xrced.sourceforge.net\
remove = False remove = False
tag = node.tagName tag = node.tagName
if tag == 'object': if tag == 'object':
if not xxxClass.hasChildren: if not klass.hasChildren: remove = True
remove = True elif tag not in klass.allParams and \
elif tag not in xxxClass.allParams and \ (not klass.hasStyle or tag not in klass.styles):
(not xxxClass.hasStyle or tag not in xxxClass.styles):
remove = True remove = True
else: else:
tags.append(tag) tags.append(tag)
@@ -834,18 +837,37 @@ Homepage: http://xrced.sourceforge.net\
elem.removeChild(node) elem.removeChild(node)
node.unlink() node.unlink()
# Remove sizeritem child if spacer
if className == 'spacer' and xxx.className != 'spacer':
sizeritem = elem.parentNode
assert sizeritem.getAttribute('class') == 'sizeritem'
sizeritem.removeChild(elem)
elem.unlink()
elem = sizeritem
tree.GetPyData(selected).hasChild = false
elif xxx.className == 'spacer' and className != 'spacer':
# Create sizeritem element
assert xxx.parent.isSizer
elem.setAttribute('class', 'sizeritem')
node = MakeEmptyDOM(className)
elem.appendChild(node)
# Replace to point to new object
xxx = xxxSizerItem(xxx.parent, elem)
elem = node
tree.SetPyData(selected, xxx)
xxx = xxx.child
else:
# Copy parameters present in dummy but not in elem # Copy parameters present in dummy but not in elem
for node in dummy.childNodes: for node in dummy.childNodes:
tag = node.tagName if node.tagName not in tags: elem.appendChild(node.cloneNode(True))
if tag not in tags:
elem.appendChild(node.cloneNode(True))
dummy.unlink() dummy.unlink()
# Change class name # Change class name
elem.setAttribute('class', className) elem.setAttribute('class', className)
if elem.hasAttribute('subclass'): if elem.hasAttribute('subclass'):
elem.removeAttribute('subclass') # clear subclassing elem.removeAttribute('subclass') # clear subclassing
# Re-create xxx element # Re-create xxx element
xxx = MakeXXXFromDOM(parentXXX, elem) xxx = MakeXXXFromDOM(xxx.parent, elem)
# Update parent in child objects # Update parent in child objects
if tree.ItemHasChildren(selected): if tree.ItemHasChildren(selected):
i, cookie = tree.GetFirstChild(selected) i, cookie = tree.GetFirstChild(selected)
@@ -861,6 +883,7 @@ Homepage: http://xrced.sourceforge.net\
container.child = xxx container.child = xxx
container.hasChildren = xxx.hasChildren container.hasChildren = xxx.hasChildren
container.isSizer = xxx.isSizer container.isSizer = xxx.isSizer
xxx = container
else: else:
tree.SetPyData(selected, xxx) tree.SetPyData(selected, xxx)
tree.SetItemText(selected, xxx.treeName()) tree.SetItemText(selected, xxx.treeName())