Skip to content

Commit

Permalink
cleaning WindowManager and related event handlers hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Oct 29, 2024
1 parent ef3d1fe commit 5d6dd5f
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 217 deletions.
5 changes: 2 additions & 3 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4568,7 +4568,6 @@ ToSandBox class >> example_toButtonWithElementTooltip [
background: Color random;
size: 70 @ 100;
yourself) ].
but whenClickedDo: [ :ann | self inform: 'Button clicked' ].
but openInInnerWindow
]

Expand Down Expand Up @@ -4786,7 +4785,7 @@ ToSandBox class >> example_toKeepTooltipWindowOnMouseLeave [
| but |
self flag: 'not working as expected'.
but := ToButton new.
but closeTooltipWindowOnMouseLeave: false.
but closeTooltipOnMouseLeave: false.
but labelText: 'Button with tooltip text'.
but tooltipText: ('This is a button', String cr, 'so, click on me...') asRopedText.
but whenClickedDo: [ :ann | self inform: 'Button clicked' ].
Expand All @@ -4801,7 +4800,7 @@ ToSandBox class >> example_toKeepTooltipWindowOnMouseLeaveWithEditableLabel [
self flag: 'Check the elevation of the editor'.
but := ToButton new.
but labelText: 'Button with editable tooltip'.
but closeTooltipWindowOnMouseLeave: false.
but closeTooltipOnMouseLeave: false.
but tooltipBuilder: [ :win :theElement |
| lab |
lab := ToLabel text: ' keep mouse over with shift key to edit / Return to accept' asRopedText.
Expand Down
6 changes: 3 additions & 3 deletions src/Toplo-Tests/TToElementWithTooltipTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
}

{ #category : #tests }
TToElementWithTooltipTest >> testCloseTooltipWindowOnMouseLeave [
TToElementWithTooltipTest >> testCloseTooltipOnMouseLeave [

| e |
e := ToElement new.
Expand All @@ -27,12 +27,12 @@ TToElementWithTooltipTest >> testCloseTooltipWindowOnMouseLeave [
]

{ #category : #tests }
TToElementWithTooltipTest >> testCloseTooltipWindowOnMouseLeave2 [
TToElementWithTooltipTest >> testCloseTooltipOnMouseLeave2 [

| e |
e := ToElement new.
e size: 50@50.
e closeTooltipWindowOnMouseLeave: false.
e closeTooltipOnMouseLeave: false.
e tooltipPopupDelay: 10 milliSeconds.
space root addChild: e.
self assert: e currentTooltipWindow isNil.
Expand Down
19 changes: 19 additions & 0 deletions src/Toplo-Tests/ToPopupWindowManagerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,25 @@ ToPopupWindowManagerTest >> testNoAutoCloseEvenAfterLongDelay [
self deny: closed
]

{ #category : #tests }
ToPopupWindowManagerTest >> testUseNoMouseButton [

| e windowManager event |
e := ToElement new.
e size: 100 asPoint.
space root addChild: e.
self waitTestingSpaces.

windowManager := ToPopupWindowManager new.
windowManager useNoMouseButton.
windowManager onInstalledIn: e.
event := BlMouseDownEvent primary.
event position: e bounds inSpace center.
BlSpace simulateEvent: event on: e.
self waitTestingSpaces.
self assert: windowManager currentWindow isNil.
]

{ #category : #tests }
ToPopupWindowManagerTest >> testUsePrimaryMouseButton [

Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Tests/ToPropertyWriterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ToPropertyWriterTest >> testAnimationNeedPropertyWithReader [
propWriter animation:
(anim := ToPropertyColorTransitionAnimation new
property: prop;
duration: 5 milliSeconds).
duration: 50 milliSeconds).
self should: [ propWriter writeTo: w ] raise: MessageNotUnderstood.

"now setup a reader and it should be ok "
Expand Down
12 changes: 5 additions & 7 deletions src/Toplo-Tests/ToSpaceSkinStateApplicationPhaseTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ ToSpaceSkinStateApplicationPhaseTest >> testStartSkinPhases [

" shoud result in a requestSkin which do the installation if needed "
" The skin specific phase is added"
space when: ToSpaceSkinPhasesStarted doOnce: [
space addEventHandlerOn: ToSpaceSkinPhasesStarted doOnce: [
self assert: space frame phases size equals: nb + 2.
self assert: (space frame phases anySatisfy: [ :p |
p isKindOf: ToSpaceSkinInstallerPhase ]).
self assert: (space frame phases anySatisfy: [ :p |
p isKindOf: ToSpaceSkinStateApplicationPhase ]).
space close ].

space skinPhasesManager startSkinPhasesIn: space


space skinPhasesManager startSkinPhasesIn: space
]

{ #category : #tests }
Expand All @@ -39,20 +37,20 @@ ToSpaceSkinStateApplicationPhaseTest >> testStartStopSkinStatePhases [

started := false.

space when: ToSpaceSkinPhasesStarted doOnce: [
space addEventHandlerOn: ToSpaceSkinPhasesStarted doOnce: [
started := true.
" The skin specific phase is added"
self assert: space frame phases size equals: nb + 2.
self assert: (space frame phases anySatisfy: [ :p |
p isKindOf: ToSpaceSkinInstallerPhase ]).
self assert: (space frame phases anySatisfy: [ :p |
p isKindOf: ToSpaceSkinStateApplicationPhase ]) ].

space startSkinPhases.
self assert: started.

stopped := false.
space when: ToSpaceSkinPhasesStopped doOnce: [
space addEventHandlerOn: ToSpaceSkinPhasesStopped doOnce: [
stopped := true.
" The skin specific phase is removed "
self assert: space frame phases size equals: nb.
Expand Down
14 changes: 7 additions & 7 deletions src/Toplo-Tests/ToTooltipWindowTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ Class {
{ #category : #tests }
ToTooltipWindowTest >> testContent [

| e windowHandler |
| e windowManager |

e := ToElement new size: 100@100.
e tooltipContent: (ToLabel text: 'Tooltip content').
windowHandler := e tooltipWindowManager.
self assert: (windowHandler isKindOf: ToTooltipWindowManager).
windowManager := e tooltipWindowManager.
self assert: (windowManager isKindOf: ToTooltipWindowManager).
space root addChild: e.
"self waitTestingSpaces."

BlSpace simulateMouseMoveInside: e.
self waitTestingSpaces.
(windowHandler popupDelay + 100 milliSecond ) wait.
(windowManager popupDelay + 100 milliSecond ) wait.
self waitTestingSpaces.

self assert: (windowHandler currentWindow root firstChild isKindOf: ToLabel) .
self assert: windowHandler currentWindow root firstChild text asString equals: 'Tooltip content' .
^ windowHandler currentWindow
self assert: (windowManager currentWindow root firstChild isKindOf: ToLabel) .
self assert: windowManager currentWindow root firstChild text asString equals: 'Tooltip content' .
^ windowManager currentWindow
]

{ #category : #tests }
Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Widget-List/ToListElementEventHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ToListElementEventHandler >> mouseDownEvent: anEvent [
self withTargetNodeFromEvent: anEvent do: [ :node |
node dispatchEvent: anEvent copy.
anEvent consume ].
target isFocused ifTrue: [ ^ self ].
(target isFocusable not or: [ target isFocused ]) ifTrue: [ ^ self ].
target requestFocus.
anEvent consume
]
Expand Down
6 changes: 6 additions & 0 deletions src/Toplo-Widget-Menu/ToContextMenuWindowManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ToContextMenuWindowManager >> elementEventHandlerClass [
^ ToElementWithContextMenuEventHandler
]

{ #category : #'event handling' }
ToContextMenuWindowManager >> elementPositionInSpaceChangedEvent: anEvent [

self currentWindowDo: [ :cw | cw close ]
]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ Class {
#category : #'Toplo-Widget-Menu-Context menu'
}

{ #category : #'element handlers' }
{ #category : #'event handling' }
ToElementWithContextMenuEventHandler >> contextMenuClosedEvent: anEvent [

anEvent windowManager = windowManager ifFalse: [ ^ self ].
windowManager onWindowClosed
]

{ #category : #'element handlers' }
ToElementWithContextMenuEventHandler >> contextMenuOpenedEvent: anEvent [

anEvent windowManager = windowManager ifFalse: [ ^ self ].
windowManager onWindowOpened
self windowClosedEvent: anEvent
]

{ #category : #'event handling' }
ToElementWithContextMenuEventHandler >> elementPositionInSpaceChangedEvent: anEvent [
ToElementWithContextMenuEventHandler >> contextMenuOpenedEvent: anEvent [

windowManager currentWindowDo: [ :cw | cw close ]
self windowOpenedEvent: anEvent
]
2 changes: 1 addition & 1 deletion src/Toplo-Widget-Menu/ToMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ToMenu >> newRawSkin [
{ #category : #'t - menu window model' }
ToMenu >> popupEvent: anEvent [

(windowManager newWindowEvent: anEvent) popupEvent: anEvent
windowManager enqueuePopupTaskFromEvent: anEvent
]

{ #category : #'adding-removing' }
Expand Down
1 change: 1 addition & 0 deletions src/Toplo-Widget-Select/ToMultiSelectBarElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ ToMultiSelectBarElement >> initialize [
self primarySelectionMode makeDisabledUnselectable: true.
self secondarySelectionMode selectionOption masked: true.
self nodeHolderClass: ToMultiSelectHolder.
self focusability: BlFocusability ignore.
maxSelectedCount := 0.
keepPickOrder := false.
pickCount := 0.
Expand Down
14 changes: 8 additions & 6 deletions src/Toplo-Widget-Select/ToSelectElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ ToSelectElement >> dataAccessor [
^ self popupListElement dataAccessor
]

{ #category : #initialization }
ToSelectElement >> defaultEventHandler [

^ ToSelectEventHandler new
]

{ #category : #initialization }
ToSelectElement >> defaultLayout [

Expand Down Expand Up @@ -106,12 +112,8 @@ ToSelectElement >> initialize [
self addChildren: {
self innerElement.
self iconContainer }.

self addEventHandlerOn: ToPlaceholderShownEvent do: [ :event |
self flag:
'The width of 16???. Why ? Anyway, it should be handled via a skin'.
event placeholder padding: (BlInsets left: (self valueOfTokenNamed: #'padding-XS')).
event placeholder layout alignCenterLeft ].

self addEventHandler: self defaultEventHandler.

" a select is made to be horizontal. the following constraints
must be set here to initialize the resizers properly "
Expand Down
27 changes: 12 additions & 15 deletions src/Toplo-Widget-Select/ToSelectEventHandler.class.st
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
Class {
#name : #ToSelectEventHandler,
#superclass : #ToElementWithPopupEventHandler,
#superclass : #BlCustomEventHandler,
#category : #'Toplo-Widget-Select-Core'
}

{ #category : #'event handling' }
ToSelectEventHandler >> elementAddedToSceneGraphEvent: anEvent [

| select |
select := anEvent currentTarget.
select refresh
]

{ #category : #'element handlers' }
ToSelectEventHandler >> elementExtentChangedEvent: anEvent [

windowManager currentWindow ifNil: [ ^ self ].
windowManager applyPositionHookFromEvent: anEvent.
windowManager applySizeHookFromEvent: anEvent
anEvent currentTarget refresh
]

{ #category : #'api - accessing' }
ToSelectEventHandler >> eventsToHandle [
^ { BlElementAddedToSceneGraphEvent. ToPlaceholderShownEvent }
]

{ #category : #'event handling' }
ToSelectEventHandler >> placeHolderShownEvent: anEvent [

^ super eventsToHandle , {
BlElementAddedToSceneGraphEvent.
BlElementExtentChangedEvent }
self flag:
'The width of 16???. Why ? Anyway, it should be handled via a skin'.
anEvent placeholder padding: (BlInsets left:
(anEvent currentTarget valueOfTokenNamed: #'padding-XS')).
anEvent placeholder layout alignCenterLeft
]
11 changes: 7 additions & 4 deletions src/Toplo-Widget-Select/ToSelectPopupWindowManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ ToSelectPopupWindowManager >> defaultSizeHook [
theWindow width: theElement measuredWidth]
]

{ #category : #accessing }
ToSelectPopupWindowManager >> elementEventHandlerClass [
{ #category : #'event handling' }
ToSelectPopupWindowManager >> elementExtentChangedEvent: anEvent [

^ ToSelectEventHandler
super elementExtentChangedEvent: anEvent.
currentWindow ifNil: [ ^ self ].
self applyPositionHookFromEvent: anEvent.
self applySizeHookFromEvent: anEvent
]

{ #category : #accessing }
Expand Down Expand Up @@ -87,7 +90,7 @@ ToSelectPopupWindowManager >> minHeight: aNumber [
listElement minHeight: aNumber
]

{ #category : #'mouse handlers' }
{ #category : #'event handling' }
ToSelectPopupWindowManager >> mouseDownInElementEvent: anEvent [

super mouseDownInElementEvent: anEvent.
Expand Down
10 changes: 5 additions & 5 deletions src/Toplo/TToElementWithTooltip.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ Trait {
}

{ #category : #'t - element with tooltip' }
TToElementWithTooltip >> closeTooltipWindowOnMouseLeave [
TToElementWithTooltip >> closeTooltipOnMouseLeave [

"Set a help string to display to the user if he let the mouse over the widget (a tooltip)."

^ self userData at: #closeTooltipWindowOnMouseLeave ifAbsentPut: [ true ]
^ self tooltipWindowManager closeOnMouseLeave
]

{ #category : #'t - element with tooltip' }
TToElementWithTooltip >> closeTooltipWindowOnMouseLeave: aBoolean [
TToElementWithTooltip >> closeTooltipOnMouseLeave: aBoolean [

"Set a help string to display to the user if he let the mouse over the widget (a tooltip)."

self userData at: #closeTooltipWindowOnMouseLeave put: aBoolean
self tooltipWindowManager closeOnMouseLeave: aBoolean
]

{ #category : #'t - element with tooltip' }
Expand All @@ -28,7 +28,7 @@ TToElementWithTooltip >> currentTooltipWindow [
{ #category : #'t - element with tooltip' }
TToElementWithTooltip >> hasOpenedTooltip [
" do not use #tooltipWindowHandler to avoid TooltipWindowHandler installation here "

self deprecated: 'Unless there are users. add an issue if this is the case'.
^ self currentTooltipWindow notNil
]

Expand Down
Loading

0 comments on commit 5d6dd5f

Please sign in to comment.