Skip to content

Commit

Permalink
- informDuring: should return the value of the block.
Browse files Browse the repository at this point in the history
- Adding test
  • Loading branch information
tesonep committed Dec 1, 2023
1 parent d67b04e commit c23dac0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/Spec2-Dialogs-Tests/SpDialogTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ SpDialogTest >> testInformUserDuringViaPresenter [
self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testInformUserReturnsValueOfTheBlock [

| returned |
returned := SpInformUserDialog new informUser: 'hello' during: [ 42 ].
self assert: returned equals: 42.
]

{ #category : 'tests - progress bar' }
SpDialogTest >> testProgressInformUserDuringExecutesItsBlock [

Expand Down
28 changes: 14 additions & 14 deletions src/Spec2-Dialogs/SpInformUserDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Class {
'title',
'label',
'progressBar',
'openAction'
'openAction',
'returnValue'
],
#category : 'Spec2-Dialogs',
#package : 'Spec2-Dialogs'
Expand Down Expand Up @@ -46,27 +47,24 @@ SpInformUserDialog class >> extent [

{ #category : 'private - actions' }
SpInformUserDialog >> afterOpenAction [

openAction ifNil: [ ^ self ].

[
[
openAction value.
self accept ]
on: Error
fork: [ :e |
self cancel.
e pass ].
] fork
[
[
returnValue := openAction value.
self accept ] on: Error fork: [ :e |
self cancel.
e pass ] ] fork
]

{ #category : 'api' }
{ #category : 'simple dialog helpers' }
SpInformUserDialog >> informUser: aString during: aBlock [
"Pay attention that the aBlock argument does not expect an argument representing the bar.
Check class side example."

title := aString.
self informUserDuring: [
^ self informUserDuring: [
aBlock value ]
]

Expand All @@ -79,7 +77,9 @@ SpInformUserDialog >> informUserDuring: aBlock [
openAction := aBlock.
self openModal.
parentWindow ifNotNil: [
parentWindow takeKeyboardFocus ]
parentWindow takeKeyboardFocus ].

^ returnValue
]

{ #category : 'initialization' }
Expand Down

0 comments on commit c23dac0

Please sign in to comment.