drag & drop external objects
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
drag & drop external objects
Hi I'm struggling with getting drag & drop to work. I'm building an app for OSX and need it to be able to handle multiple types of content dragged onto it from external sources - selected text, files, emails etc.
I can do this successfully using an unlocked field and can handle the dragdrop message and get the drag data.
However, I can't seem to do this with a locked field or any other object type (ideally I'd like to do it when content is dragged onto any part of the card).
When dragging items from the finder onto my app, dragging over an unlocked field results in the mouse pointer displaying a "+" sign, whereas dragging over a locked field or anywhere else results in the pointer displaying a no entry sign suggesting the finder/OSX doesn't recognise that area of the screen as somewhere that can receive drags.
The Livecode dictionary suggests you can do this with objects other than unlocked fields and states:
"To accept drops to a locked field or a control other than a field, handle the dragDrop message, using the dragData property to determine what data is being dragged"
...but no dragdrop message appears to be being sent to any object other than an unlocked field.
Any ideas what I might be doing wrong?
I can do this successfully using an unlocked field and can handle the dragdrop message and get the drag data.
However, I can't seem to do this with a locked field or any other object type (ideally I'd like to do it when content is dragged onto any part of the card).
When dragging items from the finder onto my app, dragging over an unlocked field results in the mouse pointer displaying a "+" sign, whereas dragging over a locked field or anywhere else results in the pointer displaying a no entry sign suggesting the finder/OSX doesn't recognise that area of the screen as somewhere that can receive drags.
The Livecode dictionary suggests you can do this with objects other than unlocked fields and states:
"To accept drops to a locked field or a control other than a field, handle the dragDrop message, using the dragData property to determine what data is being dragged"
...but no dragdrop message appears to be being sent to any object other than an unlocked field.
Any ideas what I might be doing wrong?
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: drag & drop external objects
Hi.
One kluge might be to set the lockText of the field of interest to "false" upon mouseEnter, and reset it on mouseLeave.
Craig Newman
One kluge might be to set the lockText of the field of interest to "false" upon mouseEnter, and reset it on mouseLeave.
Craig Newman
Re: drag & drop external objects
Hi stanier25,
you are not doing anything wrong!
LC fully supports "Drag'n'Drop", but only drag and drop of TEXT is handled automatically, that's why you see the CROSS cursor when dragging the mouse over an editable field in LC. Drag some selected text form any text editor onto a field in LC and drop it!
All other D'n'D functionality needs to be scripted in LC. Examples:
To accept drag and drop in the complete stach on all objects, add this to the stack script:
This takes care of changing the cursor to CROSS (drag/drop) when over ANY object in the stack.
If you only want that a specific LC object accepts D'n'D, do not put this into the stack script but into the script of that namely object. Same for "dragdrop", see below.
Now you also need to take care of the "dragdrop" message, which is sent when the user, well, finally DROPS something in LC. You could check -> the dragdata["files"] and decide what to do with the dropped files.
Best
Klaus
you are not doing anything wrong!
LC fully supports "Drag'n'Drop", but only drag and drop of TEXT is handled automatically, that's why you see the CROSS cursor when dragging the mouse over an editable field in LC. Drag some selected text form any text editor onto a field in LC and drop it!
All other D'n'D functionality needs to be scripted in LC. Examples:
To accept drag and drop in the complete stach on all objects, add this to the stack script:
Code: Select all
on dragenter
set the dragaction to "copy"
end dragenter
If you only want that a specific LC object accepts D'n'D, do not put this into the stack script but into the script of that namely object. Same for "dragdrop", see below.
Now you also need to take care of the "dragdrop" message, which is sent when the user, well, finally DROPS something in LC. You could check -> the dragdata["files"] and decide what to do with the dropped files.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: drag & drop external objects
Klaus.
I rarely drag or drop anything. But I tried to drag some text from this very forum over to a field in a LC card, and with my kluge, all works fine, locked or unlocked.
But with a dragEnter handler in the card script I cannot get the drag to "take". It does not matter what the insides of the dragEnter handler are.
The cursor does indeed change to a "cross", but the text does not drop.
Without that handler, in an unlocked field, all is well.
I am using the commandKey to allow drag from the external application. Is that an issue?
Craig
I rarely drag or drop anything. But I tried to drag some text from this very forum over to a field in a LC card, and with my kluge, all works fine, locked or unlocked.
But with a dragEnter handler in the card script I cannot get the drag to "take". It does not matter what the insides of the dragEnter handler are.
The cursor does indeed change to a "cross", but the text does not drop.
Without that handler, in an unlocked field, all is well.
I am using the commandKey to allow drag from the external application. Is that an issue?
Craig
Re: drag & drop external objects
When scritping "on dragenter" in the stack (or wherever), you OVERWRITE the automatism of LC and thus have to take action by yourself, even when just dropping some text!
Holding the CMD-key should not do anything harmful.
Holding the CMD-key should not do anything harmful.
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: drag & drop external objects
Klaus.
Craig
I get that. I used your example. It prevents the drop.When scritping "on dragenter" in the stack (or wherever), you OVERWRITE the automatism of LC and thus have to take action by yourself, even when just dropping some text!
Craig
Re: drag & drop external objects
It actually does not prevent the drop, it just doesn't handle it!
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: drag & drop external objects
Hmmm.
So without a dragEnter handler of any kind, I can drag text into an unlocked field. But with a dragEnter handler of any kind, I cannot.
I tried the example handler in the dictionary:
and what do you think? Nothing happens.
This is an odd way to think about:
Craig
So without a dragEnter handler of any kind, I can drag text into an unlocked field. But with a dragEnter handler of any kind, I cannot.
I tried the example handler in the dictionary:
Code: Select all
on dragEnter -- show a green outline around the drop target
set the borderColor of the target to "green"
end dragEnter
This is an odd way to think about:
For a newbie like me, can you post a simple example of a dragEnter hander that does indeed allow me to drop text into a field? And any other functionality that might ride along would be a bonus.It actually does not prevent the drop, it just doesn't handle it!
Craig
Re: drag & drop external objects
Hi Craig,
uncheck "3d" for the field and the handler will work!
Use something like this in the STACK or CARD script to handle the "former automatism" of text dropping in LC:
You can of course finetune this ad infinitum, check if is a field at all, if there is already text in the field etc., but this is it in general...
Best
Klaus
uncheck "3d" for the field and the handler will work!
Use something like this in the STACK or CARD script to handle the "former automatism" of text dropping in LC:
Code: Select all
on dragenter
set the dragaction to "copy"
set the borderColor of the target to green
end dragenter
on dragdrop
if the dragdata["text"] <> EMPTY then
set the text of the target to the dragdata["text"]
end if
end dragdrop
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: drag & drop external objects
Klaus.
OK, thanks. I see. Like you said, you have to handle it.
What threw me was that without any "drag"-like handler at all, the process worked just fine.
Craig
OK, thanks. I see. Like you said, you have to handle it.
What threw me was that without any "drag"-like handler at all, the process worked just fine.
Craig
Re: drag & drop external objects
Many thanks for such quick responses.
Setting the drag action in the stack script did, indeed, solve the issue and I can now happily drag external content onto objects other than unlocked field. Interestingly, the one object that doesn't respond is the card itself but that doesn't matter as you can simply use a graphic or locked field to cover the whole of the card area to get the same effect.
Setting the drag action in the stack script did, indeed, solve the issue and I can now happily drag external content onto objects other than unlocked field. Interestingly, the one object that doesn't respond is the card itself but that doesn't matter as you can simply use a graphic or locked field to cover the whole of the card area to get the same effect.