HierarchicalListEditor.st
changeset 558 5b5d08815af4
parent 552 8597d3786b09
child 559 33365ca6eb1d
--- a/HierarchicalListEditor.st	Mon Feb 02 23:48:47 1998 +0100
+++ b/HierarchicalListEditor.st	Tue Feb 03 00:01:16 1998 +0100
@@ -515,6 +515,7 @@
                 #'label:' 'Save'
                 #'isButton:' true
                 #'value:' #doInstall
+                #'activeHelpKey:' #fileSave
                 #'enabled:' #hasValidClass
                 #'labelImage:' #(#ResourceRetriever nil #saveIcon)
             )
@@ -789,7 +790,7 @@
 newItem
     "creates and returns a new default item"
 
-    ^TreeItem name: 'Undefined' contents: nil
+    ^TreeItem name: 'Item' contents: nil
 !
 
 updateChannels
@@ -1044,13 +1045,15 @@
 doCreateChild
     "create a child within selected parent"
 
-    |node|
+    |node newItem|
 
     (node := treeView selectedNode) notNil 
     ifTrue:
     [
-        treeView model add: self newItem beforeIndex:1 below:node.
+        treeView model add: (newItem := self newItem) afterIndex: node children size below:node.
+        newItem name: 'Child ', (self getDepthAndSistersNumberOfNode: newItem onParentNode: node).
         treeView selectedNodeExpand:true.
+        treeView selectNode: newItem.
         self updateChannels.
         isModified := true
     ]
@@ -1059,14 +1062,17 @@
 doCreateSister
     "create a sister next to selected item
     "
-    |node|
+    |node newItem|
 
     (node := treeView selectedNode) notNil 
     ifTrue:
     [
+        newItem := self newItem.
         node parent notNil 
-            ifTrue: [treeView model add: self newItem after:node] 
-            ifFalse:[treeView model add: self newItem beforeIndex:1 below:node].
+            ifTrue: [treeView model add: newItem after: (node parent children at: node parent children size ifAbsent: nil)] 
+            ifFalse:[treeView model add: newItem beforeIndex:1 below:node].
+        newItem name: 'Child ', (self getDepthAndSistersNumberOfNode: newItem onParentNode: node parent).
+        treeView selectNode: newItem.
         self updateChannels.
         isModified := true
     ]
@@ -1208,8 +1214,8 @@
 doNew
     "remove all items; restart"
 
-    treeView root:(TreeItem name:'Anchor' contents:#anchor).
-    treeView selection:0.
+    treeView root:(TreeItem name:'Root' contents:#anchor).
+    treeView selection:1.
     isModified := true
 
 
@@ -1273,6 +1279,20 @@
 
 
 
+!
+
+getDepthAndSistersNumberOfNode: aNode onParentNode: aParentNode
+    "return depth of selected node"
+
+    |parent childNode depthAndSistersNumber|
+
+    depthAndSistersNumber := ''.
+    childNode := aNode.
+    parent := aParentNode.
+    [parent notNil ] 
+    whileTrue: [depthAndSistersNumber := depthAndSistersNumber, '.', (parent children indexOf: childNode) printString. childNode := parent. parent := parent parent. ].
+
+    ^(depthAndSistersNumber reverse copyFrom: 1 to: depthAndSistersNumber size - 2), aParentNode children size printString
 ! !
 
 !HierarchicalListEditor class methodsFor:'documentation'!