here is a "hackish" solution:

        collection1 := #(1 2 3 4 5) asOrderedCollection.
        collection2 := #($a $b $c $d $e) asOrderedCollection.
        list1 := ListModel new.
        list1 items: collection1.
        list1 dragEnabled: true.
        list1 dropEnabled: true.
         list1
                acceptDropBlock: [ :transfer :event :source :receiver
:index |
                        | c1 c2 l1 l2 |
                        l1 := source model model.
                        c1 := l1 listItems.
                        l2 := transfer source model model.
                        c2 := l2 listItems.
                        transfer passenger
                                do: [ :e |
                                        c1 insert: e first before: index.
                                        c2 remove: e first ].
                        l1 items: c1.
collection1 removeAll; addAll: c1.
                        l2 items: c2.
collection2 removeAll; addAll: c2. ].
        list1 openWithSpec.
        list2 := ListModel new.
        list2 items: collection2.
        list2 dragEnabled: true.
        list2 dropEnabled: true.
        list2 acceptDropBlock: [ :transfer :event :source :receiver :index
|
self halt ].
        ^ list2 openWithSpec.

The problem here is that by default, the list items are sorted, setting the
listItems with a copy.
Maybe it would be better to actually do not sort until one sets a real
sortingBlock.

Ben


2014-04-03 22:55 GMT+02:00 MartinW <w...@fastmail.fm>:

> Goubier Thierry wrote
> > Another approach, that I would use, is to put more complex objects
> > inside the lists. Thoses objects would know how to get added / removed
> > from their respective collections, and then I would propagate collection
> > changes to the ListModel instances.
>
> That sounded promising. I made a Collectible class. It's instances know how
> to add themselves to a collection (i'm not sure if that's a good idea, but
> as experiment..)
>
> The problem is, i never get to these objects in my acceptDropBlock. In
>
> list1 acceptDropBlock: [ :transfer :event :source :receiver :index |
>    transfer passenger do: [:element | element addSelfToCollection:
> collection1] ].
>
> the element is only a ByteString - the name of my Collectible object. :(
>
> Are there other possibilities if i do not use Spec?
>
>
>
> --
> View this message in context:
> http://forum.world.st/Drag-and-drop-items-between-list-views-tp4752285p4752625.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>

Reply via email to