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

Update after selection in Color Picker #766

Merged
merged 2 commits into from
Jun 13, 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
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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is equivallent to just StSettingSHStyleButtonColorPresenterItem on: aSettingDeclaration, no need of the bureaucracy... and in any case is not recommended to do it like that. Which is the application that presenter belongs to?
(this still can work if you will after add that presenter to another that knows its app, or set the app, but as is, it doesn't)
The recommended way of doing this is by passing a builder (see SpPresenterBuilder)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll address the suggested changes in a new issue

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 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer real names "aColor" or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I will address the changes in a new issue.

| 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
]
Loading