Login  Register

Re: "whenSelectedItemChanged:" in Spec

Posted by Peter Kenny on Jul 17, 2019; 9:52am
URL: https://forum.world.st/whenSelectedItemChanged-in-Spec-tp5101233p5101278.html

Ben Coman wrote
> I'm not familiar with Spec but I'll have a go...
>
> On Wed, 17 Jul 2019 at 07:03, Steve Quezadas <

> steveeq1@

> > wrote:
>
>> On Tue, Jul 16, 2019 at 7:43 AM Ben Coman <

> btc@

> > wrote:
>>>
>>> On Tue, 16 Jul 2019 at 12:49, Steve Quezadas <

> steveeq1@

> > wrote:
>>> >
>>> > I am running through the "Spec UI Framework" tutorial, and in it has a
>>> widget class inherited from "ComposablePresenter" (ComposablePresenter
>>> subclass: #WidgetClassList). But for some reason the
>>> "whenSelectedItemChanged:" method call does not execute when I select
>>> any item on the GUI list. Is there anything I'm missing?
>>> >
>>> > I posted this earlier on the list, and someone suggested I try
>>> "whenActivatedDo:" or "whenSelectionChangedDo:", but it doesn't do
>>> anything as well. The code looks like this:
>>> >
>>> > whenSelectedItemChanged: aBlock
>>> >     Transcript show: 'should get here; cr.
>>> >
>>> > I am using Pharo 7.
>>>
>>> Can you FileOut the entire sample class and attached it?
>>>
>>> cheers -ben
>>>
>>
>> Ok, I filed out and it exported the file 'WidgetClassList.st' . This is
>> the contents of the file:
>>
>> 'From Pharo7.0.3 of 12 April 2019 [Build information:
>> Pharo-7.0.3+build.158.sha.0903ade8a6c96633f07e0a7f1baa9a5d48cfdf55 (64
>> Bit)] on 16 July 2019 at 3:58:28.785036 pm'!
>> ComposablePresenter subclass: #WidgetClassList
>> instanceVariableNames: 'list'
>> classVariableNames: ''
>> poolDictionaries: ''
>> category: 'QuotesProg'!
>>
>> !WidgetClassList methodsFor: 'initialization' stamp: 'SteveQuezadas
>> 7/10/2019 14:07'!
>> initializeWidgets
>> list := self newList.
>> list items: (AbstractWidgetPresenter allSubclasses
>> sorted: [:a :b | a name < b name ]).
>> self focusOrder add: list.! !
>>
>>
>> !WidgetClassList methodsFor: 'events-shortcuts' stamp: 'SteveQuezadas
>> 7/15/2019 21:40'!
>> whenSelectedItemChanged: aBlock
>> Transcript show: 'got here'; cr.
>> ! !
>
> Looking at ListPresenter>>whenSelectedItemChanged: aBlock
> it is registering aBlock on selectionHolder using #whenChangedDo:
> Reviewing selectionHolder "Code search...>References to it" I see that
> selectionHolder is initialized as an instance of SelectionHolderClass.
>
> So it seems you are expecting whenSelectedItemChanged: to be called
> every time the-selection-is-changed
> when actually it is only called once (by your application) to register
> the block-to-be-called when the-selection-is-changed.
> You don't seem to have done any such registration.
>
> cheers -ben

Essentially ben is right. The method WidgetClassList >> when
SelectedItemChanged: should just relay the message to the component
ListPresenter, in the instvar list, which will carry out the registration as
he describes. The problem is that this method seems to have been replaced by
a debugging method, which simply displays a progress message on the
Transcript. I think all you need is to enter the correct code for this
method as shown in the  'Spec UI Framework' booklet:

WidgetClassList >> whenSelectedItemChanged: aBlock
        list whenSelectedItemChanged: aBlock

This is at least worth a try. You will be sticking to the code as shown in
the booklet.

HTH

Peter Kenny




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html