Skip to content

Commit

Permalink
fixed menubar autoOpen by changing mouseDownOutsideEvent managing
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Nov 3, 2024
1 parent 628ec06 commit a491110
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 131 deletions.
2 changes: 0 additions & 2 deletions src/Toplo-Tests/TToElementWithTooltipTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ TToElementWithTooltipTest >> testHasOpenedTooltip [
| e |
e := ToElement new.
e tooltipContent: ToElement new.
self assert: e hasOpenedTooltip not.
self assert: e currentTooltipWindow isNil.
e newTooltipWindowEvent: nil.
self assert: e hasOpenedTooltip.
self assert: e currentTooltipWindow notNil.
self
assert: e currentTooltipWindow class
Expand Down
19 changes: 17 additions & 2 deletions src/Toplo-Widget-Menu/ToMenuBar.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Class {
#traits : 'TToOrientable',
#classTraits : 'TToOrientable classTrait',
#instVars : [
'autoOpen',
'menus'
],
#category : #'Toplo-Widget-Menu-Bar'
Expand Down Expand Up @@ -55,11 +56,24 @@ ToMenuBar >> addSeparator [
sep horizontal: self isHorizontal not
]

{ #category : #initialize }
{ #category : #accessing }
ToMenuBar >> autoOpen [

^ autoOpen
]

{ #category : #accessing }
ToMenuBar >> autoOpen: anObject [

autoOpen := anObject
]

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

super initialize.

autoOpen := false.
self layout: BlLinearLayout new.
self layout cellSpacing: 5.
self background: Color transparent.
Expand All @@ -70,7 +84,8 @@ ToMenuBar >> initialize [
on: ToLayoutOrientationChangedEvent
do: [ self adaptToOrientation ]).
menus := OrderedCollection new.
self addEventFilter: ToMenuBarEventHandler new
self addEventFilter: ToMenuBarEventFilter new.
self addEventHandler: ToMenuBarEventHandler new
]

{ #category : #'t - orientable - accessing' }
Expand Down
75 changes: 75 additions & 0 deletions src/Toplo-Widget-Menu/ToMenuBarEventFilter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Class {
#name : #ToMenuBarEventFilter,
#superclass : #BlCustomEventHandler,
#instVars : [
'target'
],
#category : #'Toplo-Widget-Menu-Bar'
}

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

^ { BlMouseDownEvent. BlMouseOverEvent }
]

{ #category : #'as yet unclassified' }
ToMenuBarEventFilter >> mouseDownEvent: anEvent [
"switch auto=open filter "

" mouse down on the menubar stops auto-open "

(anEvent target = target or: [
target menus noneSatisfy: [ :m |
anEvent target hasInParentChain: m ] ]) ifTrue: [ " stop auto open on mouse over "
target autoOpen: false.
^ self ].

" a mouse down on an opened menu stops auto-open"
target autoOpen ifTrue: [
target menus do: [ :m |
((anEvent target hasInParentChain: m) and: [ m menuWindow notNil ])
ifTrue: [
target autoOpen: false.
^ self ] ] ].

" now auto open on mouse over "
target autoOpen: true
]

{ #category : #'as yet unclassified' }
ToMenuBarEventFilter >> mouseOverEvent: anEvent [

target autoOpen ifFalse: [ ^ self ].

" auto-open action "
target menus do: [ :m |
(anEvent target hasInParentChain: m)
ifTrue: [ m menuWindow ifNil: [ m popupEvent: anEvent ] ]
ifFalse: [ m closeWindow ] ]
]

{ #category : #'as yet unclassified' }
ToMenuBarEventFilter >> mouseUpOutsideEvent: anEvent [

target autoOpen ifFalse: [ ^ self ].
anEvent originalEvent target ifNil: [ ^ self ].
(anEvent originalEvent target hasInParentChain: target)
ifTrue: [ ^ self ].
anEvent consume.
target autoOpen: false
]

{ #category : #'api - hooks' }
ToMenuBarEventFilter >> onInstalledIn: anElement [

super onInstalledIn: anElement.
target := anElement
]

{ #category : #'api - hooks' }
ToMenuBarEventFilter >> onUninstalledIn: anElement [

super onUninstalledIn: anElement.
target := nil
]
55 changes: 6 additions & 49 deletions src/Toplo-Widget-Menu/ToMenuBarEventHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Class {
#name : #ToMenuBarEventHandler,
#superclass : #BlCustomEventHandler,
#instVars : [
'autoOpen',
'target'
],
#category : #'Toplo-Widget-Menu-Bar'
Expand All @@ -11,60 +10,18 @@ Class {
{ #category : #'api - accessing' }
ToMenuBarEventHandler >> eventsToHandle [

^ { BlMouseDownEvent. BlMouseOverEvent. BlMouseUpOutsideEvent }
]

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

super initialize.
autoOpen := false
]

{ #category : #'api - install/uninstall hook' }
ToMenuBarEventHandler >> mouseDownEvent: anEvent [
"switch auto=open filter "

" mouse down on the menubar stops auto-open "
(anEvent target = target or: [
target menus noneSatisfy: [ :m |
anEvent target hasInParentChain: m ] ]) ifTrue: [ " stop auto open on mouse over "
autoOpen := false.
^ self ].

" a mouse down on an opened menu stops auto-open"
autoOpen ifTrue: [
target menus do: [ :m |
((anEvent target hasInParentChain: m) and: [ m menuWindow notNil])
ifTrue: [
autoOpen := false.
^ self ] ] ].

" now auto open on mouse over "
autoOpen := true
^ { BlMouseDownOutsideEvent }
]

{ #category : #'mouse handlers' }
ToMenuBarEventHandler >> mouseOverEvent: anEvent [

autoOpen ifFalse: [ ^ self ].

" auto-open action "
target menus do: [ :m |
(anEvent target hasInParentChain: m)
ifTrue: [ m menuWindow ifNil: [ m popupEvent: anEvent ] ]
ifFalse: [ m closeWindow ] ]
]
ToMenuBarEventHandler >> mouseDownOutsideEvent: anEvent [

{ #category : #'mouse handlers' }
ToMenuBarEventHandler >> mouseUpOutsideEvent: anEvent [

autoOpen ifFalse: [ ^ self ].
target autoOpen ifFalse: [ ^ self ].
anEvent originalEvent target ifNil: [ ^ self ].
(anEvent originalEvent target hasInParentChain: target)
ifTrue: [ ^ self ].
(anEvent originalEvent target hasInParentChain: target) ifTrue: [
^ self ].
anEvent consume.
autoOpen := false
target autoOpen: false
]

{ #category : #'api - hooks' }
Expand Down
9 changes: 1 addition & 8 deletions src/Toplo-Widget-Select/ToSelectPopupWindowManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ToSelectPopupWindowManager >> defaultAutoCloseOnMouseUpDelay [
{ #category : #initialization }
ToSelectPopupWindowManager >> defaultAutoClosePickOutsideEventClass [

^ BlMouseDownOutsideEvent
^ BlMouseUpOutsideEvent
]

{ #category : #'api - hooks' }
Expand Down Expand Up @@ -90,13 +90,6 @@ ToSelectPopupWindowManager >> minHeight: aNumber [
listElement minHeight: aNumber
]

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

super mouseDownInElementEvent: anEvent.
element filterTextField requestFocus
]

{ #category : #initialization }
ToSelectPopupWindowManager >> newListElement [

Expand Down
70 changes: 0 additions & 70 deletions src/Toplo/ToPopupWindowManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,6 @@ ToPopupWindowManager >> mouseDownEvent: anEvent [

]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseDownInElementEvent: anEvent [

builder ifNil: [ ^ self ].
closeOnMouseDown ifTrue: [ self unqueuePopupTaskIn: element ].
anEvent button = mouseButton ifFalse: [ ^ self ].
currentWindow ifNotNil: [
closeOnMouseDown ifTrue: [
currentWindow isOpened ifTrue: [ currentWindow close ].
^ self ] ].
popupOnMouseDown ifFalse: [ ^ self ].
currentWindow ifNotNil: [ ^ self ].

self enqueuePopupTaskFromEvent: anEvent.
" currentWindow can be nil in case the element is disabled "

]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseDownOutsideEvent: anEvent [

Expand All @@ -187,15 +169,6 @@ ToPopupWindowManager >> mouseEnterEvent: anEvent [
self enqueuePopupTaskFromEvent: anEvent
]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseEnterInElementEvent: anEvent [

popupOnMouseEnter ifFalse: [ ^ self ].
self unqueuePopupTaskIn: anEvent currentTarget.
anEvent anyButtonPressed ifTrue: [ ^ self ].
self enqueuePopupTaskFromEvent: anEvent
]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseLeaveEvent: anEvent [

Expand All @@ -205,15 +178,6 @@ ToPopupWindowManager >> mouseLeaveEvent: anEvent [

]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseLeaveInElementEvent: anEvent [

self unqueuePopupTaskIn: anEvent currentTarget.
closeOnMouseLeave ifFalse: [ ^ self ].
self closeWindow

]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseUpEvent: anEvent [

Expand All @@ -228,23 +192,6 @@ ToPopupWindowManager >> mouseUpEvent: anEvent [
currentWindow close
]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseUpInElementEvent: anEvent [

| delay maxDelay |

currentWindow ifNil: [ ^ self ].
currentWindow popupTimestamp ifNil: [ ^ self ].
maxDelay := self autoCloseOnMouseUpDelay.
" maxDelay if nil -> no auto closing here "
maxDelay ifNil: [ ^ self ].
" check a minimal delay between opening and closing.
The mouse up can occur immediately after the window opening -> don't close the popup window.
After a given delay between down and up, the popup window is closed "
delay := anEvent timestamp - currentWindow popupTimestamp.
delay > maxDelay ifTrue: [ currentWindow close ]
]

{ #category : #'event handling' }
ToPopupWindowManager >> mouseUpOutsideEvent: anEvent [

Expand All @@ -258,23 +205,6 @@ ToPopupWindowManager >> onInstalledIn: anElement [
anElement allowMousePickOutsideEvent.
]

{ #category : #'event handling' }
ToPopupWindowManager >> pickOutsideElementEvent: anEvent [
"
if the original event target is the element with popup or
if the original event target is the popup window then do nothing
"

anEvent originalEvent target ifNotNil: [ :originalTarget |
(originalTarget hasInParentChain: element) ifTrue: [ ^ self ].
self currentWindowDo: [ :w |
(originalTarget hasInParentChain: w) ifTrue: [ ^ self ] ] ].

" ok, mouseUp outside the element and outside of the popup window "
anEvent consume.
self currentWindowDo: [ :w | w close ]
]

{ #category : #'event handling' }
ToPopupWindowManager >> pickOutsideEvent: anEvent [
"
Expand Down

0 comments on commit a491110

Please sign in to comment.