Skip to content

Commit

Permalink
cleaned-up ToMultiSelectElement + optimize command appliers (removed …
Browse files Browse the repository at this point in the history
…all event uses - optimization after after Pablo remark about overused events )
  • Loading branch information
plantec committed Oct 21, 2024
1 parent 9b6f25e commit 0a82b28
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 144 deletions.
2 changes: 1 addition & 1 deletion src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3871,7 +3871,7 @@ ToSandBox class >> example_selectWithEditingMultiSelectionWithAllClassNames [
innerWindow := ToInnerWindow new.
select popupWindowManager anchorRoot: innerWindow root.
select hMatchParent.
select popupListDataAccessor updateAllWith:
select popupListElement dataAccessor updateAllWith:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).

innerWindow pane addChild: select.
Expand Down
22 changes: 14 additions & 8 deletions src/Toplo-Widget-Album-Tests/ToLabelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -111,43 +111,49 @@ ToLabelTest >> testTextChangePreserveAttributes2 [
" test if changing the text of a ToLabel do rebuild its skin "

| label hugeFontSize attributes fontSizeAttr prevAttributes |
self flag: 'To check'.
hugeFontSize := 60.

label := ToLabel text: 'Hello'.
space root addChild: label.
space applyAllSkinPhases.
attributes := label text attributesAt: 1.

" skin default attributes "
self assert: attributes notEmpty.

label defaultFontSize: hugeFontSize.
space applyAllSkinPhases.
fontSizeAttr := label text iterator
detectAttribute: [ :a |
a isKindOf: BlFontSizeDefaultAttribute ]
ifFound: [ :a | a ]
ifNone: [
self fail:
'should have a BlFontSizeDefaultAttribute' ].
" remember taht the skin drives the look so the font size is not applied here "
self deny: fontSizeAttr size equals: hugeFontSize.
self assert: fontSizeAttr size equals: (label valueOfTokenNamed: #'font-size').
" remember that the skin drives the look so the font size is not applied here "
"self deny: fontSizeAttr size equals: hugeFontSize.
self
assert: fontSizeAttr size
equals: (label valueOfTokenNamed: #'font-size')."
space applyAllSkinPhases.
" changing the text should renew the skin (and then take the stamp into account again)"
label text: 'Goodbye'.
space applyAllSkinPhases.

self assert: label text asString equals: 'Goodbye'.
prevAttributes := attributes.

attributes := label text attributesAt: 1.
self assert: prevAttributes ~~ attributes.
space applyAllSkinPhases.
fontSizeAttr := label text iterator
detectAttribute: [ :a |
a isKindOf: BlFontSizeDefaultAttribute ]
ifFound: [ :a | a ]
ifNone: [
self fail:
'should have a BlFontSizeDefaultAttribute' ].
self assert: fontSizeAttr size equals: (label valueOfTokenNamed: #'font-size').

self
assert: fontSizeAttr size
equals: (label valueOfTokenNamed: #'font-size')
]

{ #category : #tests }
Expand Down
13 changes: 0 additions & 13 deletions src/Toplo-Widget-List-Tests/ToSelectionModelCommandTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ ToSelectionModelCommandTest >> applyCommand: aCommand [
aCommand applyWithOperator: self
]

{ #category : #'event management' }
ToSelectionModelCommandTest >> dispatchEvent: anEvent [

(anEvent isKindOf: ToElementCommandApplicationRequest) ifTrue: [
anEvent sendTo: self ]
]

{ #category : #'event management' }
ToSelectionModelCommandTest >> elementCommandApplicationRequest: anEvent [

anEvent currentTarget applyCommand: anEvent command
]

{ #category : #accessing }
ToSelectionModelCommandTest >> noSelectionCommand [

Expand Down
20 changes: 0 additions & 20 deletions src/Toplo-Widget-List/ToCommandApplicationEvent.class.st

This file was deleted.

24 changes: 15 additions & 9 deletions src/Toplo-Widget-List/ToCommandApplicationTask.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ ToCommandApplicationTask >> applier: anObject [
{ #category : #'api - running' }
ToCommandApplicationTask >> applyAll [

| nextInQueue |

element ifNil: [ ^ self ].
self canApplyCommands ifFalse: [
finishedAction value.
posponedRequestTask ifNotNil: [ ^ self ].
posponedRequestTask := BlTaskAction new.
posponedRequestTask action: [
applier dispatchEvent: ToCommandApplicationTaskActivationEvent new ].
"applier dispatchEvent: ToCommandApplicationTaskActivationEvent new"
self privateApplyAll ].
element enqueueTask: posponedRequestTask.
^ self ].

[ (nextInQueue := commandQueue nextOrNil) isNotNil ] whileTrue: [
applier applyCommand: nextInQueue ]
self privateApplyAll
]

{ #category : #'api - running' }
ToCommandApplicationTask >> canApplyCommands [

^ element isAttachedToSceneGraph
^ element notNil and: [ element isAttachedToSceneGraph ]
]

{ #category : #initialization }
Expand All @@ -66,9 +64,17 @@ ToCommandApplicationTask >> operator: anOperator [
operator := anOperator
]

{ #category : #'api - running' }
ToCommandApplicationTask >> privateApplyAll [

| nextInQueue |
[ (nextInQueue := commandQueue nextOrNil) isNotNil ] whileTrue: [
applier applyCommand: nextInQueue ]
]

{ #category : #'api - running' }
ToCommandApplicationTask >> run [

self applyAll.
finishedAction value
finishedAction value.
]
12 changes: 6 additions & 6 deletions src/Toplo-Widget-List/ToCommandApplier.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Class {
}

{ #category : #accessing }
ToCommandApplier >> element: anElement [
ToCommandApplier >> command: aCommand addedIn: aSelecter [

element := anElement
self subclassResponsibility
]

{ #category : #'event handling' }
ToCommandApplier >> elementCommandAddedEvent: aCommandAddedEvent [
{ #category : #accessing }
ToCommandApplier >> element: anElement [

self subclassResponsibility
element := anElement
]

{ #category : #'api - accessing' }
ToCommandApplier >> eventsToHandle [

^ { ToElementCommandAddedEvent. }
^ { }
]
11 changes: 5 additions & 6 deletions src/Toplo-Widget-List/ToDataSourceCommandApplier.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Class {
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #'event handling' }
ToDataSourceCommandApplier >> elementCommandAddedEvent: aCommandAddedEvent [
{ #category : #accessing }
ToDataSourceCommandApplier >> command: aCommand addedIn: aSelecter [

element isAttachedToSceneGraph ifFalse: [
aCommandAddedEvent currentTarget applyCommand:
aCommandAddedEvent command.
aSelecter applyCommand: aCommand.
^ self ].
element dataSource
notifySelecterCommandApplicationRequest: aCommandAddedEvent command
from: aCommandAddedEvent currentTarget.
notifySelecterCommandApplicationRequest: aCommand
from: aSelecter.
element spaceDo: [ :sp | sp requestNextPulse ]
]
11 changes: 0 additions & 11 deletions src/Toplo-Widget-List/ToDirectCommandApplier.class.st

This file was deleted.

11 changes: 0 additions & 11 deletions src/Toplo-Widget-List/ToElementCommandAddedEvent.class.st

This file was deleted.

11 changes: 0 additions & 11 deletions src/Toplo-Widget-List/ToElementCommandApplicationRequest.class.st

This file was deleted.

11 changes: 11 additions & 0 deletions src/Toplo-Widget-List/ToImmediateCommandApplier.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Class {
#name : #ToImmediateCommandApplier,
#superclass : #ToCommandApplier,
#category : #'Toplo-Widget-List-Command-Support'
}

{ #category : #accessing }
ToImmediateCommandApplier >> command: aCommand addedIn: aSelecter [

aSelecter applyCommand: aCommand
]
4 changes: 1 addition & 3 deletions src/Toplo-Widget-List/ToListSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Class {
ToListSelecter >> addCommand: aCommand [

enabled ifFalse: [ ^ self ].
self dispatchEvent: (ToElementCommandAddedEvent new
command: aCommand;
yourself)
commandApplier command: aCommand addedIn: self
]

{ #category : #'command application' }
Expand Down
14 changes: 3 additions & 11 deletions src/Toplo-Widget-List/ToQueueBasedCommandApplier.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@ Class {
}

{ #category : #'event handling' }
ToQueueBasedCommandApplier >> elementCommandAddedEvent: aCommandAddedEvent [
ToQueueBasedCommandApplier >> command: aCommand addedIn: aSelecter [

weak ifTrue: [
element isAttachedToSceneGraph ifFalse: [
aCommandAddedEvent currentTarget applyCommand:
aCommandAddedEvent command.
aSelecter applyCommand: aCommand.
^ self ] ].

commandQueue nextPut: aCommandAddedEvent command.
commandQueue nextPut: aCommand.
self postApplicationTask.
element spaceDo: [ :sp | sp requestNextPulse ]
]

{ #category : #'event handling' }
ToQueueBasedCommandApplier >> elementCommandApplicationRequest: anEvent [

anEvent currentTarget applyCommand: anEvent command
]

{ #category : #'event handling' }
ToQueueBasedCommandApplier >> elementCommandApplicationTaskActivationEvent: aCommandsApplicationRequestEvent [

Expand All @@ -40,7 +33,6 @@ ToQueueBasedCommandApplier >> elementCommandApplicationTaskActivationEvent: aCom
ToQueueBasedCommandApplier >> eventsToHandle [

^ super eventsToHandle , {
ToElementCommandApplicationRequest.
ToCommandApplicationTaskActivationEvent }
]

Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Widget-List/ToSieveSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
{ #category : #initialization }
ToSieveSelecter >> initializeCommandApplier [

commandApplier := ToDirectCommandApplier new
commandApplier := ToImmediateCommandApplier new
]

{ #category : #'event firing' }
Expand Down
10 changes: 4 additions & 6 deletions src/Toplo-Widget-List/ToTaskBasedCommandApplier.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ Class {
}

{ #category : #'event handling' }
ToTaskBasedCommandApplier >> elementCommandAddedEvent: aCommandAddedEvent [
ToTaskBasedCommandApplier >> command: aCommand addedIn: aSelecter [

weak ifTrue: [
element isAttachedToSceneGraph ifFalse: [
aCommandAddedEvent currentTarget applyCommand:
aCommandAddedEvent command.
aSelecter applyCommand: aCommand.
^ self ] ].
element enqueueTask: (BlTaskAction new action: [
aCommandAddedEvent currentTarget applyCommand:
aCommandAddedEvent command ])
element enqueueTask:
(BlTaskAction new action: [ aSelecter applyCommand: aCommand ])
]

{ #category : #initialization }
Expand Down
8 changes: 1 addition & 7 deletions src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ ToMultiSelectBarElement >> checkMaxSelectedCount [
self popupListElement notifyDataSourceChanged
]

{ #category : #initialization }
ToMultiSelectBarElement >> defaultNodeManager [

^ ToMultiSelectNodeManager new
]

{ #category : #layout }
ToMultiSelectBarElement >> extentChanged [

Expand Down Expand Up @@ -131,7 +125,7 @@ ToMultiSelectBarElement >> initialize [
self selectionOption masked: true.
self primarySelectionMode makeDisabledUnselectable: true.
self secondarySelectionMode selectionOption masked: true.

self nodeHolderClass: ToMultiSelectHolder.
maxSelectedCount := 0.
keepPickOrder := false.
pickCount := 0.
Expand Down
3 changes: 1 addition & 2 deletions src/Toplo-Widget-Select/ToMultiSelectElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ ToMultiSelectElement >> nodeWrapping: aBoolean [
{ #category : #'accessing - list' }
ToMultiSelectElement >> setGroupIndex: anIndex [

self popupListElement groupSelecter selectIndex: anIndex.
self popupListElement disabledSelecter selectIndex: anIndex
self popupListElement groupSelecter selectIndex: anIndex
]

{ #category : #private }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Class {
#name : #ToMultiSelectListElementEventHandler,
#superclass : #ToSelectListElementEventHandler,
#category : #'Toplo-Widget-Select-List'
}

{ #category : #'api - accessing' }
ToMultiSelectListElementEventHandler >> eventsToHandle [

^ super eventsToHandle , { ToSelectGroupSelectionChangedEvent }
]

{ #category : #'event handling' }
ToMultiSelectListElementEventHandler >> selectGroupSelectionChangedEvent: anEvent [

| touchedIntervals target |
touchedIntervals := anEvent touchedIntervals.
target := anEvent currentTarget.
touchedIntervals do: [ :int |
target disabledSelecter selectIndex: int first to: int last.
self flag: 'Given that the list is initialized with #makeDisabledUnselectable: true, having to unselect here is not desired. It is necessary here because instead, the secondary selection can be on a group index.'.
target unselectableSelecter selectIndex: int first to: int last.
target dataSource notifyItemsChanged: int ]
]
Loading

0 comments on commit 0a82b28

Please sign in to comment.