1. Create a new class such as MyListMorph
Object subclass: #MyListMorph
instanceVariableNames: 'list listMenu selectedIndex xCoord yCoord aListMorph '
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Windows'!
2. Modify the initialize method to take in the list you want the PluggableListMorph to display.
initialize: aList x: xNum y: yNum
list _ aList. "Set the list to be displayed"
xCoord _ xNum. "Set the x coordinate of the morph"
yCoord _ yNum. "Set the y coordinate of the morph"
selectedIndex _ 1. "Set the index to be highlighted to be 1."
3. Create the accessor and modifier methods.
list
"get the list that is being displayed"
^list.
listIndex
"get the index of what is currently selected"
^selectedIndex.
listMenu
"get the menu of the PluggableListMorph"
^listMenu.
listIndex: anInteger
"change the selectedIndex"
selectedIndex _ anInteger.
self changed: #listIndex. "note: this is needed, or the list won't update when you click on it!"
listMenu: aMenu
"set the menu of the pluggableListMorph"
listMenu _ aMenu.
4. Create the openView method which will be called to display the PluggableListMorph at the point you specified.
openView: aPoint
| window aListMorph |
aListMorph _ PluggableListMorph
on: self "I am the model that has the list to display"
list: #list "This is how the morph gets the list from me"
selected: #listIndex "This is how the morph knows which item to highlight"
changeSelected: #listIndex: "This is how the morph informs me of a user selection"
menu: #listMenu. "This is how the morph requests a menu for the list"
aListMorph color: Color random. "Get a random color for the morph"
aListMorph x: xCoord y: yCoord. "Set the position of the morph"
^aListMorph openInWord.
5. To use MyListMorph:
w _ MyListMorph new initialize: #list x: 100 y: 200.
w openView.