From 215425274374e02232f27584f0bc8bb4cb3ff9c6 Mon Sep 17 00:00:00 2001 From: Pablo Tesone Date: Wed, 20 Mar 2024 12:17:45 +0100 Subject: [PATCH 1/2] - Organizing the creation of presenters. - Fixing the removal of categories. - Enabling or disabling buttons if needed --- .../StCritiqueRuleSelectorPresenter.class.st | 100 ++++++++++-------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st b/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st index 4a32fb769..24054e11f 100644 --- a/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st +++ b/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st @@ -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 @@ -174,7 +145,7 @@ StCritiqueRuleSelectorPresenter >> initializeButtonBar [ expand: false ] -{ #category : 'adding' } +{ #category : 'initialization' } StCritiqueRuleSelectorPresenter >> initializeButtons [ addButton := self newButton @@ -202,7 +173,7 @@ StCritiqueRuleSelectorPresenter >> initializeButtons [ yourself ] -{ #category : 'adding' } +{ #category : 'initialization' } StCritiqueRuleSelectorPresenter >> initializeLayout [ self layout: (SpBoxLayout newTopToBottom @@ -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. @@ -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' } @@ -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 @@ -401,6 +390,23 @@ 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. + removeAllButton enabled: shouldBeEnabled + + +] + { #category : 'adding' } StCritiqueRuleSelectorPresenter >> updateTree [ From a7e07f85751c3226b7feb6e22bac04aad3108cef Mon Sep 17 00:00:00 2001 From: Pablo Tesone Date: Thu, 21 Mar 2024 09:23:16 +0100 Subject: [PATCH 2/2] - Fixing tests --- .../StCritiqueRuleSelectorPresenterTest.class.st | 1 - .../StCritiqueRuleSelectorPresenter.class.st | 1 - 2 files changed, 2 deletions(-) diff --git a/src/NewTools-CodeCritiques-Tests/StCritiqueRuleSelectorPresenterTest.class.st b/src/NewTools-CodeCritiques-Tests/StCritiqueRuleSelectorPresenterTest.class.st index 7e66523bc..3e560432b 100644 --- a/src/NewTools-CodeCritiques-Tests/StCritiqueRuleSelectorPresenterTest.class.st +++ b/src/NewTools-CodeCritiques-Tests/StCritiqueRuleSelectorPresenterTest.class.st @@ -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 ] diff --git a/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st b/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st index 24054e11f..9eaa428da 100644 --- a/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st +++ b/src/NewTools-CodeCritiques/StCritiqueRuleSelectorPresenter.class.st @@ -402,7 +402,6 @@ StCritiqueRuleSelectorPresenter >> updateButtonsState: aSelection [ ifFalse: [ true ] ]. removeButton enabled: shouldBeEnabled. - removeAllButton enabled: shouldBeEnabled ]