Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
propeller
- Posts: 22
- Joined: Sat Oct 13, 2018 12:22 pm
Post
by propeller » Wed Dec 30, 2020 10:49 am
Hi there,
i have a problem on windows with dragging lines in a field. Basically i have a field, which is filled with names and i want to reorder them by clicking on a name and then moving it up or down in the field. I found a wonderful script in the forum which works well on mac but does not on windows.
this is the script:
Code: Select all
local sClicked, sArray, sMovingText, sLastLineNum
on mousedown
put word 2 of the mouseLine into sClicked
put the styledText of me into sArray
put sArray[sClicked] into sMovingText
put empty into sLastLineNum
end mousedown
on mouseMove
put word 2 of the mouseLine into tLineNum
if tLineNum is empty or the mouse is not down then exit mouseMove
## don't do swapping if the lineNumber has not changed
if tLineNum = sLastLineNum then exit mouseMove
put tLineNum into sLastLineNum
## swap here
put sArray[tLineNum] into sArray[sClicked]
put sMovingText into sArray[tLineNum]
lock screen
put the vScroll of me into tScroll
set the styledText of me to sArray
set the scroll of me to tScroll
select line tLineNum of me
unlock screen
put tLineNum into sClicked
end mouseMove
What on windows happens is that when i click on a name, all text is gone and i get the line where the name was hilited. Does anyone know what the problem is or how to drag lines of a field on windows?
I would be very happy, if someone could push me into the right direction.
Have a nice day!
-
richmond62
- Livecode Opensource Backer

- Posts: 10073
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Wed Dec 30, 2020 12:39 pm
Trying to be 'clever' in a quite different way I did this:
Code: Select all
on mouseDown
global CT
--global DT
global CL
set the itemDelimiter to " "
put the mouseText into CT
put the mouseLine into CL
delete item 3 of CL
delete item 3 of CL
delete item 3 of CL
delete item 1 of CL
put empty into line CL of me
end mouseDown
on mouseUp
global CT
global CL
set the itemDelimiter to " "
put the mouseText into DT
put the mouseLine into DL
delete item 3 of DL
delete item 3 of DL
delete item 3 of DL
delete item 1 of DL
put empty into line DL of me
put CT into line DL of me
put DT into line CL of me
end mouseUp
It is great fun: have a play with it.

-
Attachments
-
- Click ReOrder.livecode.zip
- Here's the stack.
- (1.04 KiB) Downloaded 279 times
-
propeller
- Posts: 22
- Joined: Sat Oct 13, 2018 12:22 pm
Post
by propeller » Wed Dec 30, 2020 3:11 pm
Dear richmond62,
thank you for your brainwave. I tried it and it works, even if the selected line gets blanked out somehow. I just got a solution from a friend of mine who solved the issue using a datagrid instead of the field. As i have no clue about datagrids i can not tell you anything about the solution but i thank you again and wish you a wonderful day and a great next year.
Thank you!
-
AndyP
- Posts: 634
- Joined: Wed Aug 27, 2008 12:57 pm
-
Contact:
Post
by AndyP » Wed Dec 30, 2020 4:44 pm
Another variation that works in a field, tested on windows 10, LC 9.6.1
Code: Select all
on mouseDown
--setup colors for hilited text
put "black" into tOrigCol
put "red" into tHiLiteCol
put word 2 of the clickLine into tClickLine
if line tClickLine of me is empty then
exit mousedown
end if
put item 2 of the mouseLoc into tStartLIne
put the effective textHeight of me into tHt
repeat while the mouse is down
--down
if item 2 of the mouseLoc - tStartLIne > (tHt/2) then
lock screen
put cr & line tClickLine of me after line tClickLine + 1 of me
delete line tClickLine of me
add 1 to tClickLine
set the textcolor of line tClickLine of me to tHiLiteCol
add tHt to tStartLIne
unlock screen
--up
else if tStartLIne - item 2 of the mouseLoc > (tHt/2) then
lock screen
put line tClickLine of me & cr before line tClickLine - 1 of me
delete line tClickLine + 1 of me
subtract 1 from tClickLine
set the textcolor of line tClickLine of me to tHiLiteCol
subtract tHt from tStartLIne
unlock screen
end if
end repeat
--protect against empty lines being inserted
filter lines of me without empty
--make sure all lines are reset to original text color
put the number of lines of me into tNoLines
repeat with tC = 1 to tNoLines
set the textcolor of line tC of me to tOrigCol
end repeat
end mouseDown
Andy .... LC CLASSIC ROCKS!