Skip to content

Commit

Permalink
first version with inline menu starting to work
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed Dec 21, 2024
1 parent 298da75 commit 71335f7
Show file tree
Hide file tree
Showing 29 changed files with 515 additions and 157 deletions.
74 changes: 61 additions & 13 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,36 @@ ToSandBox class >> example_HugeIntegerList [
space show
]

{ #category : #window }
ToSandBox class >> example_Inline1 [

| menu popupWindowHandler |
menu := ToElement new
layout: BlLinearLayout vertical;
background: Color transparent;
id: #'red-button';
border: Color red;
size: 100 @ 100;
position: 50 @ 50.

popupWindowHandler := ToPopupWindowManager new.
menu addEventHandler: popupWindowHandler.

popupWindowHandler beInline.
popupWindowHandler windowBuilder: [ :popup :element |
| item |
popup border: Color black.
item := ToElement new
height: 50;
hMatchParent.
item background: Color yellow.
item addEventHandler: (BlEventHandler
on: BlPrimaryClickEvent
do: [ self inform: 'Click' ]).
popup root addChild: item ].
menu openInSpace
]

{ #category : #label }
ToSandBox class >> example_LabelAndSelectableLabelAndTextField [

Expand Down Expand Up @@ -1815,7 +1845,7 @@ ToSandBox class >> example_Popup1 [
yourself.

menu := ToElement new
layout: BlBasicLayout new;
layout: BlLinearLayout vertical;
id: #'red-button';
background: Color red;
size: 100 @ 40;
Expand Down Expand Up @@ -3919,7 +3949,11 @@ ToSandBox class >> example_menuBar3 [
rand := Random new.
frame := ToInnerWindow new.
bar addFiller.

bar addItem: (ToMenuItem new
labelText: 'Inspect';
whenClickedDo: [ frame space root inspect ];
yourself).
bar addFiller.
3 timesRepeat: [
menu := ToMenu new.
menu label: (ToLabel text: 'Levels').
Expand Down Expand Up @@ -6348,13 +6382,36 @@ ToSandBox class >> example_withCheckBox [
| menu sub subsub grp right center left frame |
menu := ToMenu new.
menu labelText: 'File'.
menu addItem: (ToMenuItem new
labelText: 'Inspect';
whenClickedDo: [ menu space root inspect ];
yourself).
menu addItem: (ToMenuItem new labelText: 'Open file').
menu items last icon: (ToImage inner: (self iconNamed: #solidMenu)).
menu addItem: (ToMenuItem new labelText: 'Disabled').
menu items last icon: (ToImage inner: (self iconNamed: #solidMenu)).
menu disableAtPosition: menu items last positionInItemList.


menu addSeparator.

sub := ToMenu new labelText: 'Save All'.
sub windowManager beInline.
sub closeOnMouseEvent: false.
sub addItem: (ToMenuItem new
labelText: 'Locally';
closeOnMouseEvent: false;
yourself).

subsub := ToMenu new labelText: 'Externally'.
subsub windowManager beInline.
subsub closeOnMouseEvent: false.
subsub addItem: (ToMenuItem new labelText: 'Here'; closeOnMouseEvent: false;
yourself).

sub addItem: subsub.
menu addItem: sub.
menu addSeparator.

menu addItem: (ToRadioMenuItem new
label: (ToLabel text: 'Check');
whenClickedDo: [ :event | event currentTarget isChecked traceCr ];
Expand Down Expand Up @@ -6382,16 +6439,7 @@ ToSandBox class >> example_withCheckBox [
left }.
menu addSeparator.

sub := ToMenu new labelText: 'Save All'.
sub addItem: (ToMenuItem new labelText: 'Locally').

subsub := ToMenu new labelText: 'Externally'.
subsub addItem: (ToMenuItem new labelText: 'Here').

sub addItem: subsub.

menu addItem: sub.
menu position: 10 @ 10.
menu position: 10 @ 10.
frame := ToInnerWindow new.
frame pane addChild: menu.
frame openInSpace
Expand Down
4 changes: 2 additions & 2 deletions src/Toplo-Tests/TToElementWithContextMenuTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ TToElementWithContextMenuTest >> testCurrentContextMenuWindow [
self assert: e currentContextMenu notNil.
self
assert: e currentContextMenu class
equals: e contextMenuWindowManager windowClass.
equals: e contextMenuWindowManager popupWindowClass.
^ e
]

Expand Down Expand Up @@ -228,7 +228,7 @@ TToElementWithContextMenuTest >> testHasOpenedContextMenu [
self assert: e currentContextMenu notNil.
self
assert: e currentContextMenu class
equals: e contextMenuWindowManager windowClass.
equals: e contextMenuWindowManager popupWindowClass.
^ e
]

Expand Down
4 changes: 2 additions & 2 deletions src/Toplo-Tests/TToElementWithTooltipTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TToElementWithTooltipTest >> testCurrentTooltipWindow [
self assert: e currentTooltipWindow notNil.
self
assert: e currentTooltipWindow class
equals: e tooltipWindowManager windowClass.
equals: e tooltipWindowManager popupWindowClass.
^ e
]

Expand All @@ -73,7 +73,7 @@ TToElementWithTooltipTest >> testHasOpenedTooltip [
self assert: e currentTooltipWindow notNil.
self
assert: e currentTooltipWindow class
equals: e tooltipWindowManager windowClass.
equals: e tooltipWindowManager popupWindowClass.
^ e
]

Expand Down
20 changes: 10 additions & 10 deletions src/Toplo-Tests/ToAnchoredWindowManagerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ ToAnchoredWindowManagerTest >> testNewWindowEvent2 [
windowManager closeWindow.
]

{ #category : #tests }
ToAnchoredWindowManagerTest >> testPopupWindowClass [

| windowManager |
windowManager := ToAnchoredWindowManager new windowBuilder: [
:anchWin
:element | ].
self assert: windowManager popupWindowClass identicalTo: ToAnchoredWindow
]

{ #category : #tests }
ToAnchoredWindowManagerTest >> testPositionHook [

Expand Down Expand Up @@ -397,16 +407,6 @@ ToAnchoredWindowManagerTest >> testPositionHook3 [
self assert: win bounds inSpace bounds origin equals: 30 @ 30
]

{ #category : #tests }
ToAnchoredWindowManagerTest >> testWindowClass [

| windowManager |
windowManager := ToAnchoredWindowManager new windowBuilder: [
:anchWin
:element | ].
self assert: windowManager windowClass identicalTo: ToAnchoredWindow
]

{ #category : #tests }
ToAnchoredWindowManagerTest >> testWindowOpenRequestClass [

Expand Down
10 changes: 0 additions & 10 deletions src/Toplo-Tests/ToBasicWindowElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ ToBasicWindowElementTest >> testRoot [
self assert: prev parent isNil
]

{ #category : #tests }
ToBasicWindowElementTest >> testRootLayout [

| w l |
w := ToBasicWindowElement new.
l := BlLinearLayout horizontal.
w rootLayout: l.
self assert: w rootLayout identicalTo: l
]

{ #category : #tests }
ToBasicWindowElementTest >> testToFront [

Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Widget-Album/ToLabelEditorManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ToLabelEditorManager >> newEditorForLabel: aLabel [
]

{ #category : #accessing }
ToLabelEditorManager >> windowClass [
ToLabelEditorManager >> popupWindowClass [

^ ToLabelEditorWindow
]
12 changes: 6 additions & 6 deletions src/Toplo-Widget-Album/ToLabelEditorWindow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Class {
#category : #'Toplo-Widget-Album-LabelEditor'
}

{ #category : #'api - displaying' }
ToLabelEditorWindow >> afterCustomizedToFitAnchorRootDo: aBlock [

aBlock value
]

{ #category : #accessing }
ToLabelEditorWindow >> closedEventClass [

Expand All @@ -24,12 +30,6 @@ ToLabelEditorWindow >> installRawStyle [

]

{ #category : #'api - displaying' }
ToLabelEditorWindow >> onPositionChangedToFitAnchorRootDo: aBlock [

aBlock value
]

{ #category : #accessing }
ToLabelEditorWindow >> openedEventClass [

Expand Down
13 changes: 7 additions & 6 deletions src/Toplo-Widget-Menu/ToCheckMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ ToCheckMenuItem >> checkableData: aCheckableData [
^ self shouldNotImplement
]

{ #category : #testing }
ToCheckMenuItem >> closeOnMouseEvent [

^ false
]

{ #category : #accessing }
ToCheckMenuItem >> indeterminateBar [

^ self button indeterminateBar
]

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

super initialize.
closeOnMouseEvent := false
]

{ #category : #skin }
ToCheckMenuItem >> newRawSkin [

Expand Down
2 changes: 1 addition & 1 deletion src/Toplo-Widget-Menu/ToContextMenuManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ToContextMenuManager >> onOpened [
]

{ #category : #accessing }
ToContextMenuManager >> windowClass [
ToContextMenuManager >> popupWindowClass [

^ ToContextMenu
]
Expand Down
9 changes: 2 additions & 7 deletions src/Toplo-Widget-Menu/ToGeneralButtonMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,15 @@ ToGeneralButtonMenuItem >> clickEventClass [
^ button clickEventClass
]

{ #category : #testing }
ToGeneralButtonMenuItem >> closeOnMouseEvent [

^ true
]

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

super initialize.
self button: self buttonClass new.
self button takeFocusOnClick: false.
self button clickEventClass: self buttonClickEventClass.
self layout: self defaultLayout
self layout: self defaultLayout.
closeOnMouseEvent := true
]

{ #category : #skin }
Expand Down
6 changes: 6 additions & 0 deletions src/Toplo-Widget-Menu/ToMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ ToMenu >> initialize [
self addEventHandler: windowManager
]

{ #category : #testing }
ToMenu >> isInline [

^ self windowManager isInline
]

{ #category : #accessing }
ToMenu >> isMenu [

Expand Down
1 change: 1 addition & 0 deletions src/Toplo-Widget-Menu/ToMenuItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ToMenuItem >> buttonClass [
{ #category : #testing }
ToMenuItem >> closeOnMouseEvent [

closeOnMouseEvent ifFalse: [ ^ false ].
^ self isTopMenu not
]

Expand Down
17 changes: 14 additions & 3 deletions src/Toplo-Widget-Menu/ToMenuItemElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ Class {
#superclass : #ToItemElement,
#traits : 'TToMenuItem',
#classTraits : 'TToMenuItem classTrait',
#instVars : [
'closeOnMouseEvent'
],
#category : #'Toplo-Widget-Menu-Basic'
}

{ #category : #testing }
ToMenuItemElement >> closeOnMouseEvent [

^ false
^ closeOnMouseEvent
]

{ #category : #testing }
ToMenuItemElement >> closeOnMouseEvent: aBoolean [

closeOnMouseEvent := aBoolean
]

{ #category : #'adding-removing' }
ToMenuItemElement >> closeSiblingMenuWindow [

self parentItemListHolder ifNil: [ ^ self ].
self parentItemListHolder closeAllWindowsForItemsSatisfying: [ :it | it ~= self ]
self parentItemListHolder closeAllWindowsForItemsSatisfying: [ :it |
it ~= self ]
]

{ #category : #'t - menu window model' }
Expand Down Expand Up @@ -64,7 +74,8 @@ ToMenuItemElement >> includes: anElement [
ToMenuItemElement >> initialize [

super initialize.
self addEventHandler: self defaultEventHandler
self addEventHandler: self defaultEventHandler.
closeOnMouseEvent := false
]

{ #category : #'t - menu window model' }
Expand Down
17 changes: 15 additions & 2 deletions src/Toplo-Widget-Menu/ToMenuItemEventHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,36 @@ ToMenuItemEventHandler >> closeWindowOnEvent: anEvent [
{ #category : #'api - accessing' }
ToMenuItemEventHandler >> eventsToHandle [

^ { BlMouseEnterEvent. BlMouseUpEvent. ToClickableActionPerformedEvent }
^ { BlMouseEnterEvent. BlMouseLeaveEvent. BlMouseUpEvent. ToClickableActionPerformedEvent }
]

{ #category : #'mouse handlers' }
ToMenuItemEventHandler >> mouseEnterEvent: anEvent [

" check event and current target "

(anEvent anyButtonPressed and: [ anEvent currentTarget ~= target ])
ifTrue: [ ^ self ].
target isEnabled ifFalse: [ ^ self ].
target isTopMenu ifTrue: [ ^ self ].
"target closeOnMouseEvent ifFalse: [ ^ self ]."
target closeSiblingMenuWindow.
target isMenu ifFalse: [ ^ self ].
target isOpened ifTrue: [ ^ self ].
target popupEvent: anEvent
]

{ #category : #'mouse handlers' }
ToMenuItemEventHandler >> mouseLeaveEvent: anEvent [
" check event and current target "

(anEvent anyButtonPressed and: [ anEvent currentTarget ~= target ])
ifTrue: [ ^ self ].
target isEnabled ifFalse: [ ^ self ].
target isTopMenu ifTrue: [ ^ self ].
target closeOnMouseEvent ifFalse: [ ^ self ].
target closeSiblingMenuWindow
]

{ #category : #'mouse handlers' }
ToMenuItemEventHandler >> mouseUpEvent: anEvent [
" check event and current target "
Expand Down
Loading

0 comments on commit 71335f7

Please sign in to comment.