repositioning list-field lines
Bjoernke von Gierke
bvg at mac.com
Thu Mar 1 04:58:32 EST 2012
i just did this a few days back. There are more elegant solutions like using a second field to move around, but this works for me. If you change the textSize to a non-default value, you might need to adjust some parts of the offset calculation at the start.
on mouseDown
--preparation of data
put the effective textheight of me into myPosMargin
put item 2 of the selectedLoc + myPosMargin div 2 into myPos
put the selectedText of me into myText
put the hilitedLine of me into myCurrLine
put the text of me into textToChange
repeat while the mouse is down
-- for valor! for the engine!
wait with messages
if myPos - item 2 of the mouseLoc >= myPosMargin then
-- moving the mouse upwards
put max(myCurrLine - 1,1) into myMoveToLine
if myCurrLine <> myMoveToLine then
-- need to move to a new position in the list
put myPos - myPosMargin into myPos
end if
else if myPos - item 2 of the mouseLoc <= - myPosMargin then
-- moving the mouse downwards
put min(myCurrLine + 1,the number of lines in me) into myMoveToLine
if myCurrLine <> myMoveToLine then
-- need to move to a new position in the list
put myPos + myPosMargin into myPos
end if
else
-- not moving the mouse enough
put myCurrLine into myMoveToLine
end if
-- do the moving
delete line myCurrLine of textToChange
put myText & return before line myMoveToLine of textToChange
if char -2 of textToChange = return then
delete char -2 of textToChange
end if
put textToChange into me
set the hilitedLine of me to myMoveToLine
-- cleanup
put myMoveToLine into myCurrLine
end repeat
-- remove this line if you don't want default field behaviour to happen (in other words, don't remove)
selectionChanged
end mouseDown
On 01.03.2012, at 10:23, Nicolas Cueto wrote:
> Hello,
>
> I was wondering if anyone had pointers on how to enable a user to
> reposition lines within a listfield. More specifically, a user would
> "press" on a line and drag it within the listfield to a different
> position. To reorder the lines, for example.
>
> Hoping to not have to reinvent the wheel on this.
>
> Thank you.
>
> --
> Nicolas Cueto
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list