|
|
|
Move a line from field to field
Added on 4/4/2000
|
This behavior added to a field member allows the user to drag a line from this field to the selected field. Added to two fields it can be used to drag and drop a line from one field to another and back. The behavior uses a field to show what is being dragged, you can set this field up as you wish.
property pWhichLine
property pLineMember
property pLineSpriteNum
property pMyMember
property pMySpriteNum
property pToMember
property pToSpriteNum
on beginSprite me
-- Set constant properties
pMySpriteNum = the spriteNum of me
pMyMember = member(pMySpriteNum)
-- Find the sprite that has the Line Member
repeat with x = 1 to 120
if (sprite(x).member = pLineMember) then
pLineSpriteNum = x
exit repeat
end if
end repeat
-- Find the sprite that has the To-Field Member
repeat with x = 1 to 120
if (sprite(x).member = pToMember) then
pToSpriteNum = x
exit repeat
end if
end repeat
-- Puppet this sprite
puppetSprite pLineSpriteNum, TRUE
sprite(pLineSpriteNum).visible = FALSE
end
on mouseDown me
-- What line was pressed?
pWhichLine = the mouseLine
-- Set the text of the item member to the text of the line pressed
pLineMember.text = pMyMember.line[pWhichLine]
-- If the text is not empty go
if pLineMember.text <> "" then
-- Show the sprite
sprite(pLineSpriteNum).visible = TRUE
-- Drag the sprite
repeat while the mouseDown
sprite(pLineSpriteNum).loc = the mouseLoc + point(-20,1)
updateStage
end repeat
end if
end
on mouseUp me
-- If the sprite is dragged inside the To-Field
if inside(the mouseLoc, sprite(pToSpriteNum).rect) = TRUE then
-- Set the variables for the from-field
varText = pMyMember.text
varLines = the number of lines of varText
-- Delete the line from the from-field
repeat with x = 1 to varLines
if x = pWhichLine then
nothing
else
varNewText = varNewText & varText.line[x] & RETURN
end if
end repeat
-- Set the variables for the to-field
varToText = pToMember.text
varToLines = the number of lines of varToText
y = 1
varToNewText = ""
repeat with x = 1 to varToLines
if x = the mouseLine then
varToNewText = varToNewText & pLineMember.text & RETURN
else
-- If the line is empty don't insert it - the last line is always empty
if varToText.line[y] = "" then
nothing
else
varToNewText = varToNewText & varToText.line[y] & RETURN
y = y + 1
end if
end if
end repeat
-- Update both text fields
pMyMember.text = varNewText
pToMember.text = varToNewText
else
-- beep
end if
-- If the sprite is dragged to another position within the same field
if inside(the mouseLoc, sprite(pMySpriteNum).rect) = TRUE then
-- If it is not the same line - go
if the mouseLine <> pWhichLine then
-- Set variables
varText = pMyMember.text
varLines = the number of lines of varText
-- Delete the line from the text
repeat with x = 1 to varLines
if x = pWhichLine then
nothing
else
varNewText = varNewText & varText.line[x] & RETURN
end if
end repeat
-- Insert the line in its new position
-- Set variables first
y = 1
varText = ""
repeat with x = 1 to varLines
if x = the mouseLine then
varText = varText & pLineMember.text & RETURN
else
-- If the line is empty don't insert it - the last line is always empty
if varNewText.line[y] = "" then
nothing
else
varText = varText & varNewText.line[y] & RETURN
y = y + 1
end if
end if
end repeat
-- Update text field
pMyMember.text = varText
end if
else
-- beep
end if
-- Hide the sprite
sprite(pLineSpriteNum).visible = FALSE
end
on getPropertyDescriptionList
if the currentSpriteNum = 0 then exit
-- pLineMemberName = "fldItem"
-- pToMemberName = "fldList2"
list = [:]
addProp list, #pLineMember, [#comment:"Which field member should be used to drag a line?",#format:#field, #default:""]
addProp list, #pToMember, [#comment:"Which field member should recieve a line?",#format:#field, #default:""]
return list
end
|
|