added:
authorClaus Gittinger <cg@exept.de>
Fri, 19 Feb 1999 16:32:26 +0100
changeset 1209 2f7f9bf064bb
parent 1208 2f9d74cead2f
child 1210 55f2c4209f94
added: replaceNode:aNode with:aNewNode
SelInTree.st
SelectionInTree.st
--- a/SelInTree.st	Fri Feb 19 16:29:43 1999 +0100
+++ b/SelInTree.st	Fri Feb 19 16:32:26 1999 +0100
@@ -484,6 +484,47 @@
     sel := self selectionIndex.
     self selectionIndex:nil.
     self remove:sel.
+!
+
+replaceNode:aNode with:aNewNode
+    "replace a node by a new node; if the new node is nil, the node and its
+     children are removed. Otherwise the children are taken over to the new
+     node.
+    "
+    |parent index children|
+
+    (aNode isNil or:[aNode == aNewNode]) ifTrue:[
+        ^ self
+    ].
+
+    aNewNode isNil ifTrue:[
+        ^ self remove:aNode
+    ].
+    self stopIndicatorValidationFor:aNode.
+
+    aNewNode children:(aNode children).    
+    aNode    children:nil.
+
+    aNode == root ifTrue:[
+        aNewNode tree:(aNode tree).
+        aNewNode parent:nil.
+        root := aNewNode.
+    ] ifFalse:[
+        parent := aNode parent.
+        aNewNode tree:nil.
+        aNewNode parent:parent.
+        children := parent children.
+        index := children identityIndexOf:aNode.
+        children at:index put:aNewNode.
+    ].
+
+    aNode tree:nil.        
+    aNode parent:nil.        
+
+    (index := self indexOf:aNode) ~~ 0 ifTrue:[
+        list at:index put:aNewNode.
+        self changed:#at: with:index
+    ].
 ! !
 
 !SelectionInTree methodsFor:'change & update'!
@@ -833,5 +874,5 @@
 !SelectionInTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelInTree.st,v 1.22 1999-02-18 19:38:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelInTree.st,v 1.23 1999-02-19 15:32:26 cg Exp $'
 ! !
--- a/SelectionInTree.st	Fri Feb 19 16:29:43 1999 +0100
+++ b/SelectionInTree.st	Fri Feb 19 16:32:26 1999 +0100
@@ -484,6 +484,47 @@
     sel := self selectionIndex.
     self selectionIndex:nil.
     self remove:sel.
+!
+
+replaceNode:aNode with:aNewNode
+    "replace a node by a new node; if the new node is nil, the node and its
+     children are removed. Otherwise the children are taken over to the new
+     node.
+    "
+    |parent index children|
+
+    (aNode isNil or:[aNode == aNewNode]) ifTrue:[
+        ^ self
+    ].
+
+    aNewNode isNil ifTrue:[
+        ^ self remove:aNode
+    ].
+    self stopIndicatorValidationFor:aNode.
+
+    aNewNode children:(aNode children).    
+    aNode    children:nil.
+
+    aNode == root ifTrue:[
+        aNewNode tree:(aNode tree).
+        aNewNode parent:nil.
+        root := aNewNode.
+    ] ifFalse:[
+        parent := aNode parent.
+        aNewNode tree:nil.
+        aNewNode parent:parent.
+        children := parent children.
+        index := children identityIndexOf:aNode.
+        children at:index put:aNewNode.
+    ].
+
+    aNode tree:nil.        
+    aNode parent:nil.        
+
+    (index := self indexOf:aNode) ~~ 0 ifTrue:[
+        list at:index put:aNewNode.
+        self changed:#at: with:index
+    ].
 ! !
 
 !SelectionInTree methodsFor:'change & update'!
@@ -833,5 +874,5 @@
 !SelectionInTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.22 1999-02-18 19:38:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.23 1999-02-19 15:32:26 cg Exp $'
 ! !