Hi Ben,

I think that hard-linking the collections inside the drop block isn't working in that case, so you have to write that without any reference to collection1 and collection2 :)

But, since you're here: why don't I have an API to add or remove items from the ListModel instance? If I was working in VisualWorks, I would have used one of the model subclasses for collections and I would have used its API for adding or removing items... Here writing code like:

list1
        acceptDropBlock: [ :transfer :event :source :receiver :index |
                | c1 c2 l1 l2 |
                l1 := source model model.
                l2 := transfer source model model.
                transfer passenger do: [ :e |
                        l1 insert: e first before: index.
                        l2 remove: e first ] ].

i.e. have the ListModel instance behave as a collection for a subset of the usual collection api.

Thierry

Le 04/04/2014 00:40, Benjamin Van Ryseghem a écrit :
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 <mailto: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.



--
Thierry Goubier
CEA list
Laboratoire des Fondations des Systèmes Temps Réel Embarqués
91191 Gif sur Yvette Cedex
France
Phone/Fax: +33 (0) 1 69 08 32 92 / 83 95

Reply via email to