Page 1 of 2

Drag and drop Unicode file

Posted: Fri Nov 26, 2021 5:00 pm
by kaveh1000
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?

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 5:12 pm
by Klaus
Hi Kaveh,

you little script will only put the filename of the file into the message box. :D
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

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 5:22 pm
by kaveh1000
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.

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 5:26 pm
by Klaus
Hi Kaveh,

to avoid surprises I always use -> line 1 of the dragdata["files"] 8)
Unless my script(s) exspect more than one file.


Best

Klaus

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 5:52 pm
by kaveh1000
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?

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 6:11 pm
by Klaus
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! :D
We all know how users are, so this is neccessary in my opinion.

Best

Klaus

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 9:59 pm
by kaveh1000
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?

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 10:15 pm
by Klaus
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. :-)

Re: Drag and drop Unicode file

Posted: Fri Nov 26, 2021 10:16 pm
by kaveh1000
Thanks Klaus. just wanted to ensure I understood right. :-)

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 9:13 am
by FourthWorld
What happens when you drop three PDF document icons onto the Adobe Acrobat app icon?

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 10:50 am
by Klaus
Acrobat will open all three files.
But this is a Livecode forum and not a quiz show, Richard! :D :D :D

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"] 8)
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.

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 1:46 pm
by FourthWorld
It's a question of designing apps that work as users are accustomed to seeing.

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 1:50 pm
by Klaus
Yes, Richard. 8)

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 3:28 pm
by kaveh1000
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

Re: Drag and drop Unicode file

Posted: Sat Nov 27, 2021 3:37 pm
by Klaus
Hi Kaveh,

hint:
Do not use IT more than neccessary, since IT may change when you least exspect IT! :D
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