Skip to content

Commit

Permalink
#whenClickedDo: is usable for all button and button menu item kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Sep 24, 2024
1 parent 7d767fb commit 74c22a6
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 149 deletions.
8 changes: 3 additions & 5 deletions src/Toplo-Examples/ToMiniBrowser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ToMiniBrowser >> candidateProtocolsForClass: aClass [
| prots |
prots := classSide
ifTrue: [
aClass organization allProtocols select: [ :p |
aClass allProtocols select: [ :p |
aClass isLocalMethodsProtocol: p ] ]
ifFalse: [ aClass allProtocols ].
^ prots sort: [ :a :b | a name < b name ]
Expand Down Expand Up @@ -126,12 +126,10 @@ ToMiniBrowser >> newClassPane [
classesPane addChild: classesButtonPane.

sideToggle checked: self classSide.
sideToggle addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
sideToggle whenClickedDo: [ :event |
classSide := event current.
self refreshClassSelectionWithSelectedIndexes:
classes selectionModel selectedIndexes ]).
classes selectionModel selectedIndexes ].
^ classesPane
]

Expand Down
78 changes: 24 additions & 54 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ ToSandBox class >> barConfigurationBoardFor: aBar [
menu addItem: (ToCheckMenuItem new
label: (ToLabel text: 'Disable bar');
whenClickedDo: [ :event |
event currentTarget isChecked traceCr.
aBar enabled: event currentTarget isChecked ];
aBar disabled: event currentTarget isChecked ];
yourself).
confPane addChild: menu.

verticalSwitch := ToSwitchButton new labelText: 'Vertical'.
verticalSwitch startFlexible: true.
verticalSwitch hMatchParent.

verticalSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event | aBar vertical: event current ]).
verticalSwitch whenClickedDo: [ :event | aBar vertical: event current ].

confPane addChild: verticalSwitch.

Expand All @@ -55,59 +52,49 @@ ToSandBox class >> barConfigurationBoardFor: aBar [

confPane addChild: scrollingSwitch.

wrappingSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
wrappingSwitch whenClickedDo: [ :event |
| v |
v := event current.
aBar nodeWrapping: v.
sameWidthSwitch enabled: v.
scrollingSwitch disabled: v ]).
scrollingSwitch disabled: v ].

sameWidthSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
sameWidthSwitch whenClickedDo: [ :event |
| v |
v := event current.
aBar flowLineUniformWidth: v ]).
aBar flowLineUniformWidth: v ].

scrollingSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
scrollingSwitch whenClickedDo: [ :event |
| v |
v := event current.
aBar nodeScrolling: v ]).
aBar nodeScrolling: v ].

autoDistributionSwitch := ToSwitchButton new labelText:
'Auto-distribution'.
autoDistributionSwitch startFlexible: true.
autoDistributionSwitch hMatchParent.

confPane addChild: autoDistributionSwitch.
autoDistributionSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
autoDistributionSwitch whenClickedDo: [ :event |
| v |
v := event current.
aBar nodeAutoDistribution: v ]).
aBar nodeAutoDistribution: v ].

selectionAnimationSwitch := ToSwitchButton new labelText:
'Animate selection transition'.
selectionAnimationSwitch startFlexible: true.
selectionAnimationSwitch hMatchParent.

confPane addChild: selectionAnimationSwitch.
selectionAnimationSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
selectionAnimationSwitch whenClickedDo: [ :event |
| v |
v := event current.
aBar primarySelectionMode option animationDuration: (v
ifTrue: [ 200 milliSeconds ]
ifFalse: [ 0 milliSeconds ]).
aBar secondarySelectionMode option animationDuration: (v
ifTrue: [ 150 milliSeconds ]
ifFalse: [ 0 milliSeconds ]) ]).
ifFalse: [ 0 milliSeconds ]) ].

wrappingSwitch checked: true.

Expand All @@ -118,10 +105,8 @@ ToSandBox class >> barConfigurationBoardFor: aBar [
selectOnMouseDownSwitch hMatchParent.

confPane addChild: selectOnMouseDownSwitch.
selectOnMouseDownSwitch addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event |
aBar primarySelectionMode selectOnMouseDown: event current ]).
selectOnMouseDownSwitch whenClickedDo: [ :event |
aBar primarySelectionMode selectOnMouseDown: event current ].

