problem with drag-dropping a text string

Peter Brigham pmbrig at gmail.com
Tue Apr 8 18:34:24 EDT 2008


I am trying to modify the dragdata before a text string is dropped,  
and it's not working, so I must be doing something wrong. The idea is  
for the user to select some text from one field (unlocked), and drag  
it to to a target field (unlocked), and I want to insert a tab in  
place of a space in the text and drop the modified text into the  
target field. Both fields are in the same group on the same card.  
Here's my script (in the target field):

on dragDrop
   set the dragaction to "copy"
   put the dragData into mLine -- works fine, so does using the  
'dragData["text"]'
   set the itemdelimiter to tab
   put item 2 of mLine into mChunk
   put length(word 1 of mChunk) into w
   put tab into char w+1 of mChunk
   put mChunk into item 2 of mLine
   set the dragdata to mLine
   -- set the dragdata["text"] to mLine -- I tried this too
   pass dragDrop
end dragDrop

There are no other handlers in the script, and no other dragdrop  
handlers in the group, card, or stack scripts.

The original selected text is dropped without modification into the  
target field. The dragDrop handler is getting triggered, since  
setting a breakpoint and doing the drag-drop opens up the script in  
the debugger, and the data is manipulated correctly as I step through  
the script, so at the end mLine contains the proper string -- but the  
original string is what appears in the target field, even when I  
substitute 'set the dragdata to "something inane"'. So the command  
'set the dragData to...' is being ignored, apparently.

I tried instead modifying the dragdata in a dragStart handler in the  
starting field, but it seems that the dragdata is not yet set at that  
point, since "put the dragdata into mLine" shows mLine = empty in the  
debugger, which doesn't really make sense -- shouldn't the engine  
know by that point what the dragdata is?

I tried putting a 'wait 25 millisecs with messages' line just after  
setting the dragdata, before passing the dragdrop, figuring maybe  
setting the dragdata property takes a little time for some reason  
(but why should it?) -- still no go.

Uh oh, another problem -- suddenly, setting the dragAction to "copy"  
now doesn't work. I swear it was working before. I just tried setting  
the dragaction in a dragstart handler and in a dragleave handler in  
the starting field, as well as in the dragdrop handler in the target  
field, but in all cases the text is moved instead of being copied,  
unless of course I hold down the optionkey. I *swear* it was working  
properly before...! Oh -- the problem is the wait with messages  
command that I just put in -- this apparently allows the dragaction  
to reset to "none." When I take out the wait command the text is  
copied and not moved. Well, that's a relief. But the original problem  
remains.

This is the first time I've messed around with drag/drop, but there  
seems to be a problem setting the dragddata. Is there something I'm  
overlooking? I'm using a Mac iBook G4, OSX 10.4.1, Studio 2.9 build  
610. Running in the IDE -- but suspending development tools doesn't  
work, so it's not an obvious IDE problem. Restarting Rev didn't do it  
either. Help!

Peter M. Brigham
pmbrig at gmail.com



More information about the use-livecode mailing list