Skip to content

Commit

Permalink
Merge pull request #766 from hernanmd/fix_st_browser_color_update
Browse files Browse the repository at this point in the history
Update after selection in Color Picker
  • Loading branch information
Ducasse authored Jun 13, 2024
2 parents 48ba042 + ea67a23 commit 61dba20
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
17 changes: 14 additions & 3 deletions src/NewTools-SettingsBrowser/Color.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ Extension { #name : 'Color' }
{ #category : '*NewTools-SettingsBrowser' }
Color >> asSettingPresenter: aSettingDeclaration [

^ (StSettingSHStyleButtonColorPresenterItem on: aSettingDeclaration)
buttonAction: [ aSettingDeclaration getColor ];
whenColorChangedDo: [ self updateColor: aSettingDeclaration color ];
| settingPresenter colorValue |

colorValue := aSettingDeclaration targetSelector
ifNil: [ aSettingDeclaration realTarget perform: aSettingDeclaration name ]
ifNotNil: [
| settingsTarget |
settingsTarget := aSettingDeclaration realTarget perform: aSettingDeclaration targetSelector.
settingsTarget perform: aSettingDeclaration getSelector ].

settingPresenter := (SpPresenter new instantiate: StSettingSHStyleButtonColorPresenterItem on: aSettingDeclaration).
settingPresenter
buttonAction: [ aSettingDeclaration getColorFor: settingPresenter ];
buttonColor: colorValue;
yourself.
^ settingPresenter
]
16 changes: 9 additions & 7 deletions src/NewTools-SettingsBrowser/SettingDeclaration.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ SettingDeclaration >> asSettingPresenter [
]

{ #category : '*NewTools-SettingsBrowser' }
SettingDeclaration >> getColor [
SettingDeclaration >> getColorFor: aPresenter [

(SpPresenter new instantiate: SpColorPickerWindow on: self)
whenColorChangedDo: [ : c |
| colorPickerPresenter |

colorPickerPresenter := aPresenter instantiate: SpColorPickerWindow on: self.
colorPickerPresenter
whenChangedDo: [ : c |
| changedAspect |
"First we need to get the setter selector, then apply it"
"Some settings are built 'customized' configuring its setter in a different way than using #targetSelector (see #customSettingsOn:)"
self targetSelector
ifNil: [
self realTarget perform: self name asMutator with: c.
self realTarget perform: self name asMutator with: c value.
changedAspect := self realTarget ]
ifNotNil: [
changedAspect := self realTarget perform: self targetSelector.
changedAspect perform: self setSelector with: c. ].

self announcer announce: (StSettingsChanged new aspect: changedAspect value: c) ];
changedAspect perform: self setSelector with: c value. ].
aPresenter updateColor: c value ];
open
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,5 @@ StSettingSHStyleButtonColorPresenterItem >> buttonColor: aColor [
{ #category : 'initialization' }
StSettingSHStyleButtonColorPresenterItem >> updateColor: aColor [

]

{ #category : 'enumerating' }
StSettingSHStyleButtonColorPresenterItem >> whenColorChangedDo: aBlock [
"Inform when presenter has been displayed.
`aBlock` receives one argument
- an announcement (instance of `SpWidgetDisplayed`)"

self announcer
when: StSettingsChanged
do: aBlock
for: aBlock receiver
self buttonColor: aColor.
]
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,3 @@ StSettingSectionPresenter >> defaultLayout [
yourself);
yourself
]

{ #category : 'initialization' }
StSettingSectionPresenter >> initializePresenters [

super initializePresenters.
self layout: self defaultLayout.
]
6 changes: 6 additions & 0 deletions src/NewTools-SettingsBrowser/StSettingsChanged.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ StSettingsChanged >> aspect: aThemeSettings value: aColor [
setting := aThemeSettings.
value := aColor.
]

{ #category : 'evaluating' }
StSettingsChanged >> value [

^ value
]

0 comments on commit 61dba20

Please sign in to comment.