home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP03.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
3KB
|
92 lines
'Smalltalk Textbook Appendix 03'!
Object subclass: #EngiMenuMaker
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Interface'!
EngiMenuMaker comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiMenuMaker class
instanceVariableNames: ''!
!EngiMenuMaker class methodsFor: 'instance creation'!
fromCollection: assocCollection
| labels lines values index |
labels := OrderedCollection new.
lines := OrderedCollection new.
values := OrderedCollection new.
index := 0.
assocCollection do: [:assoc | assoc isNil
ifTrue: [lines add: index]
ifFalse:
[labels add: assoc key.
values add: assoc value.
index := index + 1]].
^PopUpMenu
labelArray: labels asArray
lines: lines asArray
values: values asArray! !
!EngiMenuMaker class methodsFor: 'examples'!
example1
"EngiMenuMaker example1."
| collection menu result |
collection := OrderedCollection new.
collection add: 'again' -> [Transcript cr; show: 'again'].
collection add: 'undo' -> [Transcript cr; show: 'undo'].
collection add: nil.
collection add: 'copy' -> [Transcript cr; show: 'copy'].
collection add: 'cut' -> [Transcript cr; show: 'cut'].
collection add: 'paste' -> [Transcript cr; show: 'paste'].
collection add: nil.
collection add: 'do it' -> [Transcript cr; show: 'do it'].
collection add: 'print it' -> [Transcript cr; show: 'print it'].
collection add: 'inspect' -> [Transcript cr; show: 'inspect'].
menu := EngiMenuMaker fromCollection: collection.
result := menu startUp.
result value!
example2
"EngiMenuMaker example2."
| collection menu result |
collection := OrderedCollection new.
collection add: 'editing' ->
[| editing |
editing := OrderedCollection new.
editing add: 'again' -> [Transcript cr; show: 'again'].
editing add: 'undo' -> [Transcript cr; show: 'undo'].
editing add: nil.
editing add: 'copy' -> [Transcript cr; show: 'copy'].
editing add: 'cut' -> [Transcript cr; show: 'cut'].
editing add: 'paste' -> [Transcript cr; show: 'paste'].
EngiMenuMaker fromCollection: editing] value.
collection add: 'execution' ->
[| execution |
execution := OrderedCollection new.
execution add: 'do it' -> [Transcript cr; show: 'do it'].
execution add: 'print it' -> [Transcript cr; show: 'print it'].
execution add: 'inspect' -> [Transcript cr; show: 'inspect'].
EngiMenuMaker fromCollection: execution] value.
menu := EngiMenuMaker fromCollection: collection.
result := menu startUp.
result value! !