--- a/HierarchicalItem.st Thu Oct 17 08:37:35 2002 +0200
+++ b/HierarchicalItem.st Thu Oct 17 09:05:40 2002 +0200
@@ -240,28 +240,34 @@
expand
"expand children
"
- self canExpand ifTrue:[
- self criticalDo:[ |index list|
- (index := self listIndex) notNil ifTrue:[
- "/ must set expand-flag to false, otherwise change notifications
- "/ are raised durring lazy auto creation (to the list).
- isExpanded := false.
- list := self children.
- isExpanded := true.
+ |index list|
+
+ "/ test whether the item already is expanded; #canExpand could be redefined
+ "/ without checking whether the node is expanded (happens already) !!
+
+ isExpanded == true ifTrue:[ ^ self ].
+ self canExpand ifFalse:[ ^ self ].
- list notNil ifTrue:[
- list notEmpty ifTrue:[
- list := OrderedCollection new:64.
- self addVisibleChildrenTo:list.
- self model itemAddAll:list beforeIndex:(index + 1).
- ]
- ].
- index ~~ 0 ifTrue:[self hierarchyChanged].
- ] ifFalse:[
- isExpanded := true
- ]
+ self criticalDo:[
+ (index := self listIndex) notNil ifTrue:[
+ "/ must set expand-flag to false, otherwise change notifications
+ "/ are raised durring lazy auto creation (to the list).
+ isExpanded := false.
+ list := self children.
+ isExpanded := true.
+
+ list notNil ifTrue:[
+ list notEmpty ifTrue:[
+ list := OrderedCollection new:64.
+ self addVisibleChildrenTo:list.
+ self model itemAddAll:list beforeIndex:(index + 1).
+ ]
+ ].
+ index ~~ 0 ifTrue:[self hierarchyChanged].
+ ] ifFalse:[
+ isExpanded := true
]
- ]
+ ].
!
makeVisible
@@ -312,25 +318,31 @@
"
|index list|
- self canExpand ifTrue:[
- isExpanded := true.
+ "/ test whether the item already is expanded; #canExpand could be redefined
+ "/ without checking whether the node is expanded (happens already) !!
+
+ isExpanded == true ifTrue:[ ^ self ].
+ self canExpand ifFalse:[ ^ self ].
+
+ isExpanded := true.
- self criticalDo:[
- self size ~~ 0 ifTrue:[
- (index := self listIndex) isNil ifTrue:[
- self nonCriticalFrom:1 to:nil do:[:el|
- el setExpanded:true
- ].
- ] ifFalse:[
- list := OrderedCollection new:512.
- self recursiveSetExpandedAndAddToList:list.
- self model itemAddAll:list beforeIndex:(index + 1).
+ self criticalDo:[
+ self size ~~ 0 ifTrue:[
+ index := self listIndex. "/ get the visible list index
- index ~~ 0 ifTrue:[self hierarchyChanged]
- ]
+ index isNil ifTrue:[ "/ not visible
+ self nonCriticalFrom:1 to:nil do:[:el|
+ el setExpanded:true
+ ].
+ ] ifFalse:[
+ list := OrderedCollection new:512.
+ self recursiveSetExpandedAndAddToList:list.
+ self model itemAddAll:list beforeIndex:(index + 1).
+
+ index ~~ 0 ifTrue:[self hierarchyChanged]
]
]
- ]
+ ].
!
recursiveToggleExpand
@@ -771,8 +783,8 @@
visStart := model identityIndexOf:self.
visStart == 0 ifTrue:[
- self parent ifNotNil:[ ^ self ]. "/ not visible in the model
- "/ I am the root and not visible
+ model root ~~ self ifTrue:[ ^ self ].
+ "/ I'am the root but switched of by setting #showRoot to false
].
self criticalDo:[
@@ -1410,6 +1422,20 @@
!HierarchicalItem methodsFor:'protocol queries'!
+canCollapse
+ "called before collapsing the item; can be redefined
+ by subclass to omit the collapse operation
+ "
+ ^ (isExpanded == true)
+!
+
+canExpand
+ "called before expanding the item; can be redefined
+ by subclass to omit the collapse operation
+ "
+ ^ (isExpanded == true) not and:[self hasChildren]
+!
+
drawHorizontalLineUpToText
"draw the horizizontal line for the selected item up to the text
or on default to the start of the the vertical line; only used by
@@ -1433,6 +1459,12 @@
^ self hasChildren
!
+isSelectable
+ "returns true if the item is selectable otherwise false
+ "
+ ^ true
+!
+
string
"access the printable string used for steping through a list
searching for an entry starting with a character.
@@ -1462,18 +1494,6 @@
!HierarchicalItem methodsFor:'queries'!
-canCollapse
- "called before collapsing the item
- "
- ^ (isExpanded == true)
-!
-
-canExpand
- "called before expanding the item
- "
- ^ (isExpanded == true) not and:[self hasChildren]
-!
-
isChildOf:anItem
"returns true if the item is a child of anItem
"
@@ -1490,8 +1510,14 @@
!
+isCollapsed
+ "returns true if the item is collapsed
+ "
+ ^ (isExpanded ~~ true)
+!
+
isExpanded
- "return true if item is expanded
+ "returns true if the item is expanded
"
^ (isExpanded == true)
!
@@ -1522,12 +1548,6 @@
^ parent isHierarchicalItem not
!
-isSelectable
- "returns true if the item is selectable otherwise false
- "
- ^ true
-!
-
size
"return the number of children
"
@@ -1802,5 +1822,5 @@
!HierarchicalItem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.45 2002-10-14 14:44:33 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.46 2002-10-17 07:05:40 ca Exp $'
! !