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
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Nov 26, 2021 5:00 pm
I am dragging and dropping a text file into a field using:
Code: Select all
on dragdrop
put dragData["files"]
end dragdrop
Works fine except it does not convert not ascii chars like ö. What is the solution?
Kaveh
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Nov 26, 2021 5:12 pm
Hi Kaveh,
you little script will only put the filename of the file into the message box.
What do you script to get the file into the field?
In any way you will need to -> textdecode("... content of file....","UTF8")
before putting into a field.
Best
Klaus
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Nov 26, 2021 5:22 pm
You are a genius Klaus!
First of all, apologies. I copied wrongly. This is what I was using:
Code: Select all
on dragdrop
put URL ("file:" & dragData["files"]) into fld "original"
end dragdrop
Now I use this which works.
Code: Select all
on dragdrop
get URL ("file:" & dragData["files"])
put textdecode(it,"UTF8") into fld "original"
end dragdrop
Thanks again.
Kaveh
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Nov 26, 2021 5:26 pm
Hi Kaveh,
to avoid surprises I always use ->
line 1 of the dragdata["files"]
Unless my script(s) exspect more than one file.
Best
Klaus
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Nov 26, 2021 5:52 pm
You know something? That is exactly what I had! Must have been advice from you years back. I could not understand it so changed it and it worked.
Could you kindly explain what is going on there? Why would there be more than one line and why do we take the first line?
Kaveh
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Nov 26, 2021 6:11 pm
Hi Kaveh,
the dragdata["files"] can contain more than one file per line!
I made a little test with a button and dropped some files on it:
Code: Select all
on dragEnter
set the dragaction to "copy"
end dragEnter
on dragDrop
put the dragdata["files"]
end dragDrop
And ended with this in the msg:
/Users/klaus2/Desktop/Linie 5x ab Hasetor.pdf
/Users/klaus2/Desktop/M1 Vitihof -> City.pdf
/Users/klaus2/Desktop/Neue Filme November 2021.rtf
/Users/klaus2/Desktop/monty.jpg
I think this speaks for itself!
We all know how users are, so this is neccessary in my opinion.
Best
Klaus
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Nov 26, 2021 9:59 pm
So am I right that you want to ensure only 1 file is acted on, in case user drops more than one file? In that case would it not be better to warn the user rather than take one of the files, namely the first one in the list?
Kaveh
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Nov 26, 2021 10:15 pm
kaveh1000 wrote: ↑Fri Nov 26, 2021 9:59 pm
So am I right that you want to ensure only 1 file is acted on, in case user drops more than one file?
Exactly!
kaveh1000 wrote: ↑Fri Nov 26, 2021 9:59 pm
In that case would it not be better to warn the user rather than take one of the files, namely the first one in the list?
You decide for your app.

-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Nov 26, 2021 10:16 pm
Thanks Klaus. just wanted to ensure I understood right.

Kaveh
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sat Nov 27, 2021 9:13 am
What happens when you drop three PDF document icons onto the Adobe Acrobat app icon?
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Nov 27, 2021 10:50 am
Acrobat will open all three files.
But this is a Livecode forum and not a quiz show, Richard!
I gave some advice since Kavehs script obviouly only exspected ONE file.
So I wrote:
to avoid surprises I always use -> line 1 of the dragdata["files"]
Unless my script(s) exspect more than one file.
I am sure Kaveh now knows that one needs a repeat loop if the user drops
more than one file and the script wants to accept and process all of them.
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sat Nov 27, 2021 1:46 pm
It's a question of designing apps that work as users are accustomed to seeing.
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Nov 27, 2021 1:50 pm
Yes, Richard.

-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Nov 27, 2021 3:28 pm
Hi Richard
The problem here is that I am dragging a file into a field. Allowing multiple files would be confusing. So it is quite logical to say you cannot drag multiple files. I am now using:
Code: Select all
on dragdrop
get dragData["files"]
if the number of lines of it > 1 then
answer "Please drag in only one file"
exit dragdrop
end if
get URL ("file:" & the dragData["files"])
put textdecode(it,"UTF8") into fld "original"
end dragdrop
Kaveh
-
Klaus
- Posts: 14190
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Nov 27, 2021 3:37 pm
Hi Kaveh,
hint:
Do not use IT more than neccessary, since IT may change when you least exspect IT!
Use an extra variable, which fortunately does not cost extra money:
Code: Select all
on dragdrop
put the dragData["files"] into tFile
if the number of lines of tFile > 1 then
answer "Please drag in only one file"
exit dragdrop
end if
put URL ("file:" & tFile) into tFileContent
put textdecode(tFileContent,"UTF8") into fld "original"
end dragdrop
Best
Klaus