added:
authorClaus Gittinger <cg@exept.de>
Wed, 14 Sep 2011 18:41:21 +0200
changeset 4078 91d764cf9cbd
parent 4077 221b121afa23
child 4079 29b468da8728
added: #new_showProgressOf: #old_showProgressOf: changed: #showProgressOf: run the action in the current thread (for handlers and queries to work)
ProgressIndicator.st
--- a/ProgressIndicator.st	Mon Sep 12 10:21:08 2011 +0200
+++ b/ProgressIndicator.st	Wed Sep 14 18:41:21 2011 +0200
@@ -1220,6 +1220,182 @@
 
 !ProgressIndicator methodsFor:'showing progress'!
 
+new_showProgressOf:aBlock
+    "show progress, while evaluating aBlock.
+     If the receiver has been created with inBox, show the
+     box centered on the screen. If not, the view is assumed to
+     be contained in another view, and no special startup actions
+     are performed.
+
+     The block is passed two arguments, the progressValue,
+     which should be set to the percentage from time-to-time
+     within the block and an action value, which should be set to
+     the currently performed action (a string) from time to time.
+     The second valueHolder can be left unchanged.
+
+     Caveat: cannot (currently) suppress close of the box ..."
+
+    |progressValue labelValue p aborted|
+
+    progressValue := 0 asValue.
+    aborted := false.
+
+    connectedLabel notNil ifTrue:[
+        labelValue := (connectedLabel label ? '') asValue.
+        connectedLabel 
+            model:labelValue;
+            aspect:#value;
+            labelMessage:#value.
+    ] ifFalse:[
+        labelValue := '' asValue.
+    ].
+
+    self model:progressValue.
+
+    "/ the display process
+    p := [
+            self topView show.
+         ] fork.
+
+"/    WindowGroup windowGroupQuerySignal handle:[:ex |
+"/        ex proceedWith:self topView windowGroup
+"/    ] do:[
+        [
+            aBlock value:progressValue value:labelValue
+        ] ensure:[
+            p terminate.
+            p := nil.
+            closeTopWhenDone ifTrue:[
+                connectedTop sensor pushEvent:(WindowEvent terminateView:connectedTop).
+                connectedTop hide
+            ].
+            self topView hide.
+            finishAction value
+        ].
+"/    ].
+
+    "
+      |p|
+
+      p := ProgressIndicator inBox.
+      p showBusyIndication:true.
+      p showProgressOf:
+            [:progressValue :currentAction |
+                1 to:200 do:[:percent |
+                    (Delay forSeconds:0.05) wait.
+                    progressValue value:percent 
+                ].
+            ].
+
+      'it can be reused ...'.  
+      p showBusyIndication:false.
+      p showProgressOf:
+            [:progressValue :currentAction |
+                1 to:100 by:5 do:[:percent |
+                    (Delay forSeconds:0.05) wait.
+                    progressValue value:percent 
+                ].
+            ].
+
+    "
+
+    "Created: / 14-09-2011 / 11:02:21 / cg"
+!
+
+old_showProgressOf:aBlock
+    "show progress, while evaluating aBlock.
+     If the receiver has been created with inBox, show the
+     box centered on the screen. If not, the view is assumed to
+     be contained in another view, and no special startup actions
+     are performed.
+
+     The block is passed two arguments, the progressValue,
+     which should be set to the percentage from time-to-time
+     within the block and an action value, which should be set to
+     the currently performed action (a string) from time to time.
+     The second valueHolder can be left unchanged.
+
+     Caveat: cannot (currently) suppress close of the box ..."
+
+    |progressValue labelValue p aborted|
+
+    progressValue := 0 asValue.
+    aborted := false.
+
+    connectedLabel notNil ifTrue:[
+        labelValue := (connectedLabel label ? '') asValue.
+        connectedLabel 
+            model:labelValue;
+            aspect:#value;
+            labelMessage:#value.
+    ] ifFalse:[
+        labelValue := '' asValue.
+    ].
+
+    self model:progressValue.
+
+    "/ the worker process
+
+    p := [
+        [
+            WindowGroup windowGroupQuerySignal handle:[:ex |
+                ex proceedWith:self topView windowGroup
+            ] do:[
+                AbortSignal handle:[:ex |
+                    aborted := true
+                ] do:[
+                    aBlock value:progressValue value:labelValue
+                ]
+            ]
+        ] ensure:[
+            p := nil.
+            closeTopWhenDone ifTrue:[
+                connectedTop sensor pushEvent:(WindowEvent terminateView:connectedTop).
+                connectedTop hide
+            ].
+            finishAction value
+        ]
+    ] newProcess.
+
+    Processor activeProcess 
+        withHigherPriorityDo:[
+            p resume.
+            self topView show.
+        ].
+    p notNil ifTrue:[p terminate].
+    aborted ifTrue:[
+        AbortSignal raiseRequest
+    ].
+
+    "
+      |p|
+
+      p := ProgressIndicator inBox.
+      p showBusyIndication:true.
+      p showProgressOf:
+            [:progressValue :currentAction |
+                1 to:200 do:[:percent |
+                    (Delay forSeconds:0.05) wait.
+                    progressValue value:percent 
+                ].
+            ].
+
+      'it can be reused ...'.  
+      p showBusyIndication:false.
+      p showProgressOf:
+            [:progressValue :currentAction |
+                1 to:100 by:5 do:[:percent |
+                    (Delay forSeconds:0.05) wait.
+                    progressValue value:percent 
+                ].
+            ].
+
+    "
+
+    "Modified: / 12-09-2011 / 09:57:03 / cg"
+    "Created: / 14-09-2011 / 11:00:12 / cg"
+!
+
 showBusyIndicatorDuring:aBlock
     "show progress, while evaluating aBlock.
      If the receiver has been created with inBox, show the
