Menu.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Feb 1997 19:53:41 +0100
changeset 451 95064b26ded1
child 452 b708d60b96b4
permissions -rw-r--r--
intitial checkin

Object subclass:#Menu
	instanceVariableNames:'items'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Support'
!

!Menu class methodsFor:'documentation'!

documentation
"
    not yet finished Menu class - this will eventually replace
    most of the MenuView and PopUpMenu stuff.
    (and hopefully be ST-80 compatible ...)

    For now, only a subset of the full protocol is implemented.

    [author:]
        Claus Gittinger

    [see also:]
        MenuItem
        PopUpMenu
"
! !

!Menu methodsFor:'accessing'!

labels
    "return a collection of labels from my items"

    ^ items collect:[:anItem | anItem label]

    "Created: 25.2.1997 / 19:47:53 / cg"
!

menuItems:aCollectionOfMenuItems groups:groups values:values
    items := aCollectionOfMenuItems.
    values notNil ifTrue:[
        items with:values do:[:anItem :aValue |
            anItem value:aValue 
        ]
    ]

    "Modified: 25.2.1997 / 19:36:28 / cg"
!

valueAt:index
    "return a collection of values from my items"

    ^ (items at:index) value

    "Created: 25.2.1997 / 19:49:41 / cg"
!

values
    "return a collection of values from my items"

    ^ items collect:[:anItem | anItem value]

    "Created: 25.2.1997 / 19:49:29 / cg"
! !

!Menu methodsFor:'converting'!

fromLiteralArrayEncoding:aLiteralEncodedArray
    "read my contents from a aLiteralEncodedArray"

    |items groups values|

    items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray].
    groups := aLiteralEncodedArray at:3.
    values := (aLiteralEncodedArray at:4) decodeAsLiteralArray.
    self menuItems:items groups:groups values:values.

    "extract from PD folder.st:
     #(#Menu #(
                #(#MenuItem 
                        #rawLabel: 'left' 
                        #value: #left ) 
                #(#MenuItem 
                        #rawLabel: 'center' 
                        #value: #center ) 
                #(#MenuItem 
                        #rawLabel: 'right' 
                        #value: #right ) 
              ) 
             #(3 ) 
             nil 
       ) decodeAsLiteralArray
    "

    "Modified: 25.2.1997 / 19:35:20 / cg"
! !

!Menu methodsFor:'startup'!

startUp
    "display the menu as a popUp; return the value associated with the
     selected item, 0 if none was selected"

    |m index|

    "/ for now, use PopUpMenu ....

    m := PopUpMenu labels:self labels.
    index := m startUp. 
    index ~~ 0 ifTrue:[
        ^ self valueAt:index
    ].
    ^ 0

    "   
        |m|
        m := #(#Menu #(
                        #(#MenuItem 
                                #rawLabel: 'left' 
                                #value: #left ) 
                        #(#MenuItem 
                                #rawLabel: 'center' 
                                #value: #center ) 
                        #(#MenuItem 
                                #rawLabel: 'right' 
                                #value: #right ) ) 
                 #(3 ) 
                nil 
        ) decodeAsLiteralArray.
        m startUp
    "

    "Modified: 25.2.1997 / 19:49:08 / cg"
! !

!Menu class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.1 1997-02-25 18:53:27 cg Exp $'
! !