Drag and Drop a single line of text

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 606
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Drag and Drop a single line of text

Post by Simon Knight » Thu Jan 12, 2017 12:18 am

Hi,
I have spent the last few hours experimenting with drag and drop. While I have written code that works it feels a clumsy and over complicated so I would appreciate any comments. The code below is in a behavior button used by two list fields. The aim is to allow the user to select complete lines/rows of text and drag them either in the same list (field) or across to a second field. Drag and drop should not occur if the field is locked. The code is here and I have attached a demo stack. Thanks

Code: Select all

local sSourceLineNo
local sNewLineNo


on dragEnter --sent to destination control
if the locktext of me is false then
   set the dragAction to "copy"
else
   set the dragAction to "none"
   end if
pass dragEnter  -- this causes the cursor to be displayed

end dragEnter



on dragMove --sent to destination control
   
   set the hilitedlines of me to (word 2 of the mouseline)

end dragMove

On dragdrop --sent to destination control
   if the locktext of me is false then
      put the mouseline into tDroppedLine
      put tDroppedLine
      If the mouseline is empty then
         put  the dragData["text"] & cr before line 1 of me
         put 1 into sNewLineNo
      else
         put cr & the dragData["text"] after the mouseline
         put (word 2 of the mouseline) into sNewLineNo
      end if
   end if
end dragdrop


On DragStart  --sent to source control
   if the locktext of me is false then
      put (word 2 of the mouseline)  into sSourceLineNo
      put line sSourceLineNo of me into tLine
      set the dragData["text"] to tLine
   end if
end DragStart

On DragEnd --sent to source control
   -- clean up the source list
   set the dragAction to "move"
   If the dragDestination is the dragsource then
      If   sNewLineNo <= sSourceLineNo then
         add one to sSourceLineNo
         delete line sSourceLineNo of me
      end if
      if sNewLineNo > sSourceLineNo   then
         delete line sSourceLineNo of me
      end if
   else 
      -- dropped in a different control
      delete line sSourceLineNo of me
   end if
      
   
   --pass DragEnd
end DragEnd
Attachments
DragDropTest.livecode.zip
(2.06 KiB) Downloaded 171 times
best wishes
Skids

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Mon Jan 16, 2017 8:15 pm

Nobody answered you, so I add some fuel..
I'm trying also a smooth drag and drop of one line of text, from a list, to a different field, but it should work also between different stacks. So the default LC text drag does not work.

I came up with the attached example, modifying the "DragExample" stack (Pete on RevOnlIne)

