MenuItem.st
author Claus Gittinger <cg@exept.de>
Thu, 06 Mar 1997 15:16:03 +0100
changeset 494 ce8c074d5e6b
parent 490 ebe88e50b29a
child 578 7e0f62d9bc47
permissions -rw-r--r--
checkin from browser

Object subclass:#MenuItem
	instanceVariableNames:'enabled label value nameKey adornment'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Support'
!

Object subclass:#MenuItemAdornment
	instanceVariableNames:'color indication submenu'
	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:index
    "ignored for now"

    "Modified: 25.2.1997 / 20:27:12 / cg"
!

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"
!

hasSubmenu
    ^ self adornment submenu notNil

    "Created: 25.2.1997 / 20:56:20 / cg"
!

isEnabled
    ^ enabled ? true

    "Created: 25.2.1997 / 19:39:17 / cg"
!

label
    ^ label

    "Created: 25.2.1997 / 19:48:16 / cg"
!

label:aString
    label := aString

    "Created: 25.2.1997 / 19:55:16 / cg"
!

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"

    ^ nil
!

submenu
    ^ self adornment submenu

    "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:'converting'!

fromLiteralArrayEncoding:aLiteralEncodedArray
    "read my contents from a aLiteralEncodedArray"

    2 to:aLiteralEncodedArray size by:2 do:[:i |
        |selector value|

        selector := aLiteralEncodedArray at:i.
        value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.

        self perform:selector with:value
    ].

    "
     #( #MenuItem #rawLabel: 'left' #value: #left )
         decodeAsLiteralArray
    "

    "Modified: 25.2.1997 / 19:24:22 / cg"
!

literalArrayEncoding
    "return myself encoded as a literal array"

    |coll|

    coll := OrderedCollection new.
    coll add:#MenuItem.
    coll add:#label: ; add:(label literalArrayEncoding).
    coll add:#value: ; add:(value literalArrayEncoding).
"/    coll add:#nameKey: ; add:(nameKey literalArrayEncoding).
    coll add:#enabled: ; add:(enabled literalArrayEncoding).
    ^ coll asArray
! !

!MenuItem methodsFor:'private - accessing'!

adornment
    adornment isNil ifTrue:[
        adornment := MenuItemAdornment new
    ].
    ^ adornment

    "Created: 25.2.1997 / 20:57:05 / cg"
! !

!MenuItem::MenuItemAdornment methodsFor:'accessing'!

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"
!

submenu
    "return the value of the instance variable 'submenu' (automatically generated)"

    ^ submenu

    "Created: 25.2.1997 / 20:59:28 / cg"
!

submenu:something
    "set the value of the instance variable 'submenu' (automatically generated)"

    submenu := something.

    "Created: 25.2.1997 / 20:59:28 / cg"
! !

!MenuItem class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.5 1997-03-05 16:06:31 ca Exp $'
! !