wrappingSwitch checked: true.

Expand Down Expand Up @@ -475,8 +460,7 @@ ToSandBox class >> example_CheckboxChecked [
on: ToSkinEvent
do: [ :evt | evt target = chb ifTrue: [ evt traceCr ] ])."
chb whenClickedDo: [ :event |
event currentTarget isChecked traceCr.
event traceCr ].
event currentTarget isChecked traceCr ].
chb checked: true.
chb isChecked traceCr.
chb openInInnerWindow
Expand Down Expand Up @@ -2697,7 +2681,7 @@ ToSandBox class >> example_bar [
bar := ToBarElement new.
bar addStamp: #background withValue: Color veryLightGray.
bar nodeFactory: [ :holder | ToBarNodeExamplePart new ].
bar nodeBuilder: [ :node :dataItem :holder|
bar nodeBuilder: [ :node :dataItem :holder |
node label:
(ToLabel text: holder position asString , ': ' , dataItem asString) ].

Expand All @@ -2719,11 +2703,11 @@ ToSandBox class >> example_bar [
confBoard := self barConfigurationBoardFor: bar.
selectionModeBoard := self selectionModeChooserFor: bar.
confBoard addChild: selectionModeBoard.

rootPane := ToPane horizontal.
rootPane padding: (BlInsets all: 5).
rootPane matchParent.

rootPane addChild: confBoard.
rootPane addChild: bar.
rootPane addDividers.
Expand Down Expand Up @@ -2764,18 +2748,13 @@ ToSandBox class >> example_buttonWithActionControl [
but label: (ToLabel text: 'Button with label').
count := 0.
but whenClickedDo: [ :event | self inform: 'Action runned' ].
but addEventHandlerOn: ToClickableActionRequestEvent do: [ :event |
count := count + 1.
event authorized: count odd.
event denied ifTrue: [ self inform: 'Action denied' ] ].
but openInSpace.
^ but
]

{ #category : #button }
ToSandBox class >> example_buttonWithDisableEnable [


| space button pane disacbox |
space := BlSpace new.
space root layout: BlLinearLayout vertical.
Expand All @@ -2784,16 +2763,12 @@ ToSandBox class >> example_buttonWithDisableEnable [
pane layout cellSpacing: 5.
pane padding: (BlInsets all: 5).

disacbox := ToCheckbox new label:
(ToLabel text: 'Disable').
disacbox := ToCheckbox new label: (ToLabel text: 'Disable').
button := (ToButton id: #buttonA)
labelText: 'Button';
yourself.
labelText: 'Button';
yourself.

disacbox addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :evt |
button disabled: evt current ]).
disacbox whenClickedDo: [ :evt | button disabled: evt current ].

pane addChild: disacbox.
pane addChild: button.
Expand Down Expand Up @@ -2938,10 +2913,7 @@ ToSandBox class >> example_closeableTabs [
(Color wheel: 5) withIndexDo: [ :eachColor :index |
but := ToTab new.
but closable: true.
but addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event | event current traceCr ]).

but whenClickedDo: [ :event | event current traceCr ].
but labelText: 'Button ' , index asString.
but paneBuilder: [ :pane :theNoteBook | pane background: eachColor ].
nb addTab: but ].
Expand Down Expand Up @@ -3811,9 +3783,7 @@ ToSandBox class >> example_switchButton2 [
((ToImage inner: (self iconNamed: #glamorousClose))
innerImageColor: Color white).

th addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :event | event current traceCr ]).
th whenClickedDo: [ :event | event current traceCr ].
sp := th openInSpace
]

Expand Down
12 changes: 4 additions & 8 deletions src/Toplo-Theme-Examples/ToThemeExamples.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,19 @@ ToThemeExamples class >> example_beeButtonsInRawPane [
primaryButton2
addTokenNamed: #'color-primary-hover'
withValue: c twiceLighter ].
chb addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :evt |
chb whenClickedDo: [ :evt |
evt current
ifTrue: [ primaryButton2 addStamp: #primary ]
ifFalse: [ primaryButton2 removeStamp: #primary ] ]).
ifFalse: [ primaryButton2 removeStamp: #primary ] ].
chb checked: true.
disachb addEventHandler: (BlEventHandler
on: ToCheckableCheckEvent
do: [ :evt |
disachb whenClickedDo: [ :evt |
evt current
ifTrue: [
pane childrenDo: [ :child |
child ~= disachb ifTrue: [ child disable ] ] ]
ifFalse: [
pane childrenDo: [ :child |
child ~= disachb ifTrue: [ child enable ] ] ] ]).
child ~= disachb ifTrue: [ child enable ] ] ] ].

pane addChild: primaryButton1.
pane addChild: chb.
Expand Down
39 changes: 5 additions & 34 deletions src/Toplo-Widget-Button/ToClickableActionEventHandler.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : #ToClickableActionEventHandler,
#superclass : #BlCustomEventHandler,
#superclass : #BlBasicEventHandler,
#instVars : [
'action'
],
Expand All @@ -19,47 +19,18 @@ ToClickableActionEventHandler >> action: aBlock [
action := aBlock
]

{ #category : #'as yet unclassified' }
ToClickableActionEventHandler >> clickableRunActionEvent: anEvent [

anEvent currentTarget clickEvent: anEvent.
action cull: anEvent
]

{ #category : #'as yet unclassified' }
ToClickableActionEventHandler >> eventsToHandle [

^ { ToClickableRunActionEvent }
]

{ #category : #'api - event managing' }
ToClickableActionEventHandler >> handleEvent: anEvent [

(anEvent isKindOf: anEvent currentTarget clickEventClass)
ifTrue: [
self receiveClickEvent: anEvent.
^ self ].
anEvent sendTo: self
]

{ #category : #'event handling' }
ToClickableActionEventHandler >> receiveClickEvent: anEvent [

| req target |
| target |
target := anEvent currentTarget.
target isDisabled ifTrue: [ ^ self ].
req := ToClickableActionRequestEvent new
requestedAction: [
target fireEvent: (ToClickableRunActionEvent new
sourceEvent: anEvent;
yourself) ];
yourself.
target fireAuthorisationRequest: req
action ifNil: [ ^ self ].
action cull: anEvent
]

{ #category : #'api - event managing' }
ToClickableActionEventHandler >> wantsEvent: anEvent [

^ (anEvent isKindOf: anEvent currentTarget clickEventClass) or: [
super wantsEvent: anEvent ]
^ (anEvent isKindOf: anEvent currentTarget clickEventClass)
]
11 changes: 0 additions & 11 deletions src/Toplo-Widget-Button/ToClickableActionRequestEvent.class.st

This file was deleted.

26 changes: 0 additions & 26 deletions src/Toplo-Widget-Button/ToClickableRunActionEvent.class.st

This file was deleted.

4 changes: 3 additions & 1 deletion src/Toplo-Widget-Button/ToSwitchButton.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ ToSwitchButton >> initialize [
super initialize.
self icon: ToSwitchIcon new.
self initializeCheckable.
self checked: false
self checked: false.
self clickEventClass: ToCheckableCheckEvent.

]

{ #category : #skin }
Expand Down
3 changes: 2 additions & 1 deletion src/Toplo-Widget-Button/ToSwitchIcon.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ ToSwitchIcon >> checked: aBoolean [

checked = aBoolean ifTrue: [ ^ self ].
checked := aBoolean.
self dispatchEvent: (ToCheckableCheckEvent current: checked previous: checked not)
self dispatchEvent:
(ToCheckableCheckEvent current: checked previous: checked not)
]

{ #category : #accessing }
Expand Down
4 changes: 3 additions & 1 deletion src/Toplo-Widget-Button/ToToggleButton.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ ToToggleButton >> checkable: aBoolean [
ToToggleButton >> initialize [

super initialize.
self initializeCheckable
self initializeCheckable.
self clickEventClass: ToCheckableCheckEvent.

]

{ #category : #skin }
Expand Down
6 changes: 6 additions & 0 deletions src/Toplo-Widget-Menu/ToCheckMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ ToCheckMenuItem >> buttonClass [
^ ToCheckbox
]

{ #category : #initialization }
ToCheckMenuItem >> buttonClickEventClass [

^ ToCheckableCheckEvent
]

{ #category : #'t - checkable - accessing' }
ToCheckMenuItem >> checkableData [

Expand Down
Loading

0 comments on commit 74c22a6

Please sign in to comment.