dragdrop question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
dragdrop question
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
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
- Attachments
-
- test dragdrop.livecode.zip
- (1.14 KiB) Downloaded 256 times
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: dragdrop question
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:
Your New & Improved Code:
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!
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
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
Hope it Helped!
Chris Bodell
Photo Room - (Editor Download)
Photo Room - (Editor Download)
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: dragdrop question
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: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!
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
Thanks again,
-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: dragdrop question
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
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
Chris Bodell
Photo Room - (Editor Download)
Photo Room - (Editor Download)
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: dragdrop question
Yes, I'm still struggling with that one. For some reason it just doesn't come naturally for mecbodell 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

macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: dragdrop question
Ok, here's my final "drag styled text into a text field" working version (sometimes we have to take pleasure in small accomplishments
:
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

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

Thanks for all you help.
-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS