Ok, look at that code:

        | collection1 collection2 list1 list2 |
        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 |
                transfer passenger do:
                        [:e |
                        collection1 insert: e first before: index.
                        collection2 remove: e first].
                list1 items: collection1.
                list2 items: collection2  ].
        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

Now you can drag and drop from list2 to list1, and I think the code is good for drag and drop of multiple items.

Thierry

Le 02/04/2014 17:08, MartinW a écrit :
I tried the following, but i do not know what to do in the acceptDropBlock.
It seems the receiver in the block is only an item in a list, but how do i
get the receiving list/collection?
What i want to achieve is that a user can drag the '1' from list1 to list2
and the resulting collections will then be collection1: (2 3 4 5)
collection2: ($a $b $c $d $e 1) and the lists will be updated accordingly.


        | collection1 collection2 list1 list2 |

        collection1 := #(1 2 3 4 5).
        collection2 := #($a $b $c $d $e).
        
        list1 := ListModel new.
        list1 items: collection1.
        list1 dragEnabled: true.
        list1 dropEnabled: true.
        list1 acceptDropBlock: [ :transfer :event :source :receiver :index |  
self
halt ].
        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.


Goubier Thierry wrote
yes, most list-like widgets can drag and drop. Feedback when inserting
items in lists could be improved, however (i.e. you can drop on a list
item, but I've never seen the feedback for dropping between list items).
Le 02/04/2014 16:09, MartinW a écrit :
i have to make a UI where users can sort items (sentences) into different
collections by dragging and dropping them between list views. Is this
possible with the widgets currently available in Pharo?





--
View this message in context: 
http://forum.world.st/Drag-and-drop-items-between-list-views-tp4752285p4752328.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