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.
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
"
"
#(#Menu #(
#(#MenuItem
#label: 'Straighten Up' )
#(#MenuItem
#label: 'Inspect' )
#(#MenuItem
#label: 'Coredump' )
)
#(3 )
#(#straightenUp #inspect #halt )
) decodeAsLiteralArray startUp
"
"
#(#Menu #(
#(#MenuItem
#label: 'Straighten Up' )
#(#MenuItem
#label: 'Inspect' )
#(#MenuItem
#label: 'Coredump' )
)
#(3 )
#(1 2 3 )
) decodeAsLiteralArray startUp
"
"Modified: 25.2.1997 / 20:00:18 / 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 val index|
"/ for now, use PopUpMenu ....
m := PopUpMenu labels:self labels.
index := m startUp.
index ~~ 0 ifTrue:[
val := self valueAt:index.
val notNil ifTrue:[
^ val
]
].
^ 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:59:35 / cg"
! !
!Menu class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.2 1997-02-25 19:21:47 cg Exp $'
! !