Dragging from a list field

J. Landman Gay jacque at hyperactivesw.com
Sun Aug 28 18:06:11 EDT 2005


Trevor DeVore wrote:

> For the project I implemented this in, drag/drop from a palette is  
> something that is done hundreds of times.  I didn't want to add any  
> modifier keys, etc. for something being done so often so I just added  
> code in mouseDown to check for a change in the selection.  That way I  
> could have my repeat loop and display data on the selected item.

Thanks Trevor, I got a variation on this approach to work. Basically I 
set a custom property each time the selection changes in the list field. 
The custom property contains the selected text of the current line. Then 
on mouseDown I compare the current selection to the custom property 
contents and if they are different, I pass mouseDown so that 
selectionChanged will trigger. If they are the same, I assume a drag and 
set the dragData.

If the user clicks the same line as before but does not do a drag, the 
engine implements a drag-in-place that doesn't move any text, so it 
appears that nothing happened, which is good.

Once the mouseDown handler sets the dragData, the usual mouse messages 
are not sent and drag messages are sent instead. I can see why this 
might be the desirable behavior in most cases. When you are dragging, 
you aren't selecting, so you presumably don't need all the click 
messages such as selectionChanged and mouseUp. You get dragEnter, 
dragLeave, dragMove, dragDrop, etc. instead.

While trying to use mouseStillDown and/or dragMove to implement all 
this, as per other suggestions, I found that both were able to set the 
dragData okay but no dragDop was sent to the target field and so the 
drag would not complete. Then I was stuck with a "drag" cursor that 
wouldn't go away until I did a second click on the target field. At that 
point the data was dropped, but this behavior wasn't acceptable for 
general use.

Here is the skeleton of what I have, which pretty much works, though I 
will probably refine it some more. It does require that the user first 
click on the line to select it before they can drag it. If anyone wants 
to play with this technique and post improvements, I'm all eyes.

In the list field:

on selectionChanged
   put the selectedText of me into tTopic
   if the cCurTopic of me = tTopic then exit selectionChanged
   set the cCurTopic of me to tTopic -- store for later reference
   -- display content here, based on selection
end selectionChanged

on mouseDown
   if the cCurTopic of me <> the selectedText of me
   then pass mouseDown -- a new selection; selectionChanged will run
   set the dragData["text"] to the selectedtext of me -- drag will run
end mouseDown


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list