SelectionInTree.st
changeset 496 d511fde77222
parent 491 c7d57a5e7a21
child 509 c6c9f5ecb977
--- a/SelectionInTree.st	Fri Aug 15 11:25:43 1997 +0200
+++ b/SelectionInTree.st	Fri Aug 15 11:26:23 1997 +0200
@@ -13,7 +13,7 @@
 
 
 Model subclass:#SelectionInTree
-	instanceVariableNames:'root list selection'
+	instanceVariableNames:'root list selection showRoot'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Support-Models'
@@ -71,27 +71,32 @@
 root:aRootNode
     "set a new root and recompute list
     "
-    self root:aRootNode keepRoot:false
+    root := aRootNode.
+    self recomputeList.
+
+! !
 
+!SelectionInTree methodsFor:'accessing behavior'!
+
+showRoot
+    "list with or without root
+    "
+    ^ showRoot
 !
 
-root:aRootNode keepRoot:keepRoot
-    "set a new root and recompute list
+showRoot:aState
+    "list with or without root
     "
-    |idx children|
+    aState ~~ showRoot ifTrue:[
+        showRoot := aState.
 
-    (keepRoot and:[root notNil]) ifTrue:[
-        children := aRootNode children.
+        root notNil ifTrue:[
+            aState ifTrue:[list addFirst:root]
+                  ifFalse:[list removeFirst].
 
-        idx := children findFirst:[:el| el name = root name ].
-
-        idx ~~ 0 ifTrue:[
-            root parent:aRootNode.
-            children at:idx put:root.
+            self changed:#list.
         ].
     ].
-    root := aRootNode.
-    self recomputeList.
 ! !
 
 !SelectionInTree methodsFor:'accessing hierarchy'!
@@ -228,6 +233,13 @@
 
 ! !
 
+!SelectionInTree methodsFor:'initialization'!
+
+initialize
+    super initialize.
+    showRoot := true.
+! !
+
 !SelectionInTree methodsFor:'private'!
 
 recomputeList
@@ -243,7 +255,9 @@
     list := OrderedCollection new.
 
     root notNil ifTrue:[
-        list add:root.
+        showRoot ifTrue:[
+            list add:root
+        ].
         root recomputeList:list
     ].
 ! !
@@ -271,6 +285,25 @@
 selectionIndex:indexesOrNil
     "set the selection
     "
+    |oldSel|
+
+    oldSel := selection.
+    self setSelectionIndex:indexesOrNil.
+
+    oldSel = selection ifFalse:[
+        self changed:#selection
+    ]
+!
+
+setSelection:indexesOrNil
+    "set the selection without raising a notification
+    "
+    self setSelectionIndex:indexesOrNil
+!
+
+setSelectionIndex:indexesOrNil
+    "set the selection without raising a notification
+    "
     |indexes|
 
     indexes := indexesOrNil.
@@ -280,15 +313,12 @@
             indexes := nil
         ]
     ].
+    selection := indexes
 
-    indexes = selection ifFalse:[
-        selection := indexes.
-        self changed:#selection
-    ]
 ! !
 
 !SelectionInTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.3 1997-08-11 11:02:03 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.4 1997-08-15 09:26:23 ca Exp $'
 ! !