@@ -1313,55 +1489,8 @@
 
      Caveat: cannot (currently) suppress close of the box ..."
 
-    |progressValue labelValue p aborted|
-
-    progressValue := 0 asValue.
-    aborted := false.
-
-    connectedLabel notNil ifTrue:[
-        labelValue := (connectedLabel label ? '') asValue.
-        connectedLabel 
-            model:labelValue;
-            aspect:#value;
-            labelMessage:#value.
-    ] ifFalse:[
-        labelValue := '' asValue.
-    ].
-
-    self model:progressValue.
-
-    "/ the worker process
-
-    p := [
-        [
-            WindowGroup windowGroupQuerySignal handle:[:ex |
-                ex proceedWith:self topView windowGroup
-            ] do:[
-                AbortSignal handle:[:ex |
-                    aborted := true
-                ] do:[
-                    aBlock value:progressValue value:labelValue
-                ]
-            ]
-        ] ensure:[
-            p := nil.
-            closeTopWhenDone ifTrue:[
-                connectedTop sensor pushEvent:(WindowEvent terminateView:connectedTop).
-                connectedTop hide
-            ].
-            finishAction value
-        ]
-    ] newProcess.
-
-    Processor activeProcess 
-        withHigherPriorityDo:[
-            p resume.
-            self topView show.
-        ].
-    p notNil ifTrue:[p terminate].
-    aborted ifTrue:[
-        AbortSignal raiseRequest
-    ].
+    "/ ^ self old_showProgressOf:aBlock
+    ^ self new_showProgressOf:aBlock
 
     "
       |p|
@@ -1388,15 +1517,15 @@
 
     "
 
-    "Modified: / 12-09-2011 / 09:57:03 / cg"
+    "Modified: / 14-09-2011 / 17:03:08 / cg"
 ! !
 
 !ProgressIndicator class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.66 2011-09-12 08:21:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.67 2011-09-14 16:41:21 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.66 2011-09-12 08:21:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ProgressIndicator.st,v 1.67 2011-09-14 16:41:21 cg Exp $'
 ! !