diff --git a/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st b/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st index 8f43df40..68f89d33 100644 --- a/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st +++ b/src/BaselineOfSpecCore/BaselineOfSpecCore.class.st @@ -17,6 +17,7 @@ BaselineOfSpecCore >> baseline: spec [ package: 'Spec2-Layout'; package: 'Spec2-Core' with: [ spec requires: #('Spec2-Layout') ]; package: 'Spec2-Dialogs' with: [ spec requires: #('Spec2-Core') ]; + package: 'Spec2-Dialogs-Tests' with: [ spec requires: #('Spec2-Dialogs') ]; package: 'Spec2-CommandLine' with: [ spec requires: #('Spec2-Core') ]; package: 'Spec2-Commands'; package: 'Spec2-Transmission' with: [ spec requires: #('Spec2-Core') ]; @@ -32,7 +33,7 @@ BaselineOfSpecCore >> baseline: spec [ "Tests" package: 'Spec2-Adapters-Stub' with: [ spec requires: #('Spec2-Core') ]; package: 'Spec2-Commander2-Tests' with: [ spec requires: #('Spec2-Commander2') ]; - package: 'Spec2-Tests' with: [ spec requires: #('Spec2-Core' 'Spec2-Examples') ]; + package: 'Spec2-Tests' with: [ spec requires: #('Spec2-Core' 'Spec2-Examples' 'Spec2-Dialogs-Tests') ]; package: 'Spec2-Code-Tests' with: [ spec requires: #('Spec2-Tests' 'Spec2-Code') ]; package: 'Spec2-Code-Diff-Tests' with: [ spec requires: #('Spec2-Tests' 'Spec2-Code-Diff') ]; "Examples" diff --git a/src/Spec2-Core/SpApplication.class.st b/src/Spec2-Core/SpApplication.class.st index 6c847e66..7ef709a6 100644 --- a/src/Spec2-Core/SpApplication.class.st +++ b/src/Spec2-Core/SpApplication.class.st @@ -109,16 +109,6 @@ SpApplication >> adapterBindings [ ^ self backend adapterBindings ] -{ #category : 'ui - dialogs' } -SpApplication >> alert: aString [ - "Displays an inform dialog, for more configurable version please use `self application newInform title: ....`." - - ^ self newAlert - title: 'Alert'; - label: aString; - openModal -] - { #category : 'accessing - backend' } SpApplication >> backend [ @@ -150,16 +140,6 @@ SpApplication >> configuration [ configuration ] ] -{ #category : 'ui - dialogs' } -SpApplication >> confirm: aString [ - "Displays a confirm dialog, for more configurable version please use `self application newConfirm title: ....`." - - ^ self newConfirm - title: 'Please confirm'; - label: aString; - openModal -] - { #category : 'showing' } SpApplication >> defaultBlockedDialogWindowPresenterClass [ @@ -251,16 +231,6 @@ SpApplication >> iconProvider: anIconProvider [ iconProvider := anIconProvider ] -{ #category : 'ui - dialogs' } -SpApplication >> inform: aString [ - "Displays an inform dialog, for more configurable version please use `self application newInform title: ....`." - - ^ self newInform - title: 'Alert'; - label: aString; - openModal -] - { #category : 'accessing' } SpApplication >> locale [ @@ -292,18 +262,6 @@ SpApplication >> notificationCenter [ ^ notificationCenter ifNil: [ notificationCenter := SpNotificationCenter new forApplication: self; yourself ] ] -{ #category : 'ui - dialogs' } -SpApplication >> notificationClass [ - - ^ SpNotificationItem -] - -{ #category : 'ui - dialogs' } -SpApplication >> notify: aString [ - - self notificationCenter add: (self notificationClass with: aString) -] - { #category : 'accessing - properties' } SpApplication >> properties [ @@ -386,18 +344,6 @@ SpApplication >> run [ self start ] -{ #category : 'ui - dialogs' } -SpApplication >> selectDirectoryTitle: aString [ - - ^ self backend selectDirectoryTitle: aString -] - -{ #category : 'ui - dialogs' } -SpApplication >> selectFileTitle: aString [ - - ^ self backend selectFileTitle: aString -] - { #category : 'ui' } SpApplication >> showWaitCursorWhile: aBlock [ diff --git a/src/Spec2-Core/SpPresenter.class.st b/src/Spec2-Core/SpPresenter.class.st index 60312d74..cbbe07f1 100644 --- a/src/Spec2-Core/SpPresenter.class.st +++ b/src/Spec2-Core/SpPresenter.class.st @@ -525,6 +525,13 @@ SpPresenter >> inform: aString [ ^ self application inform: aString ] +{ #category : 'simple dialog helpers' } +SpPresenter >> informUser: aString during: aBlock [ + "Displays a simple inform dialog while a task is perform without progress bar." + + ^ self application informUser: aString during: aBlock +] + { #category : 'TOREMOVE' } SpPresenter >> initialExtent [ diff --git a/src/Spec2-Dialogs-Tests/SpDialogTest.class.st b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st new file mode 100644 index 00000000..46c9d955 --- /dev/null +++ b/src/Spec2-Dialogs-Tests/SpDialogTest.class.st @@ -0,0 +1,44 @@ +Class { + #name : 'SpDialogTest', + #superclass : 'TestCase', + #category : 'Spec2-Dialogs-Tests', + #package : 'Spec2-Dialogs-Tests' +} + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuring [ + + self shouldnt: [ SpInformUserDialog new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error +] + +{ #category : 'tests - progress bar' } +SpDialogTest >> testInformUserDuringExecutesItsBlock [ + + | executed | + executed := false. + SpInformUserDialog new informUser: 'hello' during: [ executed := true ]. + self assert: executed. +] + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuringViaApplication [ + + self shouldnt: [ SpPresenter new application informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error. + +] + +{ #category : 'tests - informUserDuring' } +SpDialogTest >> testInformUserDuringViaPresenter [ + + self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error. + self shouldnt: [ SpPresenter new informUser: 'hello' during: [ (Delay forMilliseconds: 100) wait] ] raise: Error +] + +{ #category : 'tests - progress bar' } +SpDialogTest >> testProgressInformUserDuringExecutesItsBlock [ + + | executed | + executed := false. + SpProgressDialog new informUser: 'hello' during: [ executed := true. ]. + self assert: executed. +] diff --git a/src/Spec2-Dialogs-Tests/package.st b/src/Spec2-Dialogs-Tests/package.st new file mode 100644 index 00000000..0b97e418 --- /dev/null +++ b/src/Spec2-Dialogs-Tests/package.st @@ -0,0 +1 @@ +Package { #name : 'Spec2-Dialogs-Tests' } diff --git a/src/Spec2-Dialogs/SpApplication.extension.st b/src/Spec2-Dialogs/SpApplication.extension.st index 9b6c0099..59115c33 100644 --- a/src/Spec2-Dialogs/SpApplication.extension.st +++ b/src/Spec2-Dialogs/SpApplication.extension.st @@ -1,5 +1,45 @@ Extension { #name : 'SpApplication' } +{ #category : '*Spec2-Dialogs' } +SpApplication >> alert: aString [ + "Displays an inform dialog, for more configurable version please use `self application newInform title: ....`." + + ^ self newAlert + title: 'Alert'; + label: aString; + openModal +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> confirm: aString [ + "Displays a confirm dialog, for more configurable version please use `self application newConfirm title: ....`." + + ^ self newConfirm + title: 'Please confirm'; + label: aString; + openModal +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> inform: aString [ + "Displays an inform dialog, for more configurable version please use `self application newInform title: ....`." + + ^ self newInform + title: 'Alert'; + label: aString; + openModal +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> informUser: aString during: aBlock [ + "Displays an inform user dialog." + + ^ self newInformUser + title: aString; + informUserDuring: aBlock; + openModal +] + { #category : '*Spec2-Dialogs' } SpApplication >> newAlert [ @@ -18,6 +58,12 @@ SpApplication >> newInform [ ^ SpInformDialog newApplication: self ] +{ #category : '*Spec2-Dialogs' } +SpApplication >> newInformUser [ + + ^ SpInformUserDialog newApplication: self +] + { #category : '*Spec2-Dialogs' } SpApplication >> newJobList [ @@ -51,3 +97,27 @@ SpApplication >> newSelect [ ^ SpSelectDialog newApplication: self ] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> notificationClass [ + + ^ SpNotificationItem +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> notify: aString [ + + self notificationCenter add: (self notificationClass with: aString) +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> selectDirectoryTitle: aString [ + + ^ self backend selectDirectoryTitle: aString +] + +{ #category : '*Spec2-Dialogs' } +SpApplication >> selectFileTitle: aString [ + + ^ self backend selectFileTitle: aString +] diff --git a/src/Spec2-Dialogs/SpInformUserDialog.class.st b/src/Spec2-Dialogs/SpInformUserDialog.class.st new file mode 100644 index 00000000..bd5d5b27 --- /dev/null +++ b/src/Spec2-Dialogs/SpInformUserDialog.class.st @@ -0,0 +1,149 @@ +" +I'm a simple dialog to display something during a task proceeds. +" +Class { + #name : 'SpInformUserDialog', + #superclass : 'SpDialogPresenter', + #instVars : [ + 'title', + 'label', + 'progressBar', + 'openAction' + ], + #category : 'Spec2-Dialogs', + #package : 'Spec2-Dialogs' +} + +{ #category : 'documentation' } +SpInformUserDialog class >> documentFactoryMethodSelector [ + + ^ #newInformUserDuring +] + +{ #category : 'examples' } +SpInformUserDialog class >> exampleInformUserDuring2 [ + + self new + title: 'Carefully listen'; + informUserDuring: [ + 1 second wait ] +] + +{ #category : 'examples' } +SpInformUserDialog class >> exampleModal [ + + self new + title: 'Example Progress'; + label: 'You are seeing a progress dialog! Press escape!'; + openModal +] + +{ #category : 'accessing' } +SpInformUserDialog class >> extent [ + + ^ 600@100 +] + +{ #category : 'private - actions' } +SpInformUserDialog >> afterOpenAction [ + + openAction ifNil: [ ^ self ]. + + [ + [ + openAction value. + self accept ] + on: Error + fork: [ :e | + self cancel. + e pass ]. + ] fork +] + +{ #category : 'api' } +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: [ + aBlock value ] +] + +{ #category : 'api' } +SpInformUserDialog >> informUserDuring: aBlock [ + "Inform the user with a title during an execution. + Pay attention in this method the block is expecting no argument while in the subclass + it expects the progress bar. + Check examples on the class side" + openAction := aBlock. + self openModal. + parentWindow ifNotNil: [ + parentWindow takeKeyboardFocus ] +] + +{ #category : 'initialization' } +SpInformUserDialog >> initialize [ + + super initialize. + self title: 'Listen User'. + +] + +{ #category : 'initialization' } +SpInformUserDialog >> initializeDialogWindow: aDialogWindowPresenter [ + + aDialogWindowPresenter whenOpenedDo: [ self afterOpenAction ]. + + self parentWindow + ifNotNil: [ :w | aDialogWindowPresenter centeredRelativeTo: w ] + ifNil: [ aDialogWindowPresenter centered ] +] + +{ #category : 'initialization' } +SpInformUserDialog >> initializePresenters [ + + self layout: (SpBoxLayout newTopToBottom + borderWidth: 5; + add: (label := self newLabel) expand: false; + yourself) +] + +{ #category : 'initialization' } +SpInformUserDialog >> initializeWindow: aWindowPresenter [ + + aWindowPresenter + title: self title; + initialExtent: self class extent +] + +{ #category : 'api' } +SpInformUserDialog >> label [ + + ^ label label +] + +{ #category : 'api' } +SpInformUserDialog >> label: aString [ + + label label: aString +] + +{ #category : 'initialization' } +SpInformUserDialog >> reset [ + + self label: ''. + +] + +{ #category : 'api' } +SpInformUserDialog >> title [ + + ^ title +] + +{ #category : 'api' } +SpInformUserDialog >> title: aString [ + + title := aString +] diff --git a/src/Spec2-Dialogs/SpNotificationCenterPresenter.class.st b/src/Spec2-Dialogs/SpNotificationCenterPresenter.class.st index b0b9d5f5..e2828556 100644 --- a/src/Spec2-Dialogs/SpNotificationCenterPresenter.class.st +++ b/src/Spec2-Dialogs/SpNotificationCenterPresenter.class.st @@ -1,15 +1,16 @@ Class { - #name : #SpNotificationCenterPresenter, - #superclass : #SpPresenterWithModel, + #name : 'SpNotificationCenterPresenter', + #superclass : 'SpPresenterWithModel', #instVars : [ 'itemList', 'descriptionText', 'clearButton' ], - #category : #'Spec2-Dialogs' + #category : 'Spec2-Dialogs', + #package : 'Spec2-Dialogs' } -{ #category : #examples } +{ #category : 'examples' } SpNotificationCenterPresenter class >> example2 [ @@ -21,14 +22,14 @@ SpNotificationCenterPresenter class >> example2 [ "1 to: 10 do: [ :each | app notify: each printString ]" ] -{ #category : #initialization } +{ #category : 'initialization' } SpNotificationCenterPresenter >> clearNotificationsAction [ itemList items: OrderedCollection new. descriptionText text: ' No notification ' ] -{ #category : #initialization } +{ #category : 'initialization' } SpNotificationCenterPresenter >> connectPresenters [ "Why this is not working @@ -38,7 +39,7 @@ SpNotificationCenterPresenter >> connectPresenters [ ] -{ #category : #layout } +{ #category : 'layout' } SpNotificationCenterPresenter >> defaultLayout [ | upperLayout lowerLayout | @@ -56,7 +57,7 @@ SpNotificationCenterPresenter >> defaultLayout [ yourself ] -{ #category : #initialization } +{ #category : 'initialization' } SpNotificationCenterPresenter >> initializePresenters [ itemList := self newList @@ -70,20 +71,20 @@ SpNotificationCenterPresenter >> initializePresenters [ yourself ] -{ #category : #initialization } +{ #category : 'initialization' } SpNotificationCenterPresenter >> initializeWindow: aWindowPresenter [ aWindowPresenter title: 'Notifications' ] -{ #category : #initialization } +{ #category : 'initialization' } SpNotificationCenterPresenter >> modelChanged [ itemList items: announcingObject value items. itemList selectFirst ] -{ #category : #updating } +{ #category : 'updating' } SpNotificationCenterPresenter >> updatePresenter [ self modelChanged diff --git a/src/Spec2-Dialogs/SpProgressDialog.class.st b/src/Spec2-Dialogs/SpProgressDialog.class.st index e3dd4448..5997d79e 100644 --- a/src/Spec2-Dialogs/SpProgressDialog.class.st +++ b/src/Spec2-Dialogs/SpProgressDialog.class.st @@ -1,15 +1,12 @@ " -A dialog to show a message and a progress bar. +I'm a simple form showing a dialog with progress bar during a task proceeds. +The task can control the progress. " Class { #name : 'SpProgressDialog', - #superclass : 'SpDialogPresenter', + #superclass : 'SpInformUserDialog', #instVars : [ - 'title', - 'label', - 'progressBar', - 'maxValue', - 'openAction' + 'maxValue' ], #category : 'Spec2-Dialogs', #package : 'Spec2-Dialogs' @@ -21,16 +18,6 @@ SpProgressDialog class >> documentFactoryMethodSelector [ ^ #newProgress ] -{ #category : 'examples' } -SpProgressDialog class >> example [ - - self new - title: 'Example Progress'; - label: 'You are seeing a progress dialog!'; - progressPercent: 30; - openDialog -] - { #category : 'examples' } SpProgressDialog class >> exampleInformUserDuring [ @@ -45,19 +32,21 @@ SpProgressDialog class >> exampleInformUserDuring [ ] { #category : 'examples' } -SpProgressDialog class >> exampleModal [ +SpProgressDialog class >> exampleInformUserDuring2 [ self new title: 'Example Progress'; - label: 'You are seeing a progress dialog!'; - progressPercent: 30; - openModal + informUserDuring: [ :bar | + 1 second wait ] ] -{ #category : 'accessing' } -SpProgressDialog class >> extent [ +{ #category : 'examples' } +SpProgressDialog class >> exampleModal [ - ^ 600@100 + self new + title: 'Example Progress'; + label: 'You are seeing a progress dialog!'; + openModal ] { #category : 'private - actions' } @@ -78,21 +67,14 @@ SpProgressDialog >> afterOpenAction [ { #category : 'api' } SpProgressDialog >> informUser: aString during: aBlock [ - + "Pay attention that the aBlock argument does not expect an argument representing the bar. + Check class side example." + self informUserDuring: [ :bar | bar label: aString. aBlock value ] ] -{ #category : 'api' } -SpProgressDialog >> informUserDuring: aBlock [ - - openAction := aBlock. - self openModal. - parentWindow ifNotNil: [ - parentWindow takeKeyboardFocus ] -] - { #category : 'initialization' } SpProgressDialog >> initialize [ @@ -121,27 +103,7 @@ SpProgressDialog >> initializePresenters [ yourself) ] -{ #category : 'initialization' } -SpProgressDialog >> initializeWindow: aWindowPresenter [ - - aWindowPresenter - title: self title; - initialExtent: self class extent -] - -{ #category : 'api' } -SpProgressDialog >> label [ - - ^ label label -] - -{ #category : 'api' } -SpProgressDialog >> label: aString [ - - label label: aString -] - -{ #category : 'compatibility' } +{ #category : 'accessing' } SpProgressDialog >> max: aNumber [ "sets the maximum value. Affects how #value: is calculated" @@ -149,19 +111,13 @@ SpProgressDialog >> max: aNumber [ maxValue := aNumber asFloat ] -{ #category : 'api' } -SpProgressDialog >> progress [ - - ^ progressBar value -] - -{ #category : 'api' } +{ #category : 'progress' } SpProgressDialog >> progress: aFraction [ progressBar fixedAt: aFraction ] -{ #category : 'api' } +{ #category : 'progress' } SpProgressDialog >> progressPercent: aNumber [ progressBar fixedPercentage: aNumber asFloat floor @@ -175,27 +131,3 @@ SpProgressDialog >> reset [ self progress: 0.0. ] - -{ #category : 'api' } -SpProgressDialog >> title [ - - ^ title -] - -{ #category : 'api' } -SpProgressDialog >> title: aString [ - - title := aString -] - -{ #category : 'compatibility' } -SpProgressDialog >> value [ - - ^ self progress -] - -{ #category : 'compatibility' } -SpProgressDialog >> value: aFraction [ - - self progress: (aFraction / maxValue) asFloat -]