Improved version for copying and pasting subtrees between nodes. This inhibit that nodes
can appear as children of the same parent several times (clones in Leo vocabulary). Still we need to explore if cloning is useful in other contexts.
This commit is contained in:
parent
0ed3ffe53f
commit
82ba093f3f
@ -78,7 +78,7 @@ GrafoscopioNode >> addLink: anUrl [
|
||||
GrafoscopioNode >> addNode: aNode [
|
||||
"Adds the given node to the receivers collection of children, and sets this object as the parent
|
||||
of the node"
|
||||
aNode parent = self ifTrue: [ ^ self ].
|
||||
"aNode parent = self ifTrue: [ ^ self ]."
|
||||
self children add: aNode.
|
||||
aNode level: (self level) + 1.
|
||||
aNode parent: self.
|
||||
@ -302,8 +302,7 @@ GrafoscopioNode >> content: anObject [
|
||||
|
||||
{ #category : #'add/remove nodes' }
|
||||
GrafoscopioNode >> copyToClipboard [
|
||||
self class clipboard: self copy.
|
||||
self class cleanTreeRootReferences
|
||||
self class clipboard: self subtreeCopy.
|
||||
|
||||
|
||||
]
|
||||
@ -845,7 +844,14 @@ GrafoscopioNode >> parent [
|
||||
{ #category : #accessing }
|
||||
GrafoscopioNode >> parent: aNode [
|
||||
"A parent is a node that has the current node in its children"
|
||||
aNode ifNil: [
|
||||
parent := aNode.
|
||||
^self ].
|
||||
aNode parent = self ifTrue: [ ^ self ].
|
||||
parent := aNode.
|
||||
(aNode children includes: self)
|
||||
ifFalse: [ aNode addNode: self ]
|
||||
|
||||
]
|
||||
|
||||
{ #category : #'add/remove nodes' }
|
||||
@ -947,7 +953,21 @@ GrafoscopioNode >> specModelClass [
|
||||
^ GrafoscopioTextModel
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
{ #category : #operation }
|
||||
GrafoscopioNode >> subtreeCopy [
|
||||
"I return the same node if its subtree only contains the receiver, or a copy of the receivers
|
||||
subtree, in other cases."
|
||||
| linearSubtree linearSubtreeCopy |
|
||||
linearSubtree := self preorderTraversal.
|
||||
linearSubtreeCopy := OrderedCollection new.
|
||||
linearSubtree do: [ :cn | linearSubtreeCopy add: cn surfaceCopy ].
|
||||
linearSubtreeCopy allButFirst doWithIndex: [ :n :i | | parentPos |
|
||||
parentPos := linearSubtree indexOf: (linearSubtree at: i+1) parent.
|
||||
n parent: (linearSubtreeCopy at: parentPos) ].
|
||||
^ linearSubtreeCopy at: 1.
|
||||
]
|
||||
|
||||
{ #category : #operation }
|
||||
GrafoscopioNode >> surfaceCopy [
|
||||
"I copy the most relevant values of the receiver. I'm useful to avoid copying references
|
||||
to the rest of the container tree, which could end in copying the whole tree."
|
||||
|
Loading…
Reference in New Issue
Block a user