Page 1 of 1
dragdrop question
Posted: Mon Nov 21, 2011 1:19 am
by marksmithhfx
Hi, just trying to figure out how I can capture and process text after it is dragged and dropped onto a text field. I created a text field and put a dragdrop handler in it:
on dragdrop
put return & "dragdrop detected" after msg
put the number of lines of field "text" into fld "count"
pass dragdrop
end dragdrop
And, the msg shows up in the msg box indicating detection. However the line count only includes text already in the field, and not the new text just dropped in. Is there a way to detect and process the dropped text?
Thanks... I've attached a simple demo stack showing the problem I am having.
-- Mark
Re: dragdrop question
Posted: Mon Nov 21, 2011 3:24 am
by cbodell
Hi Mark,
Firstly, upon dragDrop, you have the option to invoke code before the dragDrop actually takes place. After your code, the engine takes over and completes the process.
Your Code:
Code: Select all
on dragDrop
put return & "dragdrop detected" after msg
put the number of lines of fld "text" into fld "count"
[u]pass dragDrop[/u] <-- Part of your problem
end dragDrop
Your New & Improved Code:
Code: Select all
on dragDrop
if the dragData["text"] is not empty then put "DragDrop Detected!" <-- Optional Line
put the dragData["text"] after me
put the number of lines of me into fld "count"
end dragDrop
Do not add a pass command, because then the engine will add the text to the field when it takes over after passing of the handler.
Hope it Helped!
Re: dragdrop question
Posted: Mon Nov 21, 2011 5:03 am
by marksmithhfx
cbodell wrote:Hi Mark,
Do not add a pass command, because then the engine will add the text to the field when it takes over after passing of the handler.
Hope it Helped!
Brilliant! Thanks Chris. I was also able to solve another problem I was working on. I wanted the field to be able to handle styled text:
Code: Select all
on dragdrop
-- put return & "dragdrop detected" after msg -- debugging
put the htmltext of fld "text" into temp
put the dragdata["html"] after temp
-- put return & temp after msg -- debugging
set the htmltext of fld "text" to temp
select after me
put the number of lines of me into fld "count"
end dragdrop
It works great. Just wondering if there is an easier way to do this (or if this is pretty much the way it is usually done?)
Thanks again,
-- Mark
Re: dragdrop question
Posted: Mon Nov 21, 2011 5:51 am
by cbodell
Your welcome,
Im not sure there is an easier way, that's the way i would go about it.
To save a few words of code, you could refer to the field as "me" instead of fld "text" but it wont speed for efficiency. Just a reminder
Re: dragdrop question
Posted: Mon Nov 21, 2011 6:11 am
by marksmithhfx
cbodell wrote:Your welcome,
To save a few words of code, you could refer to the field as "me" instead of fld "text" but it wont speed for efficiency. Just a reminder
Yes, I'm still struggling with that one. For some reason it just doesn't come naturally for me

Re: dragdrop question
Posted: Mon Nov 21, 2011 6:24 am
by marksmithhfx
Ok, here's my final "drag styled text into a text field" working version (sometimes we have to take pleasure in small accomplishments

:
Code: Select all
on dragdrop
put the htmltext of me into temp
put the dragdata["html"] after temp
set the htmltext of me to temp
select after me
end dragdrop
After all that I'm tempted to comment "I guess its all about me!" but that would just be a bad joke
Thanks for all you help.
-- Mark