Somehow works, BUT:
- The drop is possible (the green plus sign) to the desktop (and I don't want that...). The MouseStack get stuck with the last stack where the mouse was overing.
- I want to be sure that the dragged text replace all the text in the destination field
- I would like the cursor to reflect the text that is dragged (I think I should do an export to image but how to get the rect of the selection?)

Any help or working example?
PS: note that placing breakpoints in the script, often freezes execution for a few seconds. Could be a bug.

Thanks
Trevix
Attachments
Drag Text.zip
(3.25 KiB) Downloaded 162 times
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Tue Jan 17, 2017 3:07 pm

Ok.
I fixed most things but I still cannot solve the problem that the drop is still available when the mouse is overing the desktop (not a LC stack).
The front script is this:

Code: Select all

global gDestStack

on dragMove x,y
    --Only allow the control to be dropped on the specific field "tDestination"
    put the long name of the target into gDestStack
    if gDestStack is not empty and "tDestination" is in gDestStack then
      set the dragAction to "copy"
   else
      put empty into gDestStack
      set the dragAction to "none"
   end if
   pass dragMove
end dragMove
What is wrong with this?
Thanks
Trevix
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 345
Joined: Mon Jun 10, 2013 1:32 pm

Re: Drag and Drop a single line of text

Post by Lagi Pittas » Tue Jan 17, 2017 4:17 pm

Hi All

Here is some Livecode Magic from Scott Rossi that has vanished from his updated site into the memory hole. I remembered how impressed I was when I saw this and so I managed to save it via archive.org.
I'm sure Scott won't mind me posting here.

Scott if You read this how about putting a downloads folder for all your stuff - it doesn't have to look like Leonardo D' Rossi did it :D It would be a shame to lose all that work.

For some reason the "explosion" when you delete a line when dragged outside the list box doesn't show unless you single step the program (LC v 6.7.11) - (it worked a couple of years ago when i tested.

If you get your drag and drop working using this technique (it only copies within a single box) would be nice if you posted the results her

Regards Lagi
Attachments
drag_sampler.rev.zip
(4.49 KiB) Downloaded 186 times

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Tue Jan 17, 2017 4:28 pm

Thanks. It is nice.
But we are talking about dragging text. And I was talking about dragging text between different stacks.
PS: in order to work al references to old Staus must be quoted

Trevix
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 345
Joined: Mon Jun 10, 2013 1:32 pm

Re: Drag and Drop a single line of text

Post by Lagi Pittas » Tue Jan 17, 2017 5:12 pm

HI

It does drag text but uses some clever image grabbing to show the text being dragged , I was thinking that some of the routines might give you ideas for yours that's why I explained it wasn't between listboxes - we can always learn something from Scott's stuff

lagi

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 345
Joined: Mon Jun 10, 2013 1:32 pm

Re: Drag and Drop a single line of text

Post by Lagi Pittas » Tue Feb 07, 2017 12:01 am

Hi

The following code was submitted to to tge Livecode use-list by Andy Piddock

I hope he doesn't mind me posting herr as it is small enough and easy to follow to adapt to dua listboxes.

Code: Select all

-- Field script
on mouseDown
  put the num of lines of me into tmax # Store drag constraint
  put word 2 of the clickLine into tcl
  if not the listBehavior of me then set the textcolor of line tcl of me to
"red" # Cosmetic
  if line tcl of me is empty then
    exit mousedown
  end if
  put item 2 of the mouseLoc into tstarty
  put the effective textHeight of me into th
  repeat while the mouse is down
    if item 2 of the mouseLoc - tstarty > (th/2) then
      if within (me, the mouseLoc) is true then
        lock screen
        if tcl<tmax then # Constrain drag to max lines
          put cr & line tcl of me after line (tcl + 1) of me
          delete line tcl of me
          add 1 to tcl
          if not the listBehavior of me then set the textcolor of line tcl
of me to "red" # Cosmetic
          add th to tstarty
        end if
        if the listBehavior of me then set the hilitedLine of me to tcl #
Update hilitedline
        unlock screen
      end if
    else if tstarty - item 2 of the mouseLoc > (th/2) then
      if within (me, the mouseLoc) is true then
        lock screen
        put line tcl of me & cr before line (tcl - 1) of me
        delete line tcl + 1 of me
        subtract 1 from tcl
        if tcl<1 then put 1 into tcl # Constrain drag to min lines
        if not the listBehavior of me then set the textcolor of line tcl of
me to "red" # Cosmetic
        subtract th from tstarty
         if the listBehavior of me then set the hilitedLine of me to tcl #
Update hilitedline
        unlock screen
      end if
    end if
  end repeat
  if not the listBehavior of me then set the textcolor of line tcl of me to
empty # Cosmetic
end mouseDown
Regards Lagi

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Tue Feb 07, 2017 12:02 pm

Thanks but meanwhile I solved it.
I managed it with Dragstart, drag end and export export snapshot from Field.
See attachment
Most of the problem came from scripting the position of the text to be placed (in the final destination field): I could not find a way to easily position the cursor by script.
Regards
Trevix
Attachments
Drag Text 2.zip
Open both stack: instructions inside
(4.48 KiB) Downloaded 206 times
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 72
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City
Contact:

Can you verify Mac-only DragDrop bug?

Post by tomBTG » Tue Feb 26, 2019 10:00 pm

Hi,

Can you verify or explain this odd Mac drag/drop bug?

I've spent days trying to debug a Mac-only bug in which drag/drop fails on the 4th drag operation. On drag/drop attempts 1 through 3, I am able to drag/drop lines of text from one field to a field in another stack with no trouble. But on the fourth attempt, drag/drop fails to operate and no further DDs are possible. (On Windows, no problem.)

Desperate to see what I'm doing wrong, I searched the forum and found an unrelated example stack. And just like my project, this example runs fine on Windows, but on Mac it fails on the fourth drag attempt. As in my own project, the example stack inserts the dragMove handler into a FrontScript.

Test it yourself with the sample stack (Drag Text 2.zip) by Trevix:
download/file.php?id=7550 from the last post of this thread: viewtopic.php?t=28634

By logging the various drag/drop handlers in my own project, I can see that on the fourth attempt to drag, the dragStart handler fires, but the dragMove does not.

I am seeing this in LC 8.1.10 Build 14072 on Macbook Pro running OS 10.12.6

Anyone else see this?

Thanks,
Tom Bodine

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6918
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag and Drop a single line of text

Post by dunbarx » Tue Feb 26, 2019 10:20 pm

Hi.

If you have a solid stack recipe with that fourth-time failure thing, send it immediately to the team at:

https://quality.livecode.com

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6918
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag and Drop a single line of text

Post by dunbarx » Tue Feb 26, 2019 10:24 pm

Hmm.

I downloaded your two stacks and played around. Dragging from "dragText" to "WhereToDrag" works fine forever.

On Mac OS 10.13.4. LiveCode 8.1.10.

Craig

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 72
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City
Contact:

Re: Drag and Drop a single line of text

Post by tomBTG » Tue Feb 26, 2019 11:57 pm

Thanks Craig.

That points the finger back at my Mac, where the problem is persistent. Mac settings all look normal.
But wait! I open the same stack in trusty old LC 7.1.4 on my Mac, and the fourth-time-fails problem vanishes. That turns the finger back on LC 8.1.10. But you are running that OS, too, without the problem. Arghhh! My finger hurts.

Tom

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Fri Nov 22, 2019 7:52 pm

Right when I needed I found out that dragEnter, DragData, etc don't work on mobile.
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text

Post by trevix » Sat Nov 23, 2019 2:20 am

Or there is now some way to drag text from the hilited line of a list field to a field on iOS?
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

trevix
Posts: 552
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Drag and Drop a single line of text (iOS)

Post by trevix » Mon Nov 25, 2019 9:22 pm

While searching for a non existing drag & drop for mobile, I developed some sort of solution (LC 9.5.1).
This allow dragging a line of text from a list field to a different single field (on IOS).

Something is not quite working yet, but I cannot pin point it (some recursion occurs).

I am gratefull for any help.

Trevix
Attachments
DragText4.livecode.zip
(2.6 KiB) Downloaded 56 times
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”