Moving more than one line in a listfield

Klaus Major klaus at major-k.de
Sun Dec 21 10:14:56 EST 2003


Hi all,

> Hi friends,
>
> i'm feeling a bit lazy today ;-)
>
> Has someone eventually already written a smart handler to move more 
> than
> one hilitedlines (non-/contigous) up and/or down a listfield?
>
> If yes, are you willing to share this cleverness?
>
> Thanks in advance...

in case someone is interested, here is the soltion i found by myself ;-)

This is the script of the "up" button:

on mouseUp
   put the selectedtext of fld "filelist" into dertext
   put the hilitedlines of fld "filelist" into hl
   if hl = empty OR item 1 of hl = 1 then exit mouseup
   lock screen
   repeat with i = 1 to the num of items of hl
     delete line (item i of hl) of fld "filelist"
     put  line i of dertext & CR before line ((item i of hl) -1) of fld 
"filelist"
   end repeat
   repeat with i = 1 to the num of items of hl
     put item i of hl -1 into item i of hl
   end repeat
   set the hilitedlines of fld "filelist" to hl
   ## restore hilites
end mouseUp

This is the script of the "down" button:

on mouseUp
   put the selectedtext of fld "filelist" into dertext
   put the hilitedlines of fld "filelist" into hl
   if hl = empty then exit mouseup
   lock screen
   repeat with i = the num of items of hl down to 1  ## !!! ;-)
     delete line item i of hl of fld "filelist"
   end repeat
   put 1 into anfang
   repeat for each item l in hl
     put line anfang of dertext & CR before line l + 1 of fld "filelist"
     add 1 to anfang
   end repeat
   if char -1 of fld "filelist" = CR then delete char -1 of fld 
"filelist"
   repeat with i = 1 to the num of items of hl
     put (item i of hl +1) into item i of hl
   end repeat
   set the hilitedlines of fld "filelist" to hl
   ## restore hilites
   unlock screen
   set the uLinesAndStates of grp "CheckBoxList" to fld "filelist"
   knopfaktivierung
end mouseUp

Enhancements are very appreciated :-)


Regards

Klaus Major
klaus at major-k.de
www.major-k.de



More information about the use-livecode mailing list