Help needed with drag and drop

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Help needed with drag and drop

Post by user#606 » Mon Nov 15, 2010 11:43 pm

I wish to drag a file name to a field, drop it and copy that content to another field and clear the "dropped into" field.

on dragDrop
beep
put field "droppatch" into field "file 1"
put empty into field "droppatch"
pass dragDrop
end dragDrop

What happens is the field name drops ok, but it just stays there hilighted and nothing apears in the other field.
The BEEP works (used to see what is happening).
If I follow with another file, the earlier drop gets copied to the other field.

What have I missed?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Help needed with drag and drop

Post by Dixie » Tue Nov 16, 2010 1:33 am

606...

Code: Select all

on dragDrop
   put the dragData["text"]into line 1 of fld 1
   put URL ("file:" & line 1 of me) into fld 2
   put empty into fld 1
end dragDrop
Is this what you want to do ?... I made a stack with 2 fields... put the above script into the script of fld 1.... and then drag a text file onto fld 1. The contents of the textfile appear in field 2.

be well

Dixie

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: Help needed with drag and drop

Post by user#606 » Tue Nov 16, 2010 10:46 am

Thank you for your suggestion Dixi, however it is not what I want at all.
Perhaps I simplified the task too much.

The actual issue is that I want to drag a file address (not the file) onto a common drop zone.
Depending on the prefix of the file name, the address will be directed to a particular field.

I want the dropped address text to go from the drop zone to the destination and clear the drop zone as a single operation.
Just as you would move a file to the trash bin!

What I dont understand from the simple code is that it must be working or the beep would not sound, though the copy of text and subsequent clearing of the drop zone does not. If I put the code in a button and click it, it works!

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Help needed with drag and drop

Post by Klaus » Tue Nov 16, 2010 12:45 pm

Hi 606,

Code: Select all

on dragDrop
      beep  
      put field "droppatch" into field "file 1"
      put empty into field "droppatch"
## At this point the actual dropping of the filename has NOT yet taken playe!
## That's why the target field remains empty when this is executed the first time!

      pass dragDrop
## NOW the filename is in the dropzone, but its too late :-)
end dragDrop
We nee to let the drop occur first and then take the other action AFTer this has happened
Try somehting like this:

Code: Select all

on dragDrop
      beep
      send "the_action" to me in 10 millisesc
      ## enough time to drop the filename
  
      pass dragDrop
end dragDrop

command the_action
      put field "droppatch" into field "file 1"
      put empty into field "droppatch"
end the_action
Not tested but should work! (Famous last words :D)

Best

Klaus

a-revuser
Posts: 23
Joined: Fri Dec 04, 2009 10:23 am

Re: Help needed with drag and drop

Post by a-revuser » Tue Nov 16, 2010 4:52 pm

I have almost resolved the problem.
I have used this code
on dragDrop
put the dragData["text"]into line 1 of field "file 1"
end dragDrop

and it does everything necessary.
Just one odd thing, the insertion point is left (not flashing though) in the drop zone.
I am not sure what I expected to happen with it, perhaps if it just vanished would be good.
The mouse works fine afterwards and text cannot be entered at the insertion point, so is probably just a cosmentic thing. Any comments?

Thank you both Dixie and Klaus, both answers have shown the way.

a-revuser
Posts: 23
Joined: Fri Dec 04, 2009 10:23 am

Re: Help needed with drag and drop

Post by a-revuser » Tue Nov 16, 2010 4:52 pm

I have almost resolved the problem.
I have used this code
on dragDrop
put the dragData["text"]into line 1 of field "file 1"
end dragDrop

and it does everything necessary.
Just one odd thing, the insertion point is left (not flashing though) in the drop zone.
I am not sure what I expected to happen with it, perhaps if it just vanished would be good.
The mouse works fine afterwards and text cannot be entered at the insertion point, so is probably just a cosmentic thing. Any comments?

Thank you both Dixie and Klaus, both answers have shown the way.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Help needed with drag and drop

Post by Klaus » Tue Nov 16, 2010 5:06 pm

Hi a-revuser,

just add a "select empty" at the end of your handler!


Best

Klaus

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: Help needed with drag and drop

Post by user#606 » Tue Nov 16, 2010 11:53 pm

I cannot make the select empty work at all.
I have also noticed the insertion point is not working properly in the script editor since the dragdrop command.
I have to exit and restart rev to get back to normal.
this simple action is far from satisfactory.
any good ideas on this one?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Help needed with drag and drop

Post by Dixie » Wed Nov 17, 2010 12:56 am

606...

I have attached a stack... look at the scripts of fld 1 and fld 2... the insertion point now disappears...

be well

Dixie
Attachments
untitled folder.zip
(2.1 KiB) Downloaded 315 times

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help needed with drag and drop

Post by Mark » Wed Nov 17, 2010 11:10 am

User,

You encountered a bug in the script editor. Whenever you drag anything over the script editor, you will get stuck. Always close the script editor before starting a drag-and-drop.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

a-revuser
Posts: 23
Joined: Fri Dec 04, 2009 10:23 am

Re: Help needed with drag and drop

Post by a-revuser » Wed Nov 17, 2010 11:51 am

Hi Dixie, Klaus,
I attach an extract of the stack with basic instructions so you can see the effect for yourself.
With Dixie's stack, it did not work with the drag in from a file list in Explorer. This is key to the process.
Of course, no script is actualy required to drag text from one field to another, if only it were easy from some other source.

I hope you can help

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Help needed with drag and drop

Post by Dixie » Wed Nov 17, 2010 11:54 am

Hi 606...

I don't see the extract you mention..

Dixie

a-revuser
Posts: 23
Joined: Fri Dec 04, 2009 10:23 am

Re: Help needed with drag and drop

Post by a-revuser » Wed Nov 17, 2010 11:57 am

I am trying to sort out where it went.
I have uploaded the file twice so far, once as a livecoad and once as a zipfile. Sorry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help needed with drag and drop

Post by Mark » Wed Nov 17, 2010 12:01 pm

User,

Are you dragging a file name (text) or a file?

Mark
Last edited by Mark on Wed Nov 17, 2010 12:49 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Help needed with drag and drop

Post by Dixie » Wed Nov 17, 2010 12:01 pm

err... email ?... john@ihouse.on-rev.com

Dixie

Post Reply