diff --git a/src/Spec2-Dialogs-Tests/SpDialogTest.class.st b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st index 4c0adc34..81c7ba77 100644 --- a/src/Spec2-Dialogs-Tests/SpDialogTest.class.st +++ b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st @@ -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 [ diff --git a/src/Spec2-Dialogs/SpInformUserDialog.class.st b/src/Spec2-Dialogs/SpInformUserDialog.class.st index bd5d5b27..a57cce3f 100644 --- a/src/Spec2-Dialogs/SpInformUserDialog.class.st +++ b/src/Spec2-Dialogs/SpInformUserDialog.class.st @@ -8,7 +8,8 @@ Class { 'title', 'label', 'progressBar', - 'openAction' + 'openAction', + 'returnValue' ], #category : 'Spec2-Dialogs', #package : 'Spec2-Dialogs' @@ -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 ] ] @@ -79,7 +77,9 @@ SpInformUserDialog >> informUserDuring: aBlock [ openAction := aBlock. self openModal. parentWindow ifNotNil: [ - parentWindow takeKeyboardFocus ] + parentWindow takeKeyboardFocus ]. + + ^ returnValue ] { #category : 'initialization' }