How to reorder lines in a grouped list field (workaround)

André Bisseret andre.bisseret at wanadoo.fr
Sat Nov 13 03:16:21 EST 2010


Le 12 nov. 10 à 23:42, zryip theSlug a écrit :

> In case it could be useful for someone, here is a possible workaround
> to this problem. The script has been validated by André:

Thanks a lot again, TheSlug, for your workaround; very usefull indeed.  
I can now use it in my app. where the field must be included in a  
group :-))

Have a nice weekend

André


>
>
> -- LE SCRIPT DE DRAG DROP ENTRE 2 FIELDS d'Éric CHATONET, MODIFIÉ  
> POUR UN SEUL
> local lLineNo,tLaLigne,tStyle,lTrackDragMove -- script local variable
> ----------------------------------
> on mouseEnter
>   set the dragDelta to 5 -- AU LIEU DE 10 : EMPÊCHE UN PEU ERREUR
> -- QUI OCNSISTE À 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 --C'EST
> RÉPÉTÉ !!!
>
> if the dragSource contains the long ID of me and (the mouseControl
> is not empty \
>        and the long id of the mouseControl contains the long ID of  
> me) then
>    set the dragAction to "move" -- Change the dragAction in the
> dragMove if we are in the group
> end if
> 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
>
>   put false into lTrackDragMove -- If we re-enter in the group,
> cancel the need to force the dragDrop handler
>   -- (we avoid to execute the handler two times)
>
>   unlock screen
> end DragLeave
> ----------------------------------
> on dragEnter -- NÉCESSAIRE DANS LE CONTROL DE DESTINATION
> --
> 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
>   --- put the textStyle of the selectedLine into tStyle -- 
> MMMMMMMMMMMMMMMM
> put true into lTrackDragMove -- prepare the dragDrop handler to be  
> forced
>
> set the dragData["text"] to the selectedText --to tLaLigne --the
> selectedText -- plain text
> put the selectedText of the target into fld "Temp" -- in order to
> create the right image
> 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
> ---------------------------------
> -- set the dragData["html"] to the HTMLText of fld "telField"
> ---------------------------------
> on dragEnd
> if (lTrackDragMove) then send "dragdrop" to me --> Force the  
> dragDrop message
> 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
> ---------------------------------------------
>
> Now some explanations:
>
> Not read the report, because it is necessary to have an account to
> join the QCC. I have no account and I have not found the link to
> create an account...
>
> It seems that the dragEnter and dragDrop are not trapped in a group.
> The dragDrop is trapped only if the mouse leaves the group and then
> enter again in the group.
>
> 1) So I added a local variable named lTrackDragMove.
>
> - This variable is set to true when the drag start (dragStart handler)
> - If the drag end and the lTrackDragMove is true, the dragDrop message
> is forced by a send
> - The lTrackDragMove variable is set to false if the drag leaves the
> group. This is to avoid forcing the dragDrop as we are now in the
> normal behavior of the dragDrop handler
>
> 2) In the group, the dragEnter handler is not trapped.
>
> - The dragAction is removed from the dragEnter hander
> - The dragAction is now set to move only in the conditions specified
> by this test:
> if the dragSource contains the long ID of me and (the mouseControl is
> not empty \
>   and the long id of the mouseControl contains the long ID of me) then
>
> This is a test I picked in the datagrid library.
>
>
> Best regards,
> -- 
> -Zryip TheSlug- wish you the best! 8)
> http://www.aslugontheroad.co.cc
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list