Skip to content

Commit

Permalink
Merge pull request #231 from pharo-graphics/ItemListNodeDisable
Browse files Browse the repository at this point in the history
Item list node disable
  • Loading branch information
plantec authored Jan 10, 2025
2 parents 3a7a2da + fb455f3 commit f301be3
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3924,12 +3924,12 @@ ToSandBox class >> example_menuBar0 [
menu addItem: (ToMenuItem new labelText: 'item 1').
menu addItem: ToSeparatorMenuItem new.
sub := ToMenuItem new labelText: 'item 2'.
sub disable.
menu addItem: sub.
sub disable.
bar addItem: menu.
menu := ToMenuItem new labelText: 'Menu 1'.
bar addItem: menu.
menu disable.
menu disabled: true.
bar openInSpace
]

Expand Down
5 changes: 5 additions & 0 deletions src/Toplo-Widget-List-Tests/ToBarNodeHolderForTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #ToBarNodeHolderForTest,
#superclass : #ToBarNodeHolder,
#category : #'Toplo-Widget-List-Tests-ItemList'
}
25 changes: 25 additions & 0 deletions src/Toplo-Widget-List-Tests/ToItemElementForTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class {
#name : #ToItemElementForTest,
#superclass : #ToElement,
#traits : 'TToItem',
#classTraits : 'TToItem classTrait',
#instVars : [
'label'
],
#category : #'Toplo-Widget-List-Tests-ItemList'
}

{ #category : #initialization }
ToItemElementForTest >> initialize [

super initialize.
label := ToLabel new.
self addChild: label.
self fitContent
]

{ #category : #accessing }
ToItemElementForTest >> text: aText [

label text: aText
]
11 changes: 11 additions & 0 deletions src/Toplo-Widget-List-Tests/ToItemListElementForTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToItemListElementForTest,
#superclass : #ToItemListElement,
#category : #'Toplo-Widget-List-Tests-ItemList'
}

{ #category : #initialization }
ToItemListElementForTest >> defaultNodeManagerClass [

^ ToItemNodeManagerForTest
]
67 changes: 67 additions & 0 deletions src/Toplo-Widget-List-Tests/ToItemListElementTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"
A ToItemListElementTest is a test class for testing the behavior of ToItemListElement
"
Class {
#name : #ToItemListElementTest,
#superclass : #ToParameterizedHostTest,
#instVars : [
'l'
],
#category : #'Toplo-Widget-List-Tests-ItemList'
}

{ #category : #running }
ToItemListElementTest >> setUp [

super setUp.
l := ToItemListElementForTest new.
l vMatchParent.
space root addChild: l
]

{ #category : #tests }
ToItemListElementTest >> test [

| n |
self assert: l nodes size equals: l dataAccessor size.
self assert: (l nodeManager isKindOf: ToItemNodeManagerForTest).
l dataAccessor addAll:
((1 to: 10) collect: [ :i | ToItemElementForTest new text: i asString ]).
n := l nodes first.
self assert: (n isKindOf: ToItemNodeForTest).
self assert: (n holder isKindOf: ToBarNodeHolderForTest).
self assert: (n holder dataItem isKindOf: ToItemElementForTest)

]

{ #category : #tests }
ToItemListElementTest >> testDisableItemAfterAdding [

| n item |
self skip.
self assert: l nodes size equals: 0.
item := ToItemElementForTest new text: 'A'.
l dataAccessor add: item.
item disable.
n := l nodes first.
self waitTestingSpaces.
self assert: n holder dataItem identicalTo: item.
self assert: item isDisabled.
self assert: n isDisabled
]

{ #category : #tests }
ToItemListElementTest >> testDisableItemBeforeAdding [

| n item |
self skip.
self assert: l nodes size equals: 0.
item := ToItemElementForTest new text: 'A'.
item disable.
l dataAccessor add: item.
n := l nodes first.
self waitTestingSpaces.
self assert: n holder dataItem identicalTo: item.
self assert: item isDisabled.
self assert: n isDisabled
]
5 changes: 5 additions & 0 deletions src/Toplo-Widget-List-Tests/ToItemNodeForTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #ToItemNodeForTest,
#superclass : #ToItemNode,
#category : #'Toplo-Widget-List-Tests-ItemList'
}
23 changes: 23 additions & 0 deletions src/Toplo-Widget-List-Tests/ToItemNodeManagerForTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Class {
#name : #ToItemNodeManagerForTest,
#superclass : #ToItemNodeManager,
#category : #'Toplo-Widget-List-Tests-ItemList'
}

{ #category : #initialization }
ToItemNodeManagerForTest >> defaultFakeDataItem [

^ ToItemElementForTest new text: 'X'
]

{ #category : #'instance creation' }
ToItemNodeManagerForTest >> newHolder [

^ ToBarNodeHolderForTest new
]

{ #category : #'instance creation' }
ToItemNodeManagerForTest >> newNodeForHolder: aNodeHolder [

^ ToItemNodeForTest new
]
2 changes: 1 addition & 1 deletion src/Toplo-Widget-List/ToGenericBarNodeManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ToGenericBarNodeManager >> defaultNodeFactory [
{ #category : #initialization }
ToGenericBarNodeManager >> defaultNodeUnbuilder [

^ [ :node :dataItem :holder | ]
^ [ :node :dataItem :holder | node removeChildren ]
]

{ #category : #initialization }
Expand Down
9 changes: 7 additions & 2 deletions src/Toplo-Widget-List/ToItemBarNodeHolder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ Class {
{ #category : #accessing }
ToItemBarNodeHolder >> initializeNode [


self dataItem presetDataDo: [ :pd |
pd setupItem: dataItem ].
super initializeNode
pd setupItem: self dataItem.
self disabled: self dataItem isDisabled.
self isHidden ifTrue: [ self node height: 0 ].
^ self ].
super initializeNode

]
6 changes: 6 additions & 0 deletions src/Toplo-Widget-List/ToSubSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Class {
#category : #'Toplo-Widget-List-Selection-Selecter'
}

{ #category : #initialization }
ToSubSelecter >> defaultCommandApplicationStrategy [

^ ToImmediateCommandApplicationStrategy new
]

{ #category : #'api - hooks' }
ToSubSelecter >> onInstalledIn: anEventTarget [

Expand Down
9 changes: 9 additions & 0 deletions src/Toplo/BlElement.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ BlElement >> parentChainReverseDo: aBlock [
self parentChain reverseDo: aBlock
]

{ #category : #'*Toplo' }
BlElement >> presetDataDo: aValuable [

" do nothing at this level.
It redefined for an element that is used as a list data item.
This is the case for a menu or a segmented button as examples
( see `TToItem` users )"
]

{ #category : #'*Toplo' }
BlElement >> preventSelectionSkinEvents [

Expand Down

0 comments on commit f301be3

Please sign in to comment.