Skip to content

Commit

Permalink
fixed checkable to work again within group
Browse files Browse the repository at this point in the history
added radio skin
  • Loading branch information
plantec committed Jul 18, 2023
1 parent 63700a4 commit 6eb2bd0
Show file tree
Hide file tree
Showing 24 changed files with 505 additions and 315 deletions.
28 changes: 27 additions & 1 deletion src/Toplo-Tests/ToCheckableGroupTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ ToCheckableGroupTest >> testCheckableGroupWithDresserChangeAndSwitchToNextStateU
self assert: buttons third checked
]

{ #category : #tests }
ToCheckableGroupTest >> testCheckableGroupWithIndeterminateRaiseError [

| group |
group := ToCheckableGroup new.
1 to: 4 do: [ :idx |
| chb |
chb := ToCheckbox new.
group add: chb ].
self should: [ group buttons first withIndeterminate: true ] raise: Error
]

{ #category : #tests }
ToCheckableGroupTest >> testCheckableGroupWithIndeterminateRaiseError2 [

| group btn |
btn := ToCheckbox new.
btn withIndeterminate: true.
group := ToCheckableGroup new.
self should: [ group add: btn ] raise: Error

]

{ #category : #tests }
ToCheckableGroupTest >> testCheckableGroupWithOnePreCheckedButton [

Expand All @@ -196,7 +219,10 @@ ToCheckableGroupTest >> testCheckableGroupWithStartDefault [
group add: chb ].
group buttons second checked: true.
self assert: group checkedButtons size equals: 1.
self assert: group buttons second checked.
self assert: group buttons second isChecked.
self assert: group buttons first isUnchecked.
self assert: group buttons third isUnchecked.
self assert: group buttons fourth isUnchecked.
self assert: group uncheckedButtons size equals: group buttons size - 1
]

Expand Down
30 changes: 7 additions & 23 deletions src/Toplo-Tests/ToCheckboxTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ Class {
{ #category : #tests }
ToCheckboxTest >> testCheckUncheckStates [

| cb s |
| cb |
cb := ToCheckbox new.
s := cb stateNamed: #checked.
self assert: s name equals: #checked.
s := cb stateNamed: #unchecked.
self assert: s name equals: #unchecked
self assert: cb checked not.
cb checked: true.
self assert: cb checked
]

{ #category : #tests }
ToCheckboxTest >> testIndeterminateState [

| cb s |
| cb |
cb := ToCheckbox new.
self should: [ s := cb stateNamed: #indeterminate ] raise: Error.
cb withIndeterminate.
s := cb stateNamed: #indeterminate.
self assert: s name equals: #indeterminate
cb checked: nil.
self assert: cb isIndeterminate
]

{ #category : #tests }
Expand All @@ -38,19 +35,6 @@ ToCheckboxTest >> testStartChecked [

]

{ #category : #tests }
ToCheckboxTest >> testStartIndeterminate [

| cb space |
cb := ToCheckbox new.
self should: [ cb startIndeterminate ] raise: Error.
cb withIndeterminate.
cb startIndeterminate.
space := cb openInSpace.
self assert: cb isIndeterminate.
cb when: BlElementAddedToSceneGraphEvent do: [ space close ]
]

{ #category : #tests }
ToCheckboxTest >> testStartUnchecked [

Expand Down
95 changes: 65 additions & 30 deletions src/Toplo/TToCheckable.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ Trait {
#name : #TToCheckable,
#instVars : [
'#group',
'#checked => ObservableSlot'
'#checked => ObservableSlot',
'#withIndeterminate'
],
#category : #'Toplo-Widget-Button'
}

{ #category : #'t - toggle group' }
{ #category : #'t - checkable group' }
TToCheckable >> addToGroup: aToggleGroup [

aToggleGroup add: self.
Expand All @@ -17,18 +18,7 @@ TToCheckable >> addToGroup: aToggleGroup [
{ #category : #'t - checkable protocol' }
TToCheckable >> check [

self group ifNotNil: [ :g |
g checked: self.
^ self ].
self privateCheck
]

{ #category : #'t - checkable protocol' }
TToCheckable >> check: aBoolean [

aBoolean
ifTrue: [ self check ]
ifFalse: [ self uncheck ]
self checked: true
]

{ #category : #'t - checkable protocol' }
Expand All @@ -38,55 +28,85 @@ TToCheckable >> checked [
]

{ #category : #'t - checkable protocol' }
TToCheckable >> checked: aBoolean [

checked = aBoolean ifTrue: [ ^ self ].
checked := aBoolean
TToCheckable >> checked: aBooleanOrNil [
" change the checkable state. nil means indeterminate. "

checked = aBooleanOrNil ifTrue: [ ^ self ].
" aBoolean can be nil for indeterminate "
(aBooleanOrNil notNil and: [ self group notNil ]) ifTrue: [ " ask the group for checking/unchecking "
^ aBooleanOrNil
ifTrue: [ self group checked: self ]
ifFalse: [ self group unchecked: self ] ].
self privateChecked: aBooleanOrNil
]

{ #category : #'t - toggle group' }
{ #category : #'t - checkable group' }
TToCheckable >> group [

^ group
]

{ #category : #'t - toggle group' }
TToCheckable >> group: aToggleGroup [
{ #category : #'t - checkable group' }
TToCheckable >> group: aCheckableGroup [

self withIndeterminate ifTrue: [
Error signal:
'Invalid checkable use: indeterminate state is not allowed with a checkable group' ].

group := aToggleGroup
group := aCheckableGroup
]

{ #category : #'t - checkable initializing' }
TToCheckable >> initializeCheckable [

checked := false.
self whenCheckedChangedDo: [ :new :prev | self dispatchEvent: (ToCheckableCheckEvent current: new previous: prev) ]
withIndeterminate := false.
self whenCheckedChangedDo: [ :new :prev |
self dispatchEvent: (ToCheckableCheckEvent current: new previous: prev) ]
]

{ #category : #'t - checkable protocol' }
TToCheckable >> isChecked [

^ checked = true
]

{ #category : #'t - checkable protocol' }
TToCheckable >> isIndeterminate [

^ checked isNil
]

{ #category : #'t - checkable protocol' }
TToCheckable >> privateCheck [
TToCheckable >> isUnchecked [

checked := true
^ checked = false
]

{ #category : #'t - checkable protocol' }
TToCheckable >> privateUncheck [
TToCheckable >> privateChecked: aBooleanOrNil [

checked := false
checked := aBooleanOrNil
]

{ #category : #'t - toggle group' }
{ #category : #'t - checkable group' }
TToCheckable >> removeFromGroup [

self group remove: self
]

{ #category : #'t - checkable protocol' }
TToCheckable >> switchToNextState [

(self withIndeterminate and: [ self isUnchecked ]) ifTrue: [ ^ self checked: nil ].
self isIndeterminate ifTrue: [ ^ self checked: true ].
self checked: self checked not
]

{ #category : #'t - checkable protocol' }
TToCheckable >> uncheck [

self group ifNotNil: [ :g | g unchecked: self. ^ self ].
self privateUncheck
self checked: false
]

{ #category : #'t - change hook' }
Expand All @@ -96,3 +116,18 @@ TToCheckable >> whenCheckedChangedDo: aBlock [

self property: #checked whenChangedDo: aBlock
]

{ #category : #'t - checkable protocol' }
TToCheckable >> withIndeterminate [

^ withIndeterminate
]

{ #category : #'t - checkable protocol' }
TToCheckable >> withIndeterminate: aBoolean [

self group ifNotNil: [
Error signal:
'Invalid checkable use: indeterminate state is not allowed with a checkable group' ].
withIndeterminate := aBoolean
]
Loading

0 comments on commit 6eb2bd0

Please sign in to comment.