Moving more than one line in a listfield
depstein at att.net
depstein at att.net
Wed Dec 17 13:48:45 EST 2003
This is a subset of a more elaborate function, so I hope it still works. It
can be used to move the selected lines of a list-type field to the top or
bottom of the list, or up or down.
David Epstein
function reListed theList,actPieces,action,myDelim, at newSelec
-- theList is the starting list; if return-delimited, pass return as myDelim
-- actPieces gets passed the hilitedLines of the field containing theList
-- action is 1, 2, 3, or 4, depending on where you want to move the selected
lines.
-- the function returns the modified list, and loads variable newSelec
-- with a comma-delimited list of numbers useful for setting the appropriate
-- hilitedLines of the field after the list has been altered.
put theList into origList
replace "," with " " in actPieces
set the itemDelimiter to myDelim
put the number of items in theList into z
put the number of words in actPieces into p
repeat with w = p down to 1
put word w of actPieces into i
put myDelim & item i of theList before newList
delete item i of theList
end repeat
-- items (lines) specified in actPieces are now listed in newList, and
-- have been removed from theList. The rest of the script
-- combines those newList and theList in the right order.
delete char 1 of newList
switch action
case 1 -- move newList to the top
put rangeList(1,p) into newSelec
return newList & myDelim & theList
case 4 -- newList to the bottom
put rangeList(z-p+1,z) into newSelec
return theList & myDelim & newList
case 2 -- newList up
put word 1 of actPieces into slot
if slot < 3 then
put rangeList(1,p) into newSelec
return newList & myDelim & theList
else
put slot - 1 into slot
put rangeList(slot,slot+p-1) into newSelec
return item 1 to slot-1 of theList & myDelim & newList & myDelim & item
slot to -1 of theList
end if
case 3 -- newList down
put word -1 of actPieces into slot
if slot = z then -- last selected is at end of list
put rangeList(z-p+1,z) into newSelec
return theList & myDelim & newList
else
put slot + 2 - p into slot
put rangeList(slot,slot+p-1) into newSelec
return item 1 to slot-1 of theList & myDelim & newList & myDelim & item
slot to -1 of theList
end if
end switch
end reListed
function rangeList a,z -- returns comma delimited series of numbers from a to
z
put z-a into myCount
if myCount = 0 then return a
put a into hold
repeat with b = 1 to myCount
put "," & a+b after hold
end repeat
return hold
end rangeList
More information about the use-livecode
mailing list