Mouse events in FastTableModel subclass [Spec]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mouse events in FastTableModel subclass [Spec]

Pharo Smalltalk Users mailing list
Hi,
I've created a PictureListModel class to  manage a list of pictures.
It's a subclass FastTableModel and its
adapter (MorphicPictureListAdapter) is a subclass of MorphicFastTableAdapter.

The widget works correctly: it shows a scrollable list of pictures.

The problem is that it cannot handle “click” and “double clicks” events,
i.e. double clicking on a list item does nothing, even setting
"handlesDoubleClick:" to true.

I've tried to figure out the mechanism, looking into the
FastTableModel, its Morphic adapter and reading the "BuildingUIWithSpec"
doc, but I didn't get it.

Where could I find some hint to manage "click" and "double click" events
in FastTableModel?

Thanks,
Matteo


Reply | Threaded
Open this post in threaded view
|

Re: Mouse events in FastTableModel subclass [Spec]

matteob8
Update: problem fixed by adding an "Announcer" to the "double click"
event, i.e.:

morWidget
        onAnnouncement: FTStrongSelectionChanged
        send: #doubleClick:
        to: self.

Where "morWidget" is the morphic object representing a list of pictures,
 "self" is the "MorphicPictureListAdapter", which creates
the "morWidget" object.
The method "doubleClick:" contains the actions to be performed when the
event is triggered.

Note that, in the "FTAnnouncement" hierachy, the "double click" event is
represented by the class "FTStrongSelectionChanged", which I found a
little tricky.

Bye,
Matteo

Reply | Threaded
Open this post in threaded view
|

Re: Mouse events in FastTableModel subclass [Spec]

Ben Coman
Thanks for the follow up.  This will probably be useful for me to know later.
cheers -ben

On Fri, Jan 6, 2017 at 11:34 PM, Matteo <[hidden email]> wrote:

> Update: problem fixed by adding an "Announcer" to the "double click"
> event, i.e.:
>
> morWidget
>         onAnnouncement: FTStrongSelectionChanged
>         send: #doubleClick:
>         to: self.
>
> Where "morWidget" is the morphic object representing a list of pictures,
>  "self" is the "MorphicPictureListAdapter", which creates
> the "morWidget" object.
> The method "doubleClick:" contains the actions to be performed when the
> event is triggered.
>
> Note that, in the "FTAnnouncement" hierachy, the "double click" event is
> represented by the class "FTStrongSelectionChanged", which I found a
> little tricky.
>
> Bye,
> Matteo
>

Reply | Threaded
Open this post in threaded view
|

Re: Mouse events in FastTableModel subclass [Spec]

Henrik-Nergaard
In reply to this post by matteob8
You can get the selection directly in FastTableModel by Setting #handlesDoubleClick: to true and the event handler block using #doubleClickAction:

---------------------
        FastTableModel new
                icons: [ :e | example iconNamed: #forwardIcon ];
                items: (1 to: 10) asArray;
                handlesDoubleClick: true;
                doubleClickAction: [ :ftStrong | ftStrong inspect ];
                whenSelectedItemChanged: [ :new :old :something :announcment | { new . old . something . announcment } inspectOnce ];
                openWithSpec.
-----------------------

Best regards,
Henrik

-----Opprinnelig melding-----
Fra: Pharo-users [mailto:[hidden email]] På vegne av Matteo
Sendt: 06 January 2017 16:35
Til: [hidden email]
Emne: Re: [Pharo-users] Mouse events in FastTableModel subclass [Spec]

Update: problem fixed by adding an "Announcer" to the "double click"
event, i.e.:

morWidget
        onAnnouncement: FTStrongSelectionChanged
        send: #doubleClick:
        to: self.

Where "morWidget" is the morphic object representing a list of pictures,  "self" is the "MorphicPictureListAdapter", which creates the "morWidget" object.
The method "doubleClick:" contains the actions to be performed when the event is triggered.

Note that, in the "FTAnnouncement" hierachy, the "double click" event is represented by the class "FTStrongSelectionChanged", which I found a little tricky.

Bye,
Matteo

Reply | Threaded
Open this post in threaded view
|

Re: Mouse events in FastTableModel subclass [Spec]

matteob8
Hi Henrik,
        thanks for the hint. (I think that the code snippet misses the
definition of the "example" variable).


        Unfortunately the "problem" is located in the "Morphic Side" of the
"FastTableModel" class.

        Specifically the "FastTableModel" class relies on the
"MorphicFastTableAdapter" which in turn (surprisingly) uses the
"FTPluggableIconListMorphAdaptor", and not the "FTTableMorph" as I would
expect.

The announcer for the "double click" is coded in the
"FTPluggableIconListMorphAdaptor>>initializeSelections", by the
announcement "FTStrongSelectionChanged", as follow:

---------------------
initializeSelections
    self
        onAnnouncement: FTSelectionChanged
        send: #selectionChanged:
        to: self.
    self
        onAnnouncement: FTStrongSelectionChanged
        send: #strongSelectionChanged:
        to: self.
---------------------

In my case "PictureListModel" is a subclass of "FastTableModel" and it
has been connected to a "FTTableMorph" object (through  the
"MorphicPictureListAdapter") and NOT to a
"FTPluggableIconListMorphAdaptor" one.
In this way the "double click" has been lost.

I've wanted to avoid the "FTPluggableIconListMorphAdaptor" because it
seems a bridge for legacy code, as reported in a previous post, see

http://forum.world.st/Spec-Setting-rows-height-of-a-pictures-list-tp4920861p4922263.html.


Cheers,
Matteo

On 06/01/17 18:20, Henrik Nergaard wrote:

> You can get the selection directly in FastTableModel by Setting #handlesDoubleClick: to true and the event handler block using #doubleClickAction:
>
> ---------------------
> FastTableModel new
> icons: [ :e | example iconNamed: #forwardIcon ];
> items: (1 to: 10) asArray;
> handlesDoubleClick: true;
> doubleClickAction: [ :ftStrong | ftStrong inspect ];
> whenSelectedItemChanged: [ :new :old :something :announcment | { new . old . something . announcment } inspectOnce ];
> openWithSpec.
> -----------------------
>
> Best regards,
> Henrik
>
> -----Opprinnelig melding-----
> Fra: Pharo-users [mailto:[hidden email]] På vegne av Matteo
> Sendt: 06 January 2017 16:35
> Til: [hidden email]
> Emne: Re: [Pharo-users] Mouse events in FastTableModel subclass [Spec]
>
> Update: problem fixed by adding an "Announcer" to the "double click"
> event, i.e.:
>
> morWidget
> onAnnouncement: FTStrongSelectionChanged
> send: #doubleClick:
> to: self.
>
> Where "morWidget" is the morphic object representing a list of pictures,  "self" is the "MorphicPictureListAdapter", which creates the "morWidget" object.
> The method "doubleClick:" contains the actions to be performed when the event is triggered.
>
> Note that, in the "FTAnnouncement" hierachy, the "double click" event is represented by the class "FTStrongSelectionChanged", which I found a little tricky.
>
> Bye,
> Matteo
>