--- a/HierarchicalItem.st Fri Jul 09 08:43:47 2010 +0200
+++ b/HierarchicalItem.st Fri Jul 09 09:00:29 2010 +0200
@@ -94,30 +94,17 @@
"returns the children as they are present (or not); not going to the model..."
^ children
-
- "Modified: / 09-07-2010 / 08:43:29 / cg"
!
level
- "returns the level starting with 1"
+ "returns the level starting with 0 for the root"
|item level|
- "/ for optimization we try to suppress a block
-
- item := self.
+ item := self.
+ level := 0.
- (item := item parentOrModel) isNil ifTrue:[^ 0].
- (item := item parentOrModel) isNil ifTrue:[^ 1].
- (item := item parentOrModel) isNil ifTrue:[^ 2].
- (item := item parentOrModel) isNil ifTrue:[^ 3].
- (item := item parentOrModel) isNil ifTrue:[^ 4].
- (item := item parentOrModel) isNil ifTrue:[^ 5].
- (item := item parentOrModel) isNil ifTrue:[^ 6].
-
- level := 7.
-
- [(item := item parentOrModel) notNil] whileTrue:[
+ [ (item := item parentOrModel) notNil] whileTrue:[
level := level + 1.
level > 100000 ifTrue:[
self halt:'possibly recursive item hierarchy'
@@ -125,7 +112,7 @@
].
^ level
- "Modified: / 09-07-2010 / 08:40:56 / cg"
+ "Modified: / 09-07-2010 / 08:56:27 / cg"
!
parent
@@ -134,16 +121,12 @@
^ (parent notNil and:[parent isHierarchicalItem])
ifTrue:[parent]
ifFalse:[nil]
-
- "Modified: / 09-07-2010 / 08:36:07 / cg"
!
parent:aParent
"set the parent (or the model if the item is the root item)"
parent := aParent
-
- "Modified: / 09-07-2010 / 08:35:52 / cg"
!
rootItem
@@ -153,8 +136,6 @@
^ parent rootItem
].
^ self
-
- "Modified: / 09-07-2010 / 08:32:41 / cg"
! !
!HierarchicalItem methodsFor:'accessing-children'!
@@ -236,16 +217,12 @@
"returns the last child"
^ self at:(self size)
-
- "Modified: / 09-07-2010 / 08:41:00 / cg"
!
second
"returns the second child"
^ self at:2
-
- "Modified: / 09-07-2010 / 08:32:37 / cg"
! !
!HierarchicalItem methodsFor:'accessing-hierarchy'!
@@ -329,8 +306,6 @@
parent makeVisible
]
].
-
- "Modified: / 09-07-2010 / 08:40:37 / cg"
!
recursiveCollapse
@@ -396,8 +371,6 @@
]
]
].
-
- "Modified: / 09-07-2010 / 08:33:58 / cg"
!
recursiveToggleExpand
@@ -419,8 +392,6 @@
] ifFalse:[
self expand
].
-
- "Modified: / 29-06-2010 / 21:41:53 / cg"
! !
!HierarchicalItem methodsFor:'accessing-mvc'!
@@ -462,8 +433,6 @@
item isHierarchicalItem ifFalse:[^ item].
^ nil
-
- "Modified: / 09-07-2010 / 08:40:23 / cg"
! !
!HierarchicalItem methodsFor:'adding & removing'!
@@ -597,16 +566,12 @@
ifFalse:[parent root:nil] "parent is HierarchicalList"
].
^ self
-
- "Modified: / 09-07-2010 / 08:33:24 / cg"
!
remove:aChild
"remove a child"
self removeIndex:(self identityIndexOf:aChild)
-
- "Modified: / 09-07-2010 / 08:33:19 / cg"
!
removeAll
@@ -617,8 +582,6 @@
(size := children size) ~~ 0 ifTrue:[
self removeFromIndex:1 toIndex:size
]
-
- "Modified: / 09-07-2010 / 08:33:12 / cg"
!
removeAll:aList
@@ -636,16 +599,12 @@
]
].
^ aList
-
- "Modified: / 09-07-2010 / 08:33:08 / cg"
!
removeFromIndex:startIndex
"remove the children from startIndex up to end of children"
^ self removeFromIndex:startIndex toIndex:(children size)
-
- "Modified: / 09-07-2010 / 08:33:03 / cg"
!
removeFromIndex:startIndex toIndex:stopIndex
@@ -669,8 +628,6 @@
isExpanded := false.
]
].
-
- "Modified: / 09-07-2010 / 08:32:57 / cg"
!
removeIndex:anIndex
@@ -679,8 +636,6 @@
anIndex > 0 ifTrue:[
self removeFromIndex:anIndex toIndex:anIndex
]
-
- "Modified: / 09-07-2010 / 08:32:53 / cg"
! !
!HierarchicalItem methodsFor:'basic adding & removing'!
@@ -762,7 +717,7 @@
notify notNil ifTrue:[
notify changed
].
- ^ aList
+ ^ aList
!
basicRemoveFromIndex:startIndex toIndex:stopIndex
@@ -891,16 +846,12 @@
"hierarchy changed; optimize redrawing"
self changed:#hierarchy with:nil
-
- "Modified: / 09-07-2010 / 08:42:30 / cg"
!
iconChanged
"icon changed; optimize redrawing"
self changed:#icon with:nil
-
- "Modified: / 09-07-2010 / 08:42:20 / cg"
! !
!HierarchicalItem methodsFor:'enumerating'!
@@ -970,8 +921,6 @@
res := self nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock
].
^ res
-
- "Modified: / 09-07-2010 / 08:43:36 / cg"
!
keysAndValuesDo:aTwoArgBlock
@@ -988,8 +937,6 @@
key := key + 1.
].
^ res
-
- "Modified: / 09-07-2010 / 08:41:15 / cg"
!
keysAndValuesReverseDo:aTwoArgBlock
@@ -1005,8 +952,6 @@
res := self nonCriticalKeysAndValuesReverseDo:aTwoArgBlock
].
^ res
-
- "Modified: / 09-07-2010 / 08:41:10 / cg"
!
recursiveCollect:aBlock
@@ -1018,8 +963,6 @@
coll := OrderedCollection new.
self recursiveDo:[:el| coll add:(aBlock value:el) ].
^ coll
-
- "Modified: / 09-07-2010 / 08:34:24 / cg"
!
recursiveDo:aOneArgBlock
@@ -1029,8 +972,6 @@
aOneArgBlock value:aChild.
aChild nonCriticalRecursiveDo:aOneArgBlock
].
-
- "Modified: / 09-07-2010 / 08:34:05 / cg"
!
recursiveReverseDo:aOneArgBlock
@@ -1041,8 +982,6 @@
aChild nonCriticalRecursiveReverseDo:aOneArgBlock.
aOneArgBlock value:aChild.
].
-
- "Modified: / 09-07-2010 / 08:33:52 / cg"
!
recursiveSelect:aBlock
@@ -1054,16 +993,12 @@
coll := OrderedCollection new.
self recursiveDo:[:el| (aBlock value:el) ifTrue:[coll add:el] ].
^ coll
-
- "Modified: / 09-07-2010 / 08:33:47 / cg"
!
reverseDo:aOneArgBlock
"evaluate a block on each child in reverse direction"
^ self from:1 reverseDo:aOneArgBlock
-
- "Modified: / 09-07-2010 / 08:32:48 / cg"
!
select:aBlock
@@ -1075,8 +1010,6 @@
coll := OrderedCollection new.
self do:[:el| (aBlock value:el) ifTrue:[coll add:el] ].
^ coll
-
- "Modified: / 09-07-2010 / 08:32:32 / cg"
!
withAllDo:aOneArgBlock
@@ -1088,8 +1021,6 @@
aOneArgBlock value:el.
el nonCriticalRecursiveDo:aOneArgBlock.
].
-
- "Modified: / 09-07-2010 / 08:31:43 / cg"
! !
!HierarchicalItem methodsFor:'enumerating parents'!
@@ -1099,8 +1030,6 @@
true; if none does so, report an error"
^ self parentsDetect:aBlock ifNone:[self errorNotFound]
-
- "Modified: / 09-07-2010 / 08:35:43 / cg"
!
parentsDetect:aBlock ifNone:anExceptionBlock
@@ -1117,8 +1046,6 @@
]
].
^ anExceptionBlock value
-
- "Modified: / 09-07-2010 / 08:35:37 / cg"
!
parentsDo:aBlock
@@ -1133,8 +1060,6 @@
aBlock value:prnt
]
].
-
- "Modified: / 09-07-2010 / 08:35:31 / cg"
! !
!HierarchicalItem methodsFor:'initialization'!
@@ -1183,8 +1108,6 @@
]
].
^ nil
-
- "Modified: / 09-07-2010 / 08:40:50 / cg"
!
numberOfVisibleChildren
@@ -1205,8 +1128,6 @@
"returns the parent without checking for item or model"
^ parent
-
- "Modified: / 09-07-2010 / 08:35:48 / cg"
!
setExpanded:aBoolean
@@ -1255,8 +1176,6 @@
h := 1 + (aLabel occurrencesOf:(Character cr)).
^ h * (aGC font height)
-
- "Modified: / 09-07-2010 / 08:42:40 / cg"
!
widthOf:aLabel on:aGC
@@ -1281,8 +1200,6 @@
w := 0.
aLabel asCollectionOfLines do:[:el|w := w max:(el widthOn:aGC)].
^ w
-
- "Modified: / 09-07-2010 / 08:32:03 / cg"
! !
!HierarchicalItem methodsFor:'private-enumerating'!
@@ -1291,8 +1208,6 @@
"evaluate a block noncritical for each child."
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock
-
- "Modified: / 09-07-2010 / 08:37:57 / cg"
!
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock
@@ -1310,14 +1225,14 @@
endIndex notNil ifTrue:[
size := size min:endIndex
].
- startIndex to:size do:[:i| |item|
+ startIndex to:size do:[:i|
+ |item|
+
item := list at:i ifAbsent:nil.
item isNil ifTrue:[^ resp].
resp := aOneArgBlock value:item.
].
^ resp
-
- "Modified: / 09-07-2010 / 08:37:50 / cg"
!
nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock
@@ -1341,8 +1256,6 @@
resp := aOneArgBlock value:item.
].
^ resp
-
- "Modified: / 09-07-2010 / 08:37:43 / cg"
!
nonCriticalKeysAndValuesReverseDo:aOneArgBlock
@@ -1363,31 +1276,25 @@
resp := aOneArgBlock value:i value:item.
].
^ resp
-
- "Modified: / 09-07-2010 / 08:37:23 / cg"
!
nonCriticalRecursiveDo:aOneArgBlock
"evaluate the block non critical for each item and all the sub-items"
- self nonCriticalFrom:1 to:nil do:[:aChild|
- aOneArgBlock value:aChild.
- aChild nonCriticalRecursiveDo:aOneArgBlock
+ self nonCriticalFrom:1 to:nil do:[:eachChild|
+ aOneArgBlock value:eachChild.
+ eachChild nonCriticalRecursiveDo:aOneArgBlock
].
-
- "Modified: / 09-07-2010 / 08:36:58 / cg"
!
nonCriticalRecursiveReverseDo:aOneArgBlock
"evaluate the block non critical for each item and all the sub-items;
proccesing children in reverse direction"
- self nonCriticalFrom:1 to:nil reverseDo:[:aChild|
- aChild nonCriticalRecursiveReverseDo:aOneArgBlock.
- aOneArgBlock value:aChild.
+ self nonCriticalFrom:1 to:nil reverseDo:[:eachChild|
+ eachChild nonCriticalRecursiveReverseDo:aOneArgBlock.
+ aOneArgBlock value:eachChild.
].
-
- "Modified: / 09-07-2010 / 08:36:49 / cg"
!
nonCriticalRecursiveSort:aSortBlock
@@ -1402,8 +1309,6 @@
sorted do:[:el| el nonCriticalRecursiveSort:aSortBlock ].
children := sorted.
].
-
- "Modified: / 09-07-2010 / 08:36:33 / cg"
! !
!HierarchicalItem methodsFor:'private-hierarchy'!
@@ -1484,8 +1389,6 @@
^ model iconFor:self
].
^ nil
-
- "Modified: / 09-07-2010 / 08:42:25 / cg"
!
label
@@ -1498,8 +1401,6 @@
^ model labelFor:self
].
^ nil
-
- "Modified: / 09-07-2010 / 08:41:04 / cg"
!
middleButtonMenu
@@ -1514,8 +1415,6 @@
^ model middleButtonMenuFor:self
].
^ nil
-
- "Modified: / 09-07-2010 / 08:40:32 / cg"
!
recursiveSortChildren:aSortBlock
@@ -1573,8 +1472,6 @@
height := self heightOf:(self label) on:aGC
].
^ height
-
- "Modified: / 09-07-2010 / 08:42:35 / cg"
!
widthOn:aGC
@@ -1584,8 +1481,6 @@
width := self widthOf:(self label) on:aGC
].
^ width
-
- "Modified: / 09-07-2010 / 08:31:53 / cg"
! !
!HierarchicalItem methodsFor:'protocol-event processing'!
@@ -1596,8 +1491,6 @@
By default, false is returned (should be handled by the gc)."
^ false
-
- "Modified: / 09-07-2010 / 08:35:22 / cg"
!
processButtonPress:button x:x y:y on:aGC
@@ -1606,8 +1499,6 @@
By default, false is returned (should be handled by the gc)."
^ self processButtonPress:button x:x y:y
-
- "Modified: / 09-07-2010 / 08:35:10 / cg"
!
processButtonPressOnIcon:button on:aGC
@@ -1616,8 +1507,6 @@
By default, false is returned (should be handled by the gc)."
^ false
-
- "Modified: / 09-07-2010 / 08:35:00 / cg"
! !
!HierarchicalItem methodsFor:'protocol-monitoring'!
@@ -1627,8 +1516,6 @@
cycle is enabled. The item can perform some checks, ..
**** can be redefined by subclass to perform some actions
"
-
- "Modified: / 09-07-2010 / 08:38:06 / cg"
! !
!HierarchicalItem methodsFor:'protocol-queries'!
@@ -1675,28 +1562,22 @@
*** to optimize: redefine in subClass"
^ self children size ~~ 0
-
- "Modified: / 09-07-2010 / 08:42:50 / cg"
!
hasIndicator
"on default the indicator is drawn if the item has children"
^ self hasChildren
-
- "Modified: / 09-07-2010 / 08:42:46 / cg"
!
isSelectable
"returns true if the item is selectable"
^ true
-
- "Modified: / 09-07-2010 / 08:41:30 / cg"
!
string
- "access the printable string used for steping through a list
+ "access the printable string used for stepping through a list
searching for an entry starting with a character.
*** to optimize:redefine by subClass"
@@ -1718,8 +1599,6 @@
]
].
^ nil
-
- "Modified: / 09-07-2010 / 08:32:12 / cg"
! !
!HierarchicalItem methodsFor:'queries'!
@@ -1737,8 +1616,6 @@
]
].
^ true
-
- "Modified: / 09-07-2010 / 08:41:58 / cg"
!
isCollapsed
@@ -1764,8 +1641,6 @@
"used to decide if the parent is a hierarchical item or the model"
^ true
-
- "Modified: / 09-07-2010 / 08:41:43 / cg"
!
isRealChildOf:anItem
@@ -1779,24 +1654,18 @@
item := item parent.
].
^ false
-
- "Modified: / 09-07-2010 / 08:41:36 / cg"
!
isRootItem
"returns true if the item is the root item"
^ parent isHierarchicalItem not
-
- "Modified: / 09-07-2010 / 08:41:26 / cg"
!
size
"return the number of children"
^ self children size
-
- "Modified: / 09-07-2010 / 08:32:24 / cg"
! !
!HierarchicalItem methodsFor:'searching'!
@@ -1816,8 +1685,6 @@
(aOneArgBlock value:el) ifTrue:[^ el]
].
^ exceptionBlock value
-
- "Modified: / 13-09-2006 / 11:17:53 / cg"
!
detectLast:aOneArgBlock
@@ -1856,8 +1723,6 @@
"return the index of aChild or 0 if not found. Compare using =="
^ self identityIndexOf:aChild startingAt:1
-
- "Modified: / 09-07-2010 / 08:42:12 / cg"
!
identityIndexOf:aChild startingAt:startIndex
@@ -1873,8 +1738,6 @@
index := index + 1.
].
^ 0
-
- "Modified: / 09-07-2010 / 08:42:07 / cg"
!
recursiveDetect:aOneArgBlock
@@ -1885,8 +1748,6 @@
(aOneArgBlock value:aChild) ifTrue:[^ aChild]
].
^ nil
-
- "Modified: / 09-07-2010 / 08:34:17 / cg"
!
recursiveDetectLast:aBlock
@@ -1897,8 +1758,6 @@
(aBlock value:aChild) ifTrue:[^ aChild].
].
^ nil
-
- "Modified: / 09-07-2010 / 08:34:12 / cg"
!
withAllDetect:aOneArgBlock
@@ -1908,8 +1767,6 @@
(aOneArgBlock value:self) ifTrue:[^ self].
^ self recursiveDetect:aOneArgBlock
-
- "Modified: / 09-07-2010 / 08:31:47 / cg"
! !
!HierarchicalItem methodsFor:'sorting & reordering'!
@@ -1923,8 +1780,6 @@
self childrenOrderChanged.
]
].
-
- "Modified: / 09-07-2010 / 08:33:34 / cg"
!
sort:aSortBlock
@@ -1940,8 +1795,6 @@
self childrenOrderChanged.
]
].
-
- "Modified: / 09-07-2010 / 08:32:19 / cg"
! !
!HierarchicalItem::Example class methodsFor:'instance creation'!
@@ -2084,9 +1937,9 @@
!HierarchicalItem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.93 2010-07-09 06:43:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.94 2010-07-09 07:00:29 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.93 2010-07-09 06:43:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.94 2010-07-09 07:00:29 cg Exp $'
! !