Drag pdf from the desktop to a field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mluka
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Sun Jun 17, 2007 12:08 am
Location: Montréal, Canada

Drag pdf from the desktop to a field

Post by mluka » Tue Nov 21, 2017 3:50 am

Hi all.

OS X (10.12) and LC 8.

If I drag a pdf document from the desktop to a field, the only thing that gets copied is the document's name (the full path, actually).

Questions:
  • Is it possible to have the contents of the pdf document "inserted" into the field?
  • Is there an easy way, just by dragging from the desktop, to copy (icon + name) a pdf document and have that turn into an object (such as a button) that, when clicked, will "launch document..."
  • What about "png" documents? "jpg" documents?
What I'm trying to do: create some kind of "notebook" that would allow, in addition to text typed in, the copying of external documents into the notebook. A la Curio or OmniOutliner...

Thanks.
Michel
Montréal, Canada

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag pdf from the desktop to a field

Post by dunbarx » Tue Nov 21, 2017 3:12 pm

I do not think LC supports dragging text or pdf data into a field from the outside. Others may know better, though.

As for pulling something from the outside and having it appear as a native LC object, I believe you are limited to the actions of the "import as control" menuItem in the "edit" menu. Others may know better...

Craig Newman

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Drag pdf from the desktop to a field

Post by Klaus » Tue Nov 21, 2017 4:54 pm

Bonjour Michel,

of course LC supports Drag'n'Drop!

However PDF files can only be displayed in a Browser object out of the box on a Mac and on Windows if the Acrobat Reader web-plug-in has been installed.

To your questions:
1. See above, you cannot extract the text and/or images from a PDF file in Livecode and display it in a field object.

Example of Drag'n'Drop of file(s):
To "load" a dragged TXT document into a field, you need this in the script of that field:

Code: Select all

on dragenter
   ## Let this field accepty a Draga and Drop action
   set the dragaction to "copy"
end dragenter

on dragdrop
   
   ## we only need the first dragged file
   put line 1 of the dragdata["files"] into tFileName
   
   ## We only allow TXT files:
   if tFileName ends with ".txt" then
      
      ## We have a TXT file and load it into this field
      set the text of me to url("file:" & tFileName)
   end if
end dragdrop
2. This is also possible but requires the use of custpom properties and behaviours, although this might be possible without a behaviour. Ready for this?

3. Yes, what about PNG and JPGs? :D
LC can display these in an image object, so what is your exact question here?

Hint:
To learn the basics of Livecode, I recommend going through these stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9582
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag pdf from the desktop to a field

Post by dunbarx » Tue Nov 21, 2017 5:27 pm

Hmmm.

Everything Klaus said is true. Same for me

I think the OP was interested in the ability to drag objects, files and text directly from the desktop (from "outside" LC) either into LC directly as supported controls, or in the case of text, into LC fields.

But certainly within LC, drag and drop is fully supported.

Craig

mluka
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Sun Jun 17, 2007 12:08 am
Location: Montréal, Canada

Re: Drag pdf from the desktop to a field

Post by mluka » Wed Nov 22, 2017 4:01 pm

Hey guys! Thanks for the pointers.

I'll need a few days to look at them and figure out the limits of what's feasible. I'll come back with comments or, more likely, more questions.
I think the OP was interested in the ability to drag objects, files and text directly from the desktop (from "outside" LC) either into LC directly as supported controls, or in the case of text, into LC fields.
That's exactly it.

Thanks.
Michel
Montréal, Canada

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Drag pdf from the desktop to a field

Post by Klaus » Wed Nov 22, 2017 4:14 pm

Bonjour Michel,
mluka wrote:
Wed Nov 22, 2017 4:01 pm
I think the OP was interested in the ability to drag objects, files and text directly from the desktop (from "outside" LC) either into LC directly as supported controls, or in the case of text, into LC fields.
That's exactly it.
ah, OK, this is possible, but requires SOME preparation in Livecode! :D


Best

Klaus

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

Re: Drag pdf from the desktop to a field

Post by jacque » Wed Nov 22, 2017 5:50 pm

The basics for any external file drag operation is to get the filename and then script whatever you need to do with that.

Klaus' example does that with a text file, but any file type will work if LC has support for the format. For PDF files, the script would create a web view and load the PDF into it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mluka
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Sun Jun 17, 2007 12:08 am
Location: Montréal, Canada

Re: Drag pdf from the desktop to a field

Post by mluka » Wed Nov 22, 2017 6:17 pm

Hi Jacqueline. Thanks for the response.
create a web view
With "revBrowser"?
load the PDF into it
With "revBrowserOpen", for instance?

Thanks.
Michel
Montréal, Canada

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Drag pdf from the desktop to a field

Post by Klaus » Wed Nov 22, 2017 6:28 pm

Why not use the browser widget? Much more user (LC developer) friendly than the old revopenbrowser etc. stuff! :D

You could e.g. prepare a hidden browser widget on your card and show it in case someone dropped a PDF onto your card.

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

Re: Drag pdf from the desktop to a field

Post by jacque » Wed Nov 22, 2017 7:01 pm

Either revBrowser or a widget would work. It's also possible to create widgets on the fly if you need to.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Drag pdf from the desktop to a field

Post by MaxV » Thu Nov 23, 2017 5:32 pm

mluka wrote:
Tue Nov 21, 2017 3:50 am
Is it possible to have the contents of the pdf document "inserted" into the field?
A PDF is a complex binary object just to print, you can select the text from a reader a drag into a livecode field.
Otherwise you could use pdftotext program with the shell function, so you extract just the text.
mluka wrote:
Tue Nov 21, 2017 3:50 am
Is there an easy way, just by dragging from the desktop, to copy (icon + name) a pdf document and have that turn into an object (such as a button) that, when clicked, will "launch document..."
What about "png" documents? "jpg" documents?
Yes, that's very easy in livecode, see http://livecode.wikia.com/wiki/Drag_and_drop
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”