Probably a silly question with regard to PluggableListMorphs
Ned Konz
ned at bike-nomad.com
Thu Mar 13 18:01:05 UTC 2003
On Friday 14 March 2003 08:56 am, Stef Telford wrote:
> Recently (about a year ago) i tried squeak, and was
> very enthusiastic about it. I could see the power behind it
> but, alas, the underlying paradigm escaped me (or rather the
> integration with Morphic and Smalltalk escaped me). I found
> it very hard to find good 'examples' in the System Browser.
I wouldn't use the SystemBrowser or the Pluggable* widgets as a
Morphic example. These are more complicated than a typical Morph
should be, partly because they are set up to work in both MVC and
Morphic.
But the PluggableListMorph is still a useful piece by itself.
> Now, all that being said, i am having a bit of a problem
> understanding how to get a PluggableListMorph to send out to a
> Transcript window whenever its selected. I thought that this would
> have been under the PluggableListMorphs 'events' in the System
> Browser as something called 'onChange:' or such. Perhaps naive
> but, this is probably a 'paradigm' problem.
It is; it's just a bit subtle (and the class comment is useless).
Looking under "events" we see "mouseUp:". The action that the list
takes happens on mouseUp, rather than mouseDown events.
We see a call to setSelectedMorph: after the list item is found. If we
look at setSelectedMorph:, we see that it calls changeModelSelection:
with an index. changeModelSelection sends its instVar
setIndexSelector to its model.
OK, where's setIndexSelector set up?
Hmmm... only in the initializer:
on: anObject list: getListSel selected: getSelectionSel
changeSelected: setSelectionSel menu: getMenuSel keystroke:
keyActionSel
Let's look for a caller of that. Here's an excerpt from
SMSqueakMapBrowser>>buildMorphicPackagesList
(list _ PluggableListMorph new)
setProperty: #highlightSelector toValue:
#highlightPackagesList:with:;
on: self list: #packagesList
selected: #packagesListIndex changeSelected: #packagesListIndex:
menu: #packagesMenu: keystroke: #packagesListKey:from:.
OK... so here's what the deal is:
on: aModel (the object that gets sent all of these event
notifications)
list: getListSel (a selector that gets sent to return the list of
strings itself)
selected: getSelectionSel (a selector that gets called to get the
current selection index)
changeSelected: (this is what you were looking for; it gets called
with the new index)
menu: (a selector that gets called to update a menu)
keystroke: (a selector that gets sent a keystroke and a morph).
(I notice that #packagesListKey:from: doesn't exist, though; this
leads me to believe that a keystroke in the packages list will blow
up)
> I even can figure out 'what' i think the code should be
> (in my eyes or mind). something like:
> target: Transcript;
> actionSelector: #show: ;
> arguments: { 'you
> clicked"',selection,'"' } ).
Maybe we can do this!
> however, where would this go into the small piece of code
> that I have in my workspace, and also as important is, how did you
> get to this result (perhaps thats a very subjective question) ?
>
> mywin:= NewWorldWindow new setLabel: 'Squeak Test';
> borderColor: Color blue;
> addMorph: (PluggableListMorph new list: #('Hello' 'There');
> extent: 200 at 200;
> autoDeselect: false)
> frame: (0 at 0 corner: 1 at 0.5);
> openInWorld.
Well, let's try that but add the call to #on:...
plm _ nil.
NewWorldWindow new setLabel: 'Squeak Test';
borderColor: Color blue;
addMorph: (plm _ PluggableListMorph new list: #('Hello'
'There');
extent: 200 at 200;
autoDeselect: false)
frame: (0 at 0 corner: 1 at 0.5);
openInWorld.
plm on: Transcript list: nil selected: nil changeSelected: #show:
menu: nil keystroke: nil
Hmm.. Well, the Transcript isn't supplying a list, but when I click in
the list area I see "0" being typed.
So let's make a method so it returns a list. In TranscriptStream,
define
testList
^#(a b c)
Now do the above, but send
plm on: Transcript list: #testList selected: nil changeSelected:
#show: menu: nil keystroke: nil
Aha! Now when I click I see "1", "2", or "3" (or "0") on the
Transcript. However, I don't see the items being highlighted. This is
because the getIndexSelector is nil, so no items are selected.
We can define (again in TranscriptStream)
testGetIndex
^2
plm on: Transcript list: #testList selected: #testGetIndex
changeSelected: #show: menu: nil keystroke: nil
and now we see that the second row is highlighted, always.
Typically you'd have a model of your own that would be sent these
events; it'd keep track of the current selection index and provide
the list.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|