Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

informDuring-should-return-value-of-block #1482

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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