Object subclass:#MenuItem
instanceVariableNames:'enabled label value nameKey adornment'
classVariableNames:''
poolDictionaries:''
category:'Views-Support'
!
Object subclass:#MenuItemAdornment
instanceVariableNames:'color indication submenu shortcutKey labelText
accessCharacterPosition'
classVariableNames:''
poolDictionaries:''
privateIn:MenuItem
!
!MenuItem class methodsFor:'documentation'!
documentation
"
not yet finished MenuItem 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
"
! !
!MenuItem class methodsFor:'instance creation'!
labeled:aString
^ self new label:aString
! !
!MenuItem methodsFor:'accessing'!
accessCharacterPosition
"get the index of the access character in the label text or string, or nil if none
"
adornment notNil ifTrue:[
^ adornment accessCharacterPosition
].
^ nil
!
accessCharacterPosition:index
"set the index of the access character in the label text or string, or nil if none
"
(index isNil and:[adornment isNil]) ifFalse:[
self adornment accessCharacterPosition:index
]
!
indication
"not yet supported
"
^ true
!
indication:anIndication
"not yet supported
"
!
label
^ label
"Created: 25.2.1997 / 19:48:16 / cg"
!
label:aString
label := aString
"Created: 25.2.1997 / 19:55:16 / cg"
!
nameKey
^ nameKey
!
nameKey:aNameKey
nameKey := aNameKey.
!
rawLabel
^ label
"Created: 25.2.1997 / 19:48:16 / cg"
!
rawLabel:aString
label := aString
"Created: 25.2.1997 / 19:11:02 / cg"
!
shortcutKeyCharacter
"ignored for now"
adornment notNil ifTrue:[
^ adornment shortcutKeyCharacter
].
^ nil
!
shortcutKeyCharacter:aKey
"set the key to press to select the menu item from the keyboard
"
(aKey isNil and:[adornment isNil]) ifFalse:[
self adornment shortcutKeyCharacter:aKey
]
!
submenu
adornment notNil ifTrue:[
^ adornment submenu
].
^ nil
"Created: 25.2.1997 / 20:57:24 / cg"
!
submenu:aMenu
self adornment submenu:aMenu
"Created: 25.2.1997 / 20:56:20 / cg"
!
value
^ value
"Created: 25.2.1997 / 19:50:14 / cg"
!
value:something
value := something
"Created: 25.2.1997 / 19:11:13 / cg"
! !
!MenuItem methodsFor:'accessing behavior'!
disable
enabled := false
"Created: 25.2.1997 / 19:39:09 / cg"
!
enable
enabled := true
"Created: 25.2.1997 / 19:39:00 / cg"
!
enabled:aBoolean
enabled := aBoolean
"Created: 25.2.1997 / 19:39:27 / cg"
! !
!MenuItem methodsFor:'converting'!
fromLiteralArrayEncoding:aLiteralEncodedArray
"read my contents from a aLiteralEncodedArray"
2 to:aLiteralEncodedArray size by:2 do:[:i |
|selector value|
selector := aLiteralEncodedArray at:i.
selector == #labelImage: ifFalse:[
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.
self perform:selector with:value
]
].
"
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left )
decodeAsLiteralArray
"
"Modified: 25.2.1997 / 19:24:22 / cg"
!
literalArrayEncoding
"return myself encoded as a literal array"
|coll key|
coll := OrderedCollection new.
coll add:#MenuItem.
coll add:#label: ; add:(label literalArrayEncoding).
coll add:#nameKey: ; add:(nameKey literalArrayEncoding).
coll add:#enabled: ; add:(enabled literalArrayEncoding).
value notNil ifTrue:[
coll add:#value: ; add:(value literalArrayEncoding).
].
(key := self shortcutKeyCharacter) notNil ifTrue:[
coll add:#shortcutKeyCharacter: ; add:(key literalArrayEncoding)
].
(key := self accessCharacterPosition) notNil ifTrue:[
coll add:#accessCharacterPosition: ; add:(key literalArrayEncoding)
].
^ coll asArray
! !
!MenuItem methodsFor:'private - accessing'!
adornment
adornment isNil ifTrue:[
adornment := MenuItemAdornment new
].
^ adornment
"Created: 25.2.1997 / 20:57:05 / cg"
! !
!MenuItem methodsFor:'queries'!
hasSubmenu
^ self subMenu notNil
"Created: 25.2.1997 / 20:56:20 / cg"
!
isEnabled
^ enabled ? true
"Created: 25.2.1997 / 19:39:17 / cg"
! !
!MenuItem::MenuItemAdornment methodsFor:'accessing'!
accessCharacterPosition
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)"
^ accessCharacterPosition!
accessCharacterPosition:something
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)"
accessCharacterPosition := something.!
color
"return the value of the instance variable 'color' (automatically generated)"
^ color
"Created: 25.2.1997 / 20:59:28 / cg"
!
color:something
"set the value of the instance variable 'color' (automatically generated)"
color := something.
"Created: 25.2.1997 / 20:59:28 / cg"
!
indication
"return the value of the instance variable 'indication' (automatically generated)"
^ indication
"Created: 25.2.1997 / 20:59:28 / cg"
!
indication:something
"set the value of the instance variable 'indication' (automatically generated)"
indication := something.
"Created: 25.2.1997 / 20:59:28 / cg"
!
labelText
"get the text appear as the menu label
"
^ labelText
!
labelText:something
"set the text appear as the menu label
"
labelText := something.
!
shortcutKeyCharacter
"get the key to press to select the menu item from the keyboard
"
^ shortcutKey
!
shortcutKeyCharacter:something
"set the key to press to select the menu item from the keyboard
"
shortcutKey := something.
!
submenu
"get the submenu or nil
"
^ submenu
"Created: 25.2.1997 / 20:59:28 / cg"
!
submenu:something
"set the submenu or nil
"
submenu := something.
"Created: 25.2.1997 / 20:59:28 / cg"
! !
!MenuItem class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.8 1997-05-22 11:39:07 ca Exp $'
! !