Drag & drop a file onto a card?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2756
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Drag & drop a file onto a card?

Post by stam » Tue Jan 03, 2023 12:47 pm

Hi all,

I'm sure this must be possible, but can't get it to work...

If I put the code below into the card script then nothing happens and I just get a cursor showing a circle with a line through it. If I put the same script into any control, eg a button, and drag a file onto the it, then I get the '+' sign and the expected action happens. In this simple example it just puts the file name of the dropped file into the message box:

Code: Select all

on dragEnter
    set the dragAction to "copy"
end dragEnter

on dragDrop
    put the dragData["files"]
    pass dragdrop
end dragDrop

Can this not work with a card rather than a control?

Many thanks
S.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 1:02 pm


stam
Posts: 2756
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Drag & drop a file onto a card?

Post by stam » Tue Jan 03, 2023 1:48 pm

Thank you Richmond.

you could have just said 'no' and spared be the effort of downloading a stack, examining it's card script while being subjected to painfully questionable images... My question was whether the card can take drag and drop directly (rather than me having to put some kind of receiving control on it).

the relevant card script starts with the comment:

Code: Select all

## Obviously a "naked" card does not accept any Drag'n'Drop, so I created an opaque gracic that will "catch" the droppings
That would have sufficed. And probably would have been less effort for you to dig up this URL...

Also - I wonder why this post didn't show up on any searches? I suspect the text content and imaging of the post pretty much ruled that out from relevant searches...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 2:28 pm

Painfully questionable images?

Sorry, but something escapes me.

stam
Posts: 2756
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Drag & drop a file onto a card?

Post by stam » Tue Jan 03, 2023 3:03 pm

Probably the reason the post was titled “drag act”.
My point being that the attempts to make the thread “humorous” were so extravagant that the post doesn’t even flag up on Google when searching for “livecode drag file onto card”.

Again, just a “no, a card does not receive the dragDrop message” would have been welcome.
I did specifically look in the documentation but did not see this information (admittedly I may well have missed it as am at work with limited time).

Thanks for answering in any case.
S.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 4:00 pm

Obviously the answer, then, is to stop being a drag and get into the act . . . 8)

https://lessons.livecode.com/m/4071/l/1 ... to-a-stack

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 4:22 pm

HOWEVER: Be Warned, this does NOT import the image, it merely displays it:
-
Drag2.jpg
-
I put the code into the cardScript.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 4:24 pm

https://livecode.fandom.com/wiki/Drag_and_drop

explains about other types of data other than images.

stam
Posts: 2756
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Drag & drop a file onto a card?

Post by stam » Tue Jan 03, 2023 8:23 pm

Thanks Richmond,
I think we may be talking at crossed purposes. I have seen these links before when researching prior to posting, hence my code above.
In case I wasn't clear the question was if a 'bare naked card' can receive a drag/dropped file. Not where to put the script.
As you can deduce from my script, I'm merely trying to get the file name of a file dropped onto a card.

To illustrate the problem, see the screenshot that shows the cursor turning into a 'stop' sign (what the big red arrow is pointing at).
This does not happen if I have any kind of control to receive the dropped file (yes, with the script in the card) - but on a bare naked card it seems like a no-go:
nogo.jpg

Just wanting to confirm there is no way to drop directly onto a card without any visible or hidden controls to receive the drop and move on...

S.
Last edited by stam on Wed Jan 04, 2023 8:56 am, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 8:55 pm

Definitely there is no way a bare card can receive a file.

BUT I am sure that a card can be prepped (in the cardScript) so that things can be dragged onto it.

For instance, an image thing might be created on the card when a picture file is dragged onto the card.

HOWEVER I have not found a way to create a drop target for an image in a cardScript.
Last edited by richmond62 on Thu Jan 05, 2023 12:55 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Tue Jan 03, 2023 9:46 pm

I do NOT understand why THIS in the messageBox works:

Code: Select all

create img "OLDMASTER"
BUT this, in the cardScript does NOT:

Code: Select all

on dragEnter
create img "OLDMASTER"
end dragEnter

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9454
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Drag & drop a file onto a card?

Post by richmond62 » Wed Jan 04, 2023 12:58 pm

Unfortunately I have not got the time to try this out at the moment,
but I wonder if one could not have a create statement inside a dragDrop thing?

stam
Posts: 2756
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Drag & drop a file onto a card?

Post by stam » Wed Jan 04, 2023 4:59 pm

richmond62 wrote:
Wed Jan 04, 2023 12:58 pm
Unfortunately I have not got the time to try this out at the moment,
but I wonder if one could not have a create statement inside a dragDrop thing?
No that doesn't seem to work - but that's fine.
It was just a slight inconsistency in LC, as cards will react to practically all other messages - with the exception of drag messages it seems...

There are many workarounds to this (creating an graphic with no opacity for example and filling the card with it - resizing automatically etc) but they seem messy and inconsistent with, say, mouse events, keydown/up events etc - I wonder if this may merit an enhancement request?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Drag & drop a file onto a card?

Post by jacque » Wed Jan 04, 2023 6:16 pm

richmond62 wrote:
Tue Jan 03, 2023 9:46 pm
I do NOT understand why THIS in the messageBox works:

Code: Select all

create img "OLDMASTER"
BUT this, in the cardScript does NOT:

Code: Select all

on dragEnter
create img "OLDMASTER"
end dragEnter
Because drag messages aren't sent to a card. You wouldn't get a dragdrop message either.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”