Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.269.mcz==================== Summary ====================
Name: Collections-ar.269
Author: ar
Time: 31 December 2009, 8:35:06 am
UUID: e0d39f0d-6a39-6243-a032-9d93d8364c82
Ancestors: Collections-ar.268
Tidy up do:displayingProgress:every: a little. Make sure we update label before processing the element (may not be valid afterwards) and ensure that progress is always displayed for the first and the last element.
=============== Diff against Collections-ar.268 ===============
Item was changed:
----- Method: Collection>>do:displayingProgress:every: (in category 'enumerating') -----
do: aBlock displayingProgress: aStringOrBlock every: msecs
"Enumerate aBlock displaying progress information.
If the argument is a string, use a static label for the process.
If the argument is a block, evaluate it with the element to retrieve the label.
The msecs argument ensures that updates happen at most every msecs.
Example:
Smalltalk allClasses
do:[:aClass| (Delay forMilliseconds: 1) wait]
displayingProgress:[:aClass| 'Processing ', aClass name]
every: 0.
Smalltalk allClasses
do:[:aClass| (Delay forMilliseconds: 1) wait]
displayingProgress:[:aClass| 'Processing ', aClass name]
every: 100.
"
| count size labelBlock oldLabel newLabel lastUpdate |
labelBlock := aStringOrBlock isString
ifTrue:[[:item| aStringOrBlock]]
ifFalse:[aStringOrBlock].
+ oldLabel := nil.
+ count := lastUpdate := 0.
- count := 0.
size := self size.
'' displayProgressAt: Sensor cursorPoint from: 0 to: size during:[:bar |
self do:[:each|
+ "Special handling for first and last element"
+ (count = 0 or:[count+1 = size
+ or:[(Time millisecondsSince: lastUpdate) >= msecs]]) ifTrue:[
+ bar value: count.
+ oldLabel = (newLabel := labelBlock value: each) ifFalse:[
- "Special handling for initial progress"
- (count = 0 or:[count = size]) ifTrue:[
- bar value: count.
- ProgressNotification signal: '' extra: (oldLabel := labelBlock value: each).
- lastUpdate := Time millisecondClockValue.
- ].
- aBlock value: each.
- count := count + 1.
- (Time millisecondsSince: lastUpdate) >= msecs ifTrue:[
- bar value: count.
- oldLabel = (newLabel := labelBlock value: each) ifFalse:[
ProgressNotification signal: '' extra: (oldLabel := newLabel).
].
lastUpdate := Time millisecondClockValue.
].
+ aBlock value: each.
+ count := count + 1.
]]!