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

last changes (on Job lists, mostly) #1512

Merged
merged 18 commits into from
Jan 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ SpAbstractMorphicAdapter >> type: aString [
SpAbstractMorphicAdapter >> unsubscribe [

super unsubscribe.

self presenter hasAnnouncer ifFalse: [ ^ self ].
self presenter announcer
unsubscribe: self widget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ SpFixedProgressBarState >> customizeMorphicBar: aProgressBarMorph [
{ #category : '*Spec2-Adapters-Morphic' }
SpFixedProgressBarState >> customizeMorphicLabel: aLabelMorph [

aLabelMorph contents: (self value * 100) asInteger asString, '%'
aLabelMorph contents: ((self value * 100) asInteger min: 100) asString, '%'
]
14 changes: 8 additions & 6 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ SpMorphicBoxAdapter >> newWrapMorph [

{ #category : 'accessing' }
SpMorphicBoxAdapter >> remove: aPresenter [
| morph adapter |

aPresenter adapter ifNotNil: [ :adapter |
| morph |
morph := adapter widget.
startPanel removeMorph: morph.
endPanel removeMorph: morph.
self verifyBoxExtent ]
(adapter := aPresenter adapter) ifNil: [ ^ self ].

adapter unsubscribe.
morph := adapter widget.
startPanel removeMorph: morph.
endPanel removeMorph: morph.
self verifyBoxExtent
]

{ #category : 'accessing' }
Expand Down
13 changes: 13 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxLayoutCalculator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ SpMorphicBoxLayoutCalculator class >> newProperties: anObject [
{ #category : 'calculating' }
SpMorphicBoxLayoutCalculator >> calculateFor: aMorph in: newBounds [

[ self doCalculateFor: aMorph in: newBounds ]
ensure: [ self cleanUp ]
]

{ #category : 'private' }
SpMorphicBoxLayoutCalculator >> cleanUp [

firstCell := lastCell := nil
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculator >> doCalculateFor: aMorph in: newBounds [

self subclassResponsibility
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SpMorphicBoxLayoutCalculatorLeftToRight >> calculateCellFor: aMorph [
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculatorLeftToRight >> calculateFor: aMorph in: newBounds [
SpMorphicBoxLayoutCalculatorLeftToRight >> doCalculateFor: aMorph in: newBounds [
"An optimized left-to-right list layout"
| inset extent posX posY centering extraPerCell cell amount last submorphs |

Expand Down Expand Up @@ -126,6 +126,5 @@ SpMorphicBoxLayoutCalculatorLeftToRight >> calculateFor: aMorph in: newBounds [
width := width + amount ].
cell target layoutInBounds: (posX @ posY extent: width @ height).
posX := posX + width + inset.
cell := cell nextCell ].

cell := cell nextCell ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateCellFor: aMorph [
]

{ #category : 'calculating' }
SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
SpMorphicBoxLayoutCalculatorTopToBottom >> doCalculateFor: aMorph in: newBounds [
"An optimized top-to-bottom list layout"
| inset extent posX posY centering extraPerCell cell amount last submorphs |

Expand Down Expand Up @@ -107,7 +107,7 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
number := 0.
extra := last := 0.
cell := firstCell.
[cell == nil] whileFalse:[
[ cell == nil ] whileFalse:[
number := number + 1.
height := cell cellSize.
(extraPerCell > 0 and:[cell vSpaceFill]) ifTrue:[
Expand All @@ -117,6 +117,5 @@ SpMorphicBoxLayoutCalculatorTopToBottom >> calculateFor: aMorph in: newBounds [
].
cell target layoutInBounds: (posX @ posY extent: width @ height).
posY := posY + height + inset.
cell := cell nextCell.
].
cell := cell nextCell ]
]
42 changes: 31 additions & 11 deletions src/Spec2-Adapters-Morphic/SpMorphicProgressBarAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ SpMorphicProgressBarAdapter >> buildWidget [
vResizing: #spaceFill;
yourself.

progressLabel := LabelMorph new.

progressBar := (self progressBarState progressBarMorph from: 0 to: 1)
"changeProportionalLayout;"
hResizing: #spaceFill;
vResizing: #rigid;
height: 5;
progressLabel := LabelMorph new
contents: '';
yourself.

self progressBarState customizeMorphicBar: progressBar.
progressBar := self newProgressBar.

panel
addMorphBack: progressLabel;
Expand Down Expand Up @@ -86,6 +81,17 @@ SpMorphicProgressBarAdapter >> labelStyle [
otherStyles: self presenterStyles
]

{ #category : 'factory' }
SpMorphicProgressBarAdapter >> newProgressBar [

^ (self progressBarState progressBarMorph from: 0 to: 1)
hResizing: #spaceFill;
vResizing: #rigid;
height: 5;
in: [ :this | self progressBarState customizeMorphicBar: this ];
yourself
]

{ #category : 'accessing' }
SpMorphicProgressBarAdapter >> progressBarState [

Expand All @@ -95,14 +101,28 @@ SpMorphicProgressBarAdapter >> progressBarState [
{ #category : 'accessing' }
SpMorphicProgressBarAdapter >> refreshRateInMs: nbMilliSeconds [
"The progress bar will only be updated if the time between 2 refresh is > nbMilliSeconds"
refreshRateInMs := nbMilliSeconds.
refreshRateInMs := nbMilliSeconds
]

{ #category : 'updating' }
SpMorphicProgressBarAdapter >> updateState [
SpMorphicProgressBarAdapter >> updateProgressBar [
| newProgressBar |

newProgressBar := self newProgressBar.
self widget
replaceSubmorph: progressBar
by: newProgressBar.
progressBar := newProgressBar
]

{ #category : 'updating' }
SpMorphicProgressBarAdapter >> updateState [
| isTimeForRefresh |
self progressBarState

(self progressBarState progressBarMorph = progressBar class)
ifFalse: [ self updateProgressBar ].

self progressBarState
customizeMorphicLabel: progressLabel;
customizeMorphicBar: progressBar.

Expand Down
16 changes: 9 additions & 7 deletions src/Spec2-Adapters-Morphic/SpMorphicWindowAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ SpMorphicWindowAdapter >> delete [
self application windowClosed: self ]
]

{ #category : 'protocol' }
SpMorphicWindowAdapter >> extent: aPoint [

^ self widget extent: aPoint
]

{ #category : 'widget API' }
SpMorphicWindowAdapter >> initialExtent [

Expand Down Expand Up @@ -190,6 +184,12 @@ SpMorphicWindowAdapter >> minimize [
self widgetDo: [ :w | w minimize ]
]

{ #category : 'protocol' }
SpMorphicWindowAdapter >> moveTo: aPoint [

^ self widget position: aPoint
]

{ #category : 'widget API' }
SpMorphicWindowAdapter >> okToChange [

Expand Down Expand Up @@ -231,7 +231,9 @@ SpMorphicWindowAdapter >> rebuildWithSpecLayout: aSpec [
{ #category : 'widget API' }
SpMorphicWindowAdapter >> resize: aPoint [

widget extent: aPoint
widget extent: aPoint.
self presenter isCentered
ifTrue: [ self centered ]
]

{ #category : 'factory' }
Expand Down
6 changes: 6 additions & 0 deletions src/Spec2-Core/SpApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
47 changes: 33 additions & 14 deletions src/Spec2-Core/SpJob.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ job := self newBlock: [ :job |
progress: (0.1 * each);
title: 'Youpi ', each printString.
(Delay forMilliseconds: 100) wait.
] ]
] ].
job run.
```

Expand Down Expand Up @@ -78,22 +78,33 @@ SpJob >> addChild: aJob [
aJob parent: self
]

{ #category : 'accessing' }
{ #category : 'private - announcing' }
SpJob >> announce: anAnnouncementClass [

| announcement |
announcement := anAnnouncementClass on: self.
self announcer announce: announcement
]

{ #category : 'private' }
{ #category : 'private - announcing' }
SpJob >> announceChange [

isRunning ifFalse: [ ^ self ].
self announce: JobChange
]

{ #category : 'accessing' }
{ #category : 'private - announcing' }
SpJob >> announceEnd [

self announce: JobEnd
]

{ #category : 'private - announcing' }
SpJob >> announceStart [

self announce: JobStart
]

{ #category : 'private - announcing' }
SpJob >> announcer [

^ announcer ifNil: [ announcer := Announcer new ]
Expand Down Expand Up @@ -122,7 +133,7 @@ SpJob >> cleanupAfterRunning [

isRunning := false.
process := nil.
self announce: JobEnd.
self announceEnd.
parent ifNotNil: [ :job | job removeChild: self ]
]

Expand Down Expand Up @@ -175,6 +186,12 @@ SpJob >> initialize [
children := OrderedCollection new
]

{ #category : 'instance creation' }
SpJob >> installOn: aPresenter [

announcer := aPresenter
]

{ #category : 'testing' }
SpJob >> isRunning [

Expand All @@ -201,8 +218,8 @@ SpJob >> lookup: lookupBlock ifNone: noneBlock [
(lookupBlock value: self) ifTrue: [ ^ self ].

^ parent
ifNil: noneBlock
ifNotNil: [ parent lookup: lookupBlock ifNone: noneBlock ]
ifNotNil: [ parent lookup: lookupBlock ifNone: noneBlock ]
ifNil: noneBlock
]

{ #category : 'accessing' }
Expand All @@ -221,6 +238,7 @@ SpJob >> max: aNumber [
SpJob >> migrateProgressWhileUpdatingBounds: aBlockChangingBounds [
"Keep the progress value consistent while we change min / max"
| progress |

progress := self progress.
aBlockChangingBounds value.
self progress: progress.
Expand Down Expand Up @@ -256,10 +274,10 @@ SpJob >> prepareForRunning [

isRunning := true.
process := Processor activeProcess.
self announce: JobStart
self announceStart
]

{ #category : 'progress' }
{ #category : 'accessing' }
SpJob >> progress [
"Avoid negative progress and divideByZero."

Expand All @@ -268,7 +286,7 @@ SpJob >> progress [
ifFalse: [ (currentValue - min) / (max - min) ]
]

{ #category : 'progress' }
{ #category : 'accessing' }
SpJob >> progress: aNormalizedFloat [
"Set the progress: 0.0 - 1.0"

Expand All @@ -291,10 +309,11 @@ SpJob >> removeChild: aJob [
{ #category : 'running' }
SpJob >> run [

[
^ [
self prepareForRunning.
^ block cull: self ]
ensure: [ self cleanupAfterRunning ]
block cull: self ]
ensure: [
self cleanupAfterRunning ]
]

{ #category : 'accessing' }
Expand Down
Loading
Loading