--- a/HierarchicalItem.st Thu Feb 23 22:14:51 2006 +0100
+++ b/HierarchicalItem.st Mon Mar 06 09:39:04 2006 +0100
@@ -150,15 +150,15 @@
at:anIndex
"return the child at anIndex if valid;
- if the index is invalid, nil is returned
- "
+ if the index is invalid, nil is returned"
+
^ self at:anIndex ifAbsent:nil
!
at:anIndex ifAbsent:exceptionBlock
"return the child at anIndex if valid; if the index is
- invalid, the result of evaluating the exceptionBlock is returned.
- "
+ invalid, the result of evaluating the exceptionBlock is returned."
+
|list|
(list := self children) notNil ifTrue:[
@@ -168,8 +168,8 @@
!
at:anIndex put:anItem
- "replace a child by a new item
- "
+ "replace a child by a new item"
+
|children oldItem visIndex model expFlag|
anItem isNil ifTrue:[
@@ -204,8 +204,8 @@
!
children:aListOfChildren
- "set a new list of children
- "
+ "set a new list of children"
+
self criticalDo:[
self removeAll.
self addAll:aListOfChildren beforeIndex:1
@@ -403,8 +403,8 @@
!HierarchicalItem methodsFor:'accessing-mvc'!
application
- "returns the responsible application or nil
- "
+ "returns the responsible application or nil"
+
|model|
(model := self model) notNil ifTrue:[
@@ -414,14 +414,13 @@
!
applicationsDo:aOneArgBlock
- "evaluate the block on each dependent application
- "
+ "evaluate the block for each dependent application"
+
|model|
(model := self model) notNil ifTrue:[
model applicationsDo:aOneArgBlock
]
-
!
model
@@ -441,44 +440,44 @@
!HierarchicalItem methodsFor:'adding & removing'!
add:aChildItem
- "add a child at end
- "
+ "add a child at end"
+
^ self add:aChildItem beforeIndex:(self children size + 1).
!
add:aChildItem after:aChild
- "add an item after an existing item
- "
+ "add an item after an existing item"
+
|index|
index := self identityIndexOf:aChild.
index == 0 ifTrue:[ self subscriptBoundsError:index ].
self add:aChildItem beforeIndex:(index + 1).
- ^ aChildItem
+ ^ aChildItem
!
add:aChildItem afterIndex:anIndex
- "add an item after an index
- "
+ "add an item after an index"
+
^ self add:aChildItem beforeIndex:(anIndex + 1).
!
add:aChildItem before:aChild
- "add an item before an existing item
- "
+ "add an item before an existing item"
+
|index|
index := self identityIndexOf:aChild.
index == 0 ifTrue:[ self subscriptBoundsError:index ].
self add:aChildItem beforeIndex:index.
- ^ aChild
+ ^ aChild
!
add:aChildItem beforeIndex:anIndex
- "add an item before an index
- "
+ "add an item before an index"
+
aChildItem notNil ifTrue:[
self addAll:(Array with:aChildItem) beforeIndex:anIndex
].
@@ -486,8 +485,8 @@
!
add:aChild sortBlock:aBlock
- "add a child sorted
- "
+ "add a child sorted"
+
self criticalDo:[
self basicAdd:aChild sortBlock:aBlock
].
@@ -495,25 +494,25 @@
!
addAll:aList
- "add children at the end
- "
+ "add children at the end"
+
^ self addAll:aList beforeIndex:(self children size + 1)
!
addAll:aList before:aChild
- "add an item before an existing item
- "
+ "add an item before an existing item"
+
|index|
index := self identityIndexOf:aChild.
index == 0 ifTrue:[ self subscriptBoundsError:index ].
- ^ self addAll:aList beforeIndex:index
+ ^ self addAll:aList beforeIndex:index
!
addAll:aList beforeIndex:anIndex
- "add children before an index
- "
+ "add children before an index"
+
aList size ~~ 0 ifTrue:[
self criticalDo:[
self basicAddAll:aList beforeIndex:anIndex
@@ -523,8 +522,8 @@
!
addAll:aList sortBlock:aBlock
- "add children sorted
- "
+ "add children sorted"
+
aList size == 0 ifTrue:[ ^ aList ].
aBlock isNil ifTrue:[
@@ -538,27 +537,26 @@
!
addAllFirst:aCollectionOfItems
- "add children at the beginning
- "
+ "add children at the beginning"
+
^ self addAll:aCollectionOfItems beforeIndex:1
!
addAllLast:aCollectionOfItems
- "add children at the end
- "
+ "add children at the end"
+
^ self addAll:aCollectionOfItems
!
addFirst:aChildItem
- "add a child at begin
- "
+ "add a child at the beginning"
+
^ self add:aChildItem beforeIndex:1.
-
!
addLast:anItem
- "add a child at end
- "
+ "add a child at the end"
+
^ self add:anItem
!
@@ -646,8 +644,8 @@
!HierarchicalItem methodsFor:'basic adding & removing'!
basicAdd:aChild sortBlock:aBlock
- "add a child sorted
- "
+ "add a child sorted"
+
|size list|
size := children size.
@@ -666,8 +664,8 @@
!
basicAddAll:aList beforeIndex:anIndex
- "add children before an index
- "
+ "add children before an index"
+
|coll model notify index size|
size := children size.
@@ -727,8 +725,8 @@
basicRemoveFromIndex:startIndex toIndex:stopIndex
"remove the children from startIndex up to and including
- the child under stopIndex.
- "
+ the child under stopIndex."
+
|model notify
index "{ Class:SmallInteger }"
start "{ Class:SmallInteger }"
@@ -806,8 +804,8 @@
"called if the order of the children changed by a user
operation. Update the model and raise a change notification for
each item which has changed its position
- triggered by the user operation !!
- "
+ triggered by the user operation !!"
+
|model visStart list|
self isExpanded ifFalse:[ ^ self ]. "/ not expanded
@@ -862,13 +860,13 @@
collect:aBlock
"for each child in the receiver, evaluate the argument, aBlock
- and return a new collection with the results
- "
+ and return a new collection with the results"
+
|coll|
coll := OrderedCollection new.
self do:[:el| coll add:(aBlock value:el) ].
- ^ coll
+ ^ coll
!
contains:aBlock
@@ -1342,8 +1340,8 @@
children
"returns a list of children
- *** to optimize: redefine by subClass
- "
+ *** to optimize: redefine by subClass"
+
|model|
children isNil ifTrue:[
@@ -1639,34 +1637,32 @@
detect:aOneArgBlock
"find the first child, for which evaluation of the block returns
- true; if none does so, report an error
- "
+ true; if none does so, report an error"
+
^ self detect:aOneArgBlock ifNone:[self errorNotFound]
-
!
detect:anOneArgBlock ifNone:anExceptionBlock
"find the first child, for which evaluation of the block returns
- true; if none does so, return the evaluation of anExceptionBlock
- "
+ true; if none does so, return the evaluation of anExceptionBlock"
+
self do:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ].
- ^ anExceptionBlock value
+ ^ anExceptionBlock value
!
detectLast:aOneArgBlock
"find the last child, for which evaluation of the block returns
- true; if none does so, an exception is raised
- "
+ true; if none does so, an exception is raised"
+
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound]
-
!
detectLast:anOneArgBlock ifNone:anExceptionBlock
"find the last child, for which evaluation of the block returns
- true; if none does so, return the evaluation of anExceptionBlock
- "
+ true; if none does so, return the evaluation of anExceptionBlock"
+
self reverseDo:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ].
- ^ anExceptionBlock value
+ ^ anExceptionBlock value
!
findFirst:anOneArgBlock
@@ -1903,5 +1899,5 @@
!HierarchicalItem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.75 2006-01-11 15:46:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.76 2006-03-06 08:39:04 cg Exp $'
! !