repositioning list-field lines

André Bisseret andre.bisseret at wanadoo.fr
Thu Mar 1 11:34:13 EST 2012


Bonjour Nicolas,

create a small one line field named "temp"
and put the following in the script of your field.

Sorry for the comments in French

Best regards from Grenoble

André


------

-- LE SCRIPT DE DRAG DROP ENTRE 2 FIELDS d'Éric CHATONET, MODIFIÉ POUR UN SEUL

local lLineNo,tLaLigne,tStyle, -- script local variable
----------------------------------
on mouseEnter
    set the dragDelta to 5 -- AU LIEU DE 10 : EMPÊCHE UN PEU ERREUR
    -- QUI CONSISTE À PRENDRE UNE AUTRE LIGNE
end mouseEnter
----------------------------------
on dragMove -- sent repeatedly when the dragdata is within the field
    local tContents,tHilitedText
    -----
    put (the mouseV - the top of the target) div the effective textHeight of the target into lLineNo -- line number
    if lLineNo > the number of lines of the target then put the number of lines of the target into lLineNo
    -----
    lock screen
    put StripCR(me) into tContents -- see below
    put the hilitedText of the target into tHilitedText -- stores highlighted line
    put cr after line lLineNo of tContents -- creates a blank line
    set the text of the target to tContents
    set the hilitedLine of the target to lineOffset(tHilitedText,tContents) -- restores highlighted line
    unlock screen
    delete line (the hilitedLine of the target) of the target
end dragMove
----------------------------------

on DragLeave -- restores current contents
    local tHilitedLine,
    -----------
    lock screen
    put the hilitedLine of the target into tHilitedLine
    put StripCR(me) into the target --
    set the hilitedLine of the target to tHilitedLine
    unlock screen
end DragLeave
----------------------------------
on dragEnter -- NÉCESSAIRE DANS LE CONTROL DE DESTINATION
    set the dragAction to "Move"
end dragEnter
----------------------------------
on dragDrop
    local tContents
    -----
    put StripCR(me) into tContents -- see below
    if lLineNo = 0 then
        put the dragdata["text"] & cr before tContents
    else
        put cr & the dragdata["text"] after line lLineNo of tContents
    end if
    lock screen
    set the text of the target to tContents
    set the hilitedLine of the target to lLineNo + 1 -- sets highlighted line to dropped line
    unlock screen
end dragDrop
----------------------------------
function StripCR pText -- returns 'normal' field's contents
    if char 1 of pText = cr then delete char 1 of pText
    if char -1 of pText = cr then delete char -1 of pText
    replace cr & cr with cr in pText
    return pText
end StripCR
-- ---------------------------------
on dragStart --NÉCESSAIRE DANS LE CONTROL SOURCE
    set the dragData["text"] to the selectedText
    put the selectedText of the target into fld "Temp" -- in order to create the right image
    -- put tLaLigne into fld "Temp"
    set the dragImage to CreateDragImage() -- see below
    set the dragImageOffset to the width of last image div 2,the height of last image div 2 -- centered
end dragStart

on dragEnd
    delete last image -- we no longer need the drag image
end dragEnd
---------------------------------
function CreateDragImage -- creates drag image on-the-fly
    local tRect,tempImage
    -----
    put the rect of fld "Temp" into tRect
    -----
    export snapshot from rect tRect of this cd to tempImage as jpeg
    -- export image to a variable
    lock messages -- important to speed up the process
    create invisible image -- we don't want to see it
    set the text of last image to tempImage
    if there is an image ID 6001 then delete image ID 6001
    set the ID of last image to 6001 -- setting dimensions
    unlock messages
    return the ID of last image -- we need it to set the dragImage property
end CreateDragImage
-------------------


Le 1 mars 2012 à 10:23, Nicolas Cueto a écrit :

> 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