"Drag rearranging" in scrolling fields
Malte Brill
malte.brill at t-online.de
Sun Aug 10 16:58:01 EDT 2003
Hi Jim,
>Has anyone written a stack to implement "drag rearrangement" behavior
>in a field? I want to be able to put text into a field, then drag
>lines around to rearrange them, and then get a list of lines that have
>been moved.
I have. But my script is a bit hard to read.
I post it anyway. If you want I can send the stack offlist.
create a stack 2 fields: (the second one is for changing contens)
one is called dragfield, one newName:
dragfield must be a list field, no multiple hilites
in dragFields script I have:
global whichLine,dertext,counter2,lasthilite2
on mousedown
add 1 to counter2
if the clickline is empty then
put 0 into counter2
end if
if counter2=2 then
put 0 into counter2
if lasthilite2=the hilitedline of me and me is not empty then
put the selectedText into fld "neuername2"
set the loc of fld "neuername2" to item 1 of the loc of fld //
"neuername2",the top of me+the hilitedline of me*12-the vscroll of me
--mind wraping
show fld "neuername2"
focus on fld "neuername2"
select the text of fld "neuername2"
else
hide fld "neuername2"
end if
else
hide fld "neuername2"
end if
put the hilitedline of me into lasthilite2
set the dragPos of me to true
set the hilitecolor of me to 160,220,255
if me is empty then mouseUp
put the hilitedline of me into whichLine
put the selectedtext of me into dertext
if the clickline is empty then set the hilitedlines of me to empty
end mousedown
on mouseStillDown
if the dragpos of me is false then exit mousestilldown
if the hilitecolor of me<>170,255,0 then set the hilitecolor of me //
to 170,255,0
--mind wrapping
end mouseStillDown
on mouseUp
set the dragPos of me to false
set the hilitecolor of me to 160,220,255
end mouseUp
on mouserelease
mouseUp
end mouserelease
on selectionChanged
put the hilitedlines of me into compare
if not the dragpos of me then exit selectionchanged
if compare<>whichline then
delete line whichLine of me
put dertext & CR before line compare of me
if char 1 of me is CR then delete char 1 of me
if char -1 of me is CR then delete char -1 of me
set the hilitedlines of me to compare
end if
end selectionchanged
The second field called neuername2 is just for changing the contens of the
(slowly) twice clicked line
global lasthilite2,counter2
on enterinField
if me is empty then
put "untitled" into me
end if
put me into line lastHilite2 of fld "dragField"
put 0 into counter2
hide me
end enterinField
on returninfield
enterinfield
end returninfield
on scrollbarDrag
enterinfield
end scrollbarDrag
It does not exactly what you need, asit doesn´t report which lines have been
moved, but that would be easy to implement and it has some nice extra stuff
I guess.
Hope this is not too confusing.
Regards,
Malte
More information about the use-livecode
mailing list