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

fix-critics-browser-issue #724

Merged
merged 3 commits into from
Mar 21, 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 @@ -108,7 +108,6 @@ StCritiqueRuleSelectorPresenterTest >> testRemoveSelectedComposite [
rulesSelectorPresenter items: rulesByGroup.
rulesSelectorPresenter selectedList selectPath:
(rulesSelectorPresenter selectedList pathIndexOf: styleGroup).
rulesSelectorPresenter selectedRules: styleRules.
rulesSelectorPresenter removeButton click.
self assert: rulesSelectorPresenter selectedRules isEmpty
]
Expand Down
99 changes: 52 additions & 47 deletions src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,6 @@ StCritiqueRuleSelectorPresenter >> groupRules [
]

{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initialize [

| wrappingBlock selectedRulesChildrenBlock rulesToSelectChildrenBlock |
super initialize.
self initializeList.
self initializeSelectedList.
selectedRules := Set new.
selectedRulesChildrenBlock := [ :rule |
rule isComposite
ifTrue: [
rule rules select: [ :r |
(self isSelected: r) or: [
r isComposite ] ] ]
ifFalse: [ #( ) ] ].
rulesToSelectChildrenBlock := [ :rule |
rule isComposite
ifTrue: [
rule rules select: [ :r |
(self isSelected: r) not or: [
r isComposite ] ] ]
ifFalse: [ #( ) ] ].
list children: rulesToSelectChildrenBlock.
selectedList children: selectedRulesChildrenBlock.
wrappingBlock := [ :rule | rule name ].
list display: wrappingBlock.
selectedList display: wrappingBlock
]

{ #category : 'adding' }
StCritiqueRuleSelectorPresenter >> initializeButtonBar [

buttonBar
Expand All @@ -174,7 +145,7 @@ StCritiqueRuleSelectorPresenter >> initializeButtonBar [
expand: false
]

{ #category : 'adding' }
{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initializeButtons [

addButton := self newButton
Expand Down Expand Up @@ -202,7 +173,7 @@ StCritiqueRuleSelectorPresenter >> initializeButtons [
yourself
]

{ #category : 'adding' }
{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initializeLayout [

self layout: (SpBoxLayout newTopToBottom
Expand All @@ -225,24 +196,26 @@ StCritiqueRuleSelectorPresenter >> initializeLayout [
yourself)
]

{ #category : 'adding' }
{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initializeList [

| rulesToSelectChildrenBlock |

list := self instantiate: SpTreePresenter.
removeButton := self newButton
addStyle: 'small';
label: '<';
action: [ self removeSelected ];
yourself.

removeAllButton := self newButton
addStyle: 'small';
label: '<<';
action: [ self removeAll ];
yourself
rulesToSelectChildrenBlock := [ :rule |
rule isComposite
ifTrue: [
rule rules select: [ :r |
(self isSelected: r) not or: [
r isComposite ] ] ]
ifFalse: [ #( ) ] ].
list children: rulesToSelectChildrenBlock.
list display: [ :rule | rule name ].

]

{ #category : 'adding' }
{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initializeNextButton [

nextButton := self newButton.
Expand All @@ -264,10 +237,26 @@ StCritiqueRuleSelectorPresenter >> initializePresenters [
self initializeNextButton
]

{ #category : 'adding' }
{ #category : 'initialization' }
StCritiqueRuleSelectorPresenter >> initializeSelectedList [

selectedList := self instantiate: SpTreePresenter
| selectedRulesChildrenBlock |
selectedList := self instantiate: SpTreePresenter.

selectedRules := Set new.
selectedRulesChildrenBlock := [ :rule |
rule isComposite
ifTrue: [
rule rules select: [ :r |
(self isSelected: r) or: [
r isComposite ] ] ]
ifFalse: [ #( ) ] ].

selectedList children: selectedRulesChildrenBlock.
selectedList display: [ :rule | rule name ].

selectedList whenSelectionChangedDo: [ :aSelection |
self updateButtonsState: aSelection ].
]

{ #category : 'initialization' }
Expand Down Expand Up @@ -350,8 +339,8 @@ StCritiqueRuleSelectorPresenter >> removeButton [
StCritiqueRuleSelectorPresenter >> removeSelected [

selectedList selectedItem ifNotNil: [ :item |
(self groupRules includes: item name)
ifTrue: [ selectedRules removeAll: item rules ]
item isComposite
ifTrue: [ selectedRules removeAllFoundIn: item rules ]
ifFalse: [ selectedRules remove: item ] ].
self update.
nextButton enabled: selectedRules isNotEmpty
Expand Down Expand Up @@ -401,6 +390,22 @@ StCritiqueRuleSelectorPresenter >> setModelBeforeInitialization: aCollection [
methodName := aCollection third
]

{ #category : 'updating' }
StCritiqueRuleSelectorPresenter >> updateButtonsState: aSelection [

| shouldBeEnabled |

shouldBeEnabled := aSelection isEmpty
ifTrue: [ false ]
ifFalse: [ aSelection selectedItem isComposite
ifTrue: [ aSelection selectedItem rules anySatisfy: [:e | self isSelected: e ] ]
ifFalse: [ true ] ].

removeButton enabled: shouldBeEnabled.


]

{ #category : 'adding' }
StCritiqueRuleSelectorPresenter >> updateTree [

Expand Down
Loading