Menu :)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Menu :)

Stéphane Ducasse
I'm sure that we can do better...


popUpAt: aPoint forHand: hand in: aWorld allowKeyboard: aBoolean
        "Present this menu at the given point under control of the given  
        hand."
        | evt |
        aWorld submorphs
                select: [ :each | (each isKindOf: MenuMorph)
                        and: [each stayUp not]]
                thenCollect: [ :menu | menu delete].

        self items isEmpty
                ifTrue: [^ self].

        (self submorphs
                select: [:m | m isKindOf: UpdatingMenuItemMorph])
                do: [:m | m updateContents].
        self layoutItems.
        "precompute width"
        self
                positionAt: aPoint
                relativeTo: (selectedItem
                                ifNil: [self items first])
                inWorld: aWorld.
        aWorld addMorphFront: self.
        "Acquire focus for valid pop up behavior"
        hand newMouseFocus: self.
        aBoolean
                ifTrue: [hand newKeyboardFocus: self].
        evt := hand lastEvent.
        (evt isKeyboard
                        or: [evt isMouse
                                        and: [evt anyButtonPressed not]])
                ifTrue: ["Select first item if button not down"
                        self moveSelectionDown: 1 event: evt].
        self updateColor.
        self changed

Reply | Threaded
Open this post in threaded view
|

Re: Menu :)

Fernando olivero-2
PUAJ!!!!!
Direct references to the World and its submorphs => secondary effects
Not popping the menu if the items are empty => lost visual feedback
etc…


On Mon, Mar 11, 2013 at 9:57 PM, Stéphane Ducasse
<[hidden email]> wrote:

> I'm sure that we can do better...
>
>
> popUpAt: aPoint forHand: hand in: aWorld allowKeyboard: aBoolean
>         "Present this menu at the given point under control of the given
>         hand."
>         | evt |
>         aWorld submorphs
>                 select: [ :each | (each isKindOf: MenuMorph)
>                         and: [each stayUp not]]
>                 thenCollect: [ :menu | menu delete].
>
>         self items isEmpty
>                 ifTrue: [^ self].
>
>         (self submorphs
>                 select: [:m | m isKindOf: UpdatingMenuItemMorph])
>                 do: [:m | m updateContents].
>         self layoutItems.
>         "precompute width"
>         self
>                 positionAt: aPoint
>                 relativeTo: (selectedItem
>                                 ifNil: [self items first])
>                 inWorld: aWorld.
>         aWorld addMorphFront: self.
>         "Acquire focus for valid pop up behavior"
>         hand newMouseFocus: self.
>         aBoolean
>                 ifTrue: [hand newKeyboardFocus: self].
>         evt := hand lastEvent.
>         (evt isKeyboard
>                         or: [evt isMouse
>                                         and: [evt anyButtonPressed not]])
>                 ifTrue: ["Select first item if button not down"
>                         self moveSelectionDown: 1 event: evt].
>         self updateColor.
>         self changed
>