From 9449ee219c32f3702afb3583b48027d9e1d937d0 Mon Sep 17 00:00:00 2001 From: Esteban Lorenzano Date: Wed, 24 Jan 2024 16:55:02 +0100 Subject: [PATCH] an attempt to run fix the pharo joblist --- src/Spec2-Core/SpApplication.class.st | 6 +++ src/Spec2-Core/SpJobListPresenter.class.st | 45 ++++++++++--------- src/Spec2-Core/SpJobPresenter.class.st | 12 ++--- .../SpProgressBarPresenter.class.st | 6 +++ src/Spec2-Dialogs/SpApplication.extension.st | 7 +-- src/Spec2-Dialogs/SpProgressDialog.class.st | 1 + src/Spec2-Layout/SpExecutableLayout.class.st | 2 +- .../SpJobListPresenterTest.class.st | 23 ++++++---- 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/Spec2-Core/SpApplication.class.st b/src/Spec2-Core/SpApplication.class.st index 12e58206..96fe2e5a 100644 --- a/src/Spec2-Core/SpApplication.class.st +++ b/src/Spec2-Core/SpApplication.class.st @@ -331,6 +331,12 @@ SpApplication >> registerWindow: aWindow [ self windows add: aWindow ] +{ #category : 'accessing - properties' } +SpApplication >> removeProperty: aName [ + + ^ self properties removeKey: aName ifAbsent: [ ] +] + { #category : 'accessing' } SpApplication >> reset [ diff --git a/src/Spec2-Core/SpJobListPresenter.class.st b/src/Spec2-Core/SpJobListPresenter.class.st index d5a6f2b0..83d5ebd8 100644 --- a/src/Spec2-Core/SpJobListPresenter.class.st +++ b/src/Spec2-Core/SpJobListPresenter.class.st @@ -14,20 +14,19 @@ Class { { #category : 'examples' } SpJobListPresenter class >> example [ - | jobList | - - jobList := self new. + [ 1 to: 5 do: [ :index | [ - jobList pushJob: (SpJob - newTitle: 'Job ', index asString + Job new + title: 'Job ', index asString; block: [ :job | job min: 1; max: 10. 1 to: 10 do: [ :i | job title: ('Test {1}/10' format: {i}). job value: i. - 250 milliSeconds wait ] ]). + 250 milliSeconds wait ] ]; + run. ] fork. 200 milliSeconds wait ] ] fork. @@ -39,12 +38,6 @@ SpJobListPresenter class >> example [ SpJobListPresenter >> addJobPresenter: aJob [ | presenter | - ('adding: {1}, {2}, max={3}, value={4}' format: { - aJob class. - aJob title. - aJob max. - aJob currentValue }) crTrace. - aJob title ifEmpty: [ aJob title: 'Processing...' ]. presenter := self instantiate: SpJobPresenter on: aJob. @@ -58,6 +51,14 @@ SpJobListPresenter >> addJobPresenter: aJob [ window resize: 500@(layout children size * self jobPresenterHeight) ] ] +{ #category : 'private' } +SpJobListPresenter >> ensureOpen [ + + self withWindowDo: [ :aWindow | + aWindow isOpen + ifFalse: [ self open ] ] +] + { #category : 'private' } SpJobListPresenter >> findJob: aJob [ @@ -82,15 +83,22 @@ SpJobListPresenter >> initializeWindow: aWindowPresenter [ centered ] +{ #category : 'testing' } +SpJobListPresenter >> isEmpty [ + + ^ self layout children isEmpty +] + { #category : 'private - events' } SpJobListPresenter >> jobChanged: ann [ - (self findJob: ann job) - ifNotNil: [ :aPresenter | aPresenter updatePresenter ] + (self findJob: ann job) ifNotNil: [ :aPresenter | + aPresenter model title crTrace. + aPresenter updatePresenter ] ] { #category : 'private - events' } -SpJobListPresenter >> jobEnd: ann [ +SpJobListPresenter >> jobEnd: ann [ self removeJobPresenter: ann job ] @@ -107,21 +115,18 @@ SpJobListPresenter >> jobStart: ann [ "Skip if already there" (self findJob: ann job) ifNotNil: [ ^ self ]. self addJobPresenter: ann job. - ann job run + self ensureOpen ] { #category : 'private' } SpJobListPresenter >> newJob [ - ^ SpJob new + ^ Job new ] { #category : 'api' } SpJobListPresenter >> pushJob: aJob [ - aJob whenStartDo: [ :ann | self addJobPresenter: ann job ]. - aJob whenEndDo: [ :ann | self removeJobPresenter: ann job ]. - aJob run ] diff --git a/src/Spec2-Core/SpJobPresenter.class.st b/src/Spec2-Core/SpJobPresenter.class.st index 3de32e5f..62dcab43 100644 --- a/src/Spec2-Core/SpJobPresenter.class.st +++ b/src/Spec2-Core/SpJobPresenter.class.st @@ -32,7 +32,7 @@ Class { SpJobPresenter class >> example [ | job | - job := SpJob newBlock: [ :aJob | + job := Job block: [ :aJob | aJob title: 'Test'. aJob min: 1; max: 10. 1 to: 10 do: [ :i | @@ -61,7 +61,7 @@ SpJobPresenter >> initializePresenters [ progressLabel := self newLabel label: ''. progressBar := self newProgressBar - indeterminate; + "indeterminate;" yourself ] @@ -128,19 +128,19 @@ SpJobPresenter >> updatePresenter [ model ifNil: [ ^ self ]. progressLabel label: model title. + "progressBar fixedAt: model progress." model progress > 0 ifTrue: [ progressBar fixedAt: model progress ] ifFalse: [ progressBar indeterminate ]. - - progressBar withAdapterDo: [ :anAdapter | anAdapter updateState ] + progressBar refresh ] { #category : 'private' } SpJobPresenter >> updateSubscriptions [ - model announcer weak + "model announcer weak when: JobStart send: #jobStart: to: self; when: JobChange send: #jobChanged: to: self; - when: JobEnd send: #jobEnd: to: self. + when: JobEnd send: #jobEnd: to: self." ] diff --git a/src/Spec2-Core/SpProgressBarPresenter.class.st b/src/Spec2-Core/SpProgressBarPresenter.class.st index 75470076..67f1cc24 100644 --- a/src/Spec2-Core/SpProgressBarPresenter.class.st +++ b/src/Spec2-Core/SpProgressBarPresenter.class.st @@ -74,6 +74,12 @@ SpProgressBarPresenter >> progress: aBlock every: aDelay [ self state: (SpProgressingProgressBarState progression: aBlock every: aDelay) ] +{ #category : 'api' } +SpProgressBarPresenter >> refresh [ + + ^ self withAdapterDo: [ :anAdapter | anAdapter updateState ] +] + { #category : 'private' } SpProgressBarPresenter >> state [ diff --git a/src/Spec2-Dialogs/SpApplication.extension.st b/src/Spec2-Dialogs/SpApplication.extension.st index 088cf3a2..def49f68 100644 --- a/src/Spec2-Dialogs/SpApplication.extension.st +++ b/src/Spec2-Dialogs/SpApplication.extension.st @@ -33,11 +33,12 @@ SpApplication >> informUser: aString during: aBlock [ result := nil. self jobList - pushJob: (SpJob - newTitle: aString + pushJob: (Job new + title: aString; block: [ :job | job min: 0; max: 100. - result := aBlock cull: job ]). + result := aBlock cull: job ]; + yourself). ^ result ] diff --git a/src/Spec2-Dialogs/SpProgressDialog.class.st b/src/Spec2-Dialogs/SpProgressDialog.class.st index 5997d79e..8d44ebce 100644 --- a/src/Spec2-Dialogs/SpProgressDialog.class.st +++ b/src/Spec2-Dialogs/SpProgressDialog.class.st @@ -5,6 +5,7 @@ The task can control the progress. Class { #name : 'SpProgressDialog', #superclass : 'SpInformUserDialog', + #classTraits : '{} + TraitedClass', #instVars : [ 'maxValue' ], diff --git a/src/Spec2-Layout/SpExecutableLayout.class.st b/src/Spec2-Layout/SpExecutableLayout.class.st index 5b143640..4e44caa8 100644 --- a/src/Spec2-Layout/SpExecutableLayout.class.st +++ b/src/Spec2-Layout/SpExecutableLayout.class.st @@ -270,7 +270,7 @@ SpExecutableLayout >> remove: aPresenter ifAbsent: aBlock [ ^ (children includesKey: aPresenter) ifTrue: [ children removeKey: aPresenter ] - ifFalse: aBlock + ifFalse: [ aBlock value ] ] { #category : 'private' } diff --git a/src/Spec2-Morphic-Tests/SpJobListPresenterTest.class.st b/src/Spec2-Morphic-Tests/SpJobListPresenterTest.class.st index 1d76cf30..155541fc 100644 --- a/src/Spec2-Morphic-Tests/SpJobListPresenterTest.class.st +++ b/src/Spec2-Morphic-Tests/SpJobListPresenterTest.class.st @@ -17,9 +17,10 @@ SpJobListPresenterTest >> testJobIsFinishedWhenWaitingMoreThanWorkBlockDuration self skipOnPharoCITestingEnvironment. progress := 0. - job := SpJob - newTitle: 'some job' - block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 20 milliSeconds wait. ] ]. + job := Job new + title: 'some job'; + block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 20 milliSeconds wait. ] ]; + yourself. [ presenter := SpJobListPresenter new pushJob: job; yourself. ] fork. @@ -35,9 +36,10 @@ SpJobListPresenterTest >> testJobIsNotFinishedWhenWaitingLessThanWorkBlockDurati self skipOnPharoCITestingEnvironment. progress := 0. - job := SpJob - newTitle: 'some job' - block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 60 milliSeconds wait. ] ]. + job := Job new + title: 'some job'; + block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 60 milliSeconds wait ] ]; + yourself. [ presenter := SpJobListPresenter new pushJob: job; yourself. ] fork. @@ -57,9 +59,12 @@ SpJobListPresenterTest >> testProgressDoesNotRefreshMoreThanRefreshRate [ refreshRateInMs := 150. nbUpdates := 25. counter := 0. - job := SpJob - newTitle: 'some job' - block: [ : myjob | 1 to: nbUpdates do: [ :i | myjob value: i * 4. waitBetweenJobUpdate wait. ] ]. + job := Job new + title: 'some job'; + block: [ : myjob | + 1 to: nbUpdates do: [ :i | + myjob value: i * 4. waitBetweenJobUpdate wait ] ]; + yourself. presenter := SpJobPresenter on: job. [ presenter open.