Skip to content

Commit

Permalink
Merge pull request #234 from pharo-graphics/ToItemBarNodeHolderEnh
Browse files Browse the repository at this point in the history
To item bar node holder enh
  • Loading branch information
plantec authored Jan 15, 2025
2 parents d8c5799 + 6782ecc commit b5a19b1
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 102 deletions.
8 changes: 4 additions & 4 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ ToSandBox class >> barWithData: aCollection [
labelText: 'Unable/disable';
whenClickedDo: [
idxes do: [ :idx |
bar disabledSelecter switchIndexSelection: idx ] ]).
(bar nodeAt: idx) disable ] ]).
m addItem: (ToMenuItem new
labelText: 'Unselectable';
whenClickedDo: [
Expand Down Expand Up @@ -6991,9 +6991,9 @@ ToSandBox class >> listWithEditableAndContextMenu [
selectionMenu addItem: (ToMenuItem new
labelText: 'Enable/Disable';
whenClickedDo: [ :event |
indexes do: [ :idx |
target disabledSelecter switchIndexSelection:
idx ] ];
indexes do: [ :idx | | di |
di := (l nodeAt: idx) isDisabled.
(l nodeAt: idx) disabled: di not ] ];
yourself).
selectionMenu addItem: (ToMenuItem new
labelText: 'Set unselectable';
Expand Down
4 changes: 2 additions & 2 deletions src/Toplo-Widget-Album/ToLabelSkin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
ToLabelSkin >> deselectedSkinEvent: anEvent [

super deselectedSkinEvent: anEvent.
anEvent elementDo: [ :e |
anEvent enabledElementDo: [ :e |
| to |
to := e valueOfTokenNamed: #'color-text'.
e foreground: to ]
Expand Down Expand Up @@ -48,7 +48,7 @@ ToLabelSkin >> installSkinEvent: anEvent [
ToLabelSkin >> selectedSkinEvent: anEvent [

super selectedSkinEvent: anEvent.
anEvent elementDo: [ :e |
anEvent enabledElementDo: [ :e |
| tokname to |
tokname := anEvent focused
ifTrue: [ #'label-selected-focused' ]
Expand Down
8 changes: 4 additions & 4 deletions src/Toplo-Widget-List-Tests/ToItemBarElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ToItemBarElementTest >> testDisableItemAfterAdding [
self assert: item positionInBar equals: 1.
self assert: (l disabledSelectionModel containsIndex: item positionInBar).
self assert: item isDisabled.
self deny: n isDisabled.
self assert: n isDisabled.


]
Expand Down Expand Up @@ -95,7 +95,7 @@ ToItemBarElementTest >> testDisableItemAfterAdding2 [
self assert: n item positionInBar equals: 2.
self assert: (l disabledSelectionModel containsIndex: n item positionInBar).
self assert: n item isDisabled.
self deny: n isDisabled.
self assert: n isDisabled.

n := l nodes third.
self assert: n item positionInBar equals: 3.
Expand Down Expand Up @@ -124,7 +124,7 @@ ToItemBarElementTest >> testDisableItemBeforeAdding [
self assert: item positionInBar equals: 1.
self assert: (l disabledSelectionModel containsIndex: item positionInBar).
self assert: item isDisabled.
self deny: n isDisabled.
self assert: n isDisabled.

]

Expand Down Expand Up @@ -153,7 +153,7 @@ ToItemBarElementTest >> testDisableItemBeforeAdding2 [
self assert: n item positionInBar equals: 2.
self assert: (l disabledSelectionModel containsIndex: n item positionInBar).
self assert: n item isDisabled.
self deny: n isDisabled.
self assert: n isDisabled.

n := l nodes third.
self assert: n item positionInBar equals: 3.
Expand Down
48 changes: 48 additions & 0 deletions src/Toplo-Widget-List-Tests/ToListElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ ToListElementTest >> testDataRemovedWhenNodeRemoved [
list primarySelectionMode selectionOption selectionElements isEmpty
]

{ #category : #'test selection - mode' }
ToListElementTest >> testDisable [

| l |
l := ToListElement new.
space root addChild: l.
l matchParent.
l dataAccessor addAll: { #A. #B. #C }.
l selecter selectIndex: 2.
l secondarySelecter selectIndex: 3.
self waitTestingSpaces.
self assert: l selectionModel selectedIndexes equals: { 2 }.
self assert: l secondarySelectionModel selectedIndexes equals: { 3 }.
l disable.
self waitTestingSpaces.
self assert: l isDisabled.
self assert: l selectionModel isEmpty.
self assert: l secondarySelectionModel isEmpty.
l nodesDo: [ :n | self assert: n isDisabled ]

]

{ #category : #'test selection - mode' }
ToListElementTest >> testDisabledSelectionModel [

Expand Down Expand Up @@ -200,6 +222,32 @@ ToListElementTest >> testEmptyListSelectPreviousInSelection [
self assert: l selectionModel isEmpty
]

{ #category : #'test selection - mode' }
ToListElementTest >> testEnable [

| l |
l := ToListElement new.
space root addChild: l.
l matchParent.
l dataAccessor addAll: { #A. #B. #C }.
l selecter selectIndex: 2.
l secondarySelecter selectIndex: 3.
l disable.
self waitTestingSpaces.
self assert: l isDisabled.
self assert: l selectionModel isEmpty.
self assert: l secondarySelectionModel isEmpty.
l nodesDo: [ :n | self assert: n isDisabled ].
l enable.
self assert: l isEnabled.
self assert: l selectionModel isEmpty.
self assert: l secondarySelectionModel isEmpty.
l nodesDo: [ :n | self deny: n isDisabled ].



]

{ #category : #'test selection - mode' }
ToListElementTest >> testHiddenSelectionModel [

Expand Down
18 changes: 18 additions & 0 deletions src/Toplo-Widget-List-Tests/ToSpecificListElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ ToSpecificListElementTest >> testDisabledWithTwoNodes2 [
self assert: l disabledSelecter selectedIndexes equals: { 2 }
]

{ #category : #tests }
ToSpecificListElementTest >> testDisabledWithTwoNodes3 [

l dataAccessor add: 'first'.
space root addChild: l.
self waitTestingSpaces.
self assert: l nodes size equals: 1.
self assert: l disabledSelectionModel isEmpty.
l nodes first disabled: true.
self waitTestingSpaces.
self assert: l disabledSelecter selectedIndex equals: 1.
self assert: l nodes first isDisabled.
l dataAccessor addFirst: 'second'.
self waitTestingSpaces.
self assert: l disabledSelecter selectedIndex equals: 2.
self assert: l disabledSelecter selectedIndexes equals: { 2 }
]

{ #category : #tests }
ToSpecificListElementTest >> testEmptyList [

Expand Down
77 changes: 40 additions & 37 deletions src/Toplo-Widget-List/TToItem.trait.st
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
Trait {
#name : #TToItem,
#instVars : [
'barOwner',
'barElement',
'itemConstraints'
],
#category : #'Toplo-Widget-List-ItemBar'
}

{ #category : #'t - item' }
TToItem >> barElement [

^ barElement
^ self userData at: #barElement ifAbsent: [ ]
]

{ #category : #'t - item' }
TToItem >> barElement: anItemBarElement [

barElement := anItemBarElement
self userData at: #barElement put: anItemBarElement
]

{ #category : #'t - item' }
TToItem >> barElementDo: aBlock [

barElement ifNil: [ ^ self ].
aBlock value: barElement
self barElement ifNotNil: [ :be | aBlock value: be ]
]

{ #category : #'t - item' }
TToItem >> barOwner [

^ barOwner
^ self userData at: #barOwner ifAbsent: [ ]
]

{ #category : #'t - item' }
TToItem >> barOwner: anItemContainer [

barOwner := anItemContainer
self userData at: #barOwner put: anItemContainer
]

{ #category : #'t - item' }
TToItem >> barOwnerDo: aBlock [

barOwner ifNil: [ ^ self ].
aBlock value: barOwner
self barOwner ifNotNil: [ :bo | aBlock value: bo ]
]

{ #category : #'t - item' }
TToItem >> disabled: aBoolean [
TToItem >> ensuredItemConstraints [

self storeDisabled: aBoolean.
barElement ifNotNil: [ :l |
aBoolean
ifTrue: [ l disabledItem: self ]
ifFalse: [ l enabledItem: self ] ].
super disabled: aBoolean
^ self userData
at: #itemConstraints
ifAbsentPut: [self newItemConstraints ]
]

{ #category : #'t - item' }
TToItem >> ensureConstraintsStorage [
TToItem >> flagAsDisabled: aBoolean [

itemConstraints := ToItemConstraints new
self storeDisabled: aBoolean.
self barElementDo: [ :be |
aBoolean
ifTrue: [ be disabledItem: self ]
ifFalse: [ be enabledItem: self ] ].
super flagAsDisabled: aBoolean
]

{ #category : #'t - item' }
Expand All @@ -74,38 +69,46 @@ TToItem >> hidden: aBoolean [
]

{ #category : #'t - item' }
TToItem >> positionInBar [
TToItem >> itemConstraints [

self barElementDo: [ :pm | ^ pm items indexOf: self ].
^ 0
^ self userData at: #itemConstraints ifAbsent: [ ]
]

{ #category : #'t - item' }
TToItem >> storeDisabled: aBoolean [
TToItem >> itemConstraintsDo: aValuable [

self ensureConstraintsStorage.
itemConstraints disabled: aBoolean
self itemConstraints ifNil: [ ^ self ].
aValuable value: self itemConstraints
]

{ #category : #'t - item' }
TToItem >> storeHidden: aBoolean [
TToItem >> newItemConstraints [

self ensureConstraintsStorage.
itemConstraints hidden: aBoolean
^ ToItemConstraints new
]

{ #category : #'t - item' }
TToItem >> storeUnselectable: aBoolean [
TToItem >> positionInBar [

^ self holder position
]

{ #category : #'t - item' }
TToItem >> storeDisabled: aBoolean [

self ensuredItemConstraints disabled: aBoolean
]

self ensureConstraintsStorage.
itemConstraints unselectable: aBoolean
{ #category : #'t - item' }
TToItem >> storeHidden: aBoolean [

self ensuredItemConstraints hidden: aBoolean
]

{ #category : #'t - item' }
TToItem >> storedConstraintsDo: aValuable [
TToItem >> storeUnselectable: aBoolean [

itemConstraints ifNil: [ ^ self ].
aValuable value: itemConstraints
self ensuredItemConstraints unselectable: aBoolean
]

{ #category : #'t - item' }
Expand Down
Loading

0 comments on commit b5a19b1

Please sign in to comment.