Copying a line of text into the clipboard [SOLVED]

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
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Copying a line of text into the clipboard [SOLVED]

Post by atout66 » Thu May 01, 2014 9:20 am

Hi to all,

Sorry to ask such an obvious question in appearance, but my script below does not work despite the consultation of the dictionary and the application of different examples.
I would like to understand why ?

Code: Select all

 if the hilitedLine of field "myFld" is NOT empty then -- <"myFld"> is a list field
          put the selectedText of fld "myFld" into laSelection -- OK, <laSelection> is not empty
          copy char 1 to -1 of laSelection -- issue here !?!  the dictionary adds <of me> but here it doen't apply
     else -- 
I must add that

Code: Select all

copy laSelection
does not work either.
Kind regards, Jean-Paul.
Last edited by atout66 on Thu May 01, 2014 10:35 am, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Copying a line of text into the clipboard

Post by jmburnod » Thu May 01, 2014 9:55 am

Bonjour Jean-Paul,
I think you need somethink like this
For a fld

Code: Select all

  set the clipboarddata[text] to the selectedtext
For a listField

Code: Select all

get line (the hilitedlines of fld 1) of fld 1
set the clipboarddata[text] to it
Kind regards
Jean-Marc
https://alternatic.ch

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Copying a line of text into the clipboard

Post by atout66 » Thu May 01, 2014 10:35 am

Merci Jean-Marc, tu as trouvé la solution :wink:

I'm going to avoid of thinking why my code didn't work, it's not the right day for that :lol:

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying a line of text into the clipboard [SOLVED]

Post by Klaus » Thu May 01, 2014 11:14 am

Lazy moi:
...
set the clipboarddata[text] to the selectedtext of fld 1
...
And this avoids using IT unneccessarily :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Copying a line of text into the clipboard [SOLVED]

Post by atout66 » Thu May 01, 2014 11:45 am

You're right Klaus, IT is allowed to do the less possible :)
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying a line of text into the clipboard [SOLVED]

Post by Klaus » Thu May 01, 2014 1:59 pm

atout66 wrote:IT is allowed to do the less possible :)
Exactement! :D

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Copying a line of text into the clipboard

Post by magice » Thu May 01, 2014 4:03 pm

atout66 wrote:
I'm going to avoid of thinking why my code didn't work, it's not the right day for that :lol:
I prefer using Klaus' method, but if you want to know how to do it using "copy", you can try this.

Code: Select all

select the text of fld "myFieldName"
copy
I know it feels wrong throwing out a command without any parameters, but it works.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Copying a line of text into the clipboard [SOLVED]

Post by FourthWorld » Thu May 08, 2014 6:46 pm

Using the copy command without parameters may seem strange if you're used to more complex languages, or necessary if you're implementing an unusual interface.

The clipboard belongs to the user, and an application should preserve anything the user has explicitly placed in it. Using it for any other purpose risks overwriting data the user had copied that may be important to them, perhaps even for use in other applications unrelated to yours.

In most applications, copy works on an active text selection within an editable field. In that most common scenario, LiveCode makes it as simple as can be to do what you want while leaving the user in control:

Code: Select all

copy
...is all you need, provided the user has selected a range of text to copy.

It's very rare that copy is allowed for uneditable text in a list field. Offhand, I can't think of any examples where I've seen that. It may indeed be a very useful thing to provide in your specific application, but in such an unusual circumstance we can expect to need unusual syntax to support it.

Thankfully, as the others here have shown, LiveCode is flexible enough that it requires at most just a few extra tokens or a second line of code to do even uncommon things like this.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Copying a line of text into the clipboard [SOLVED]

Post by atout66 » Thu May 08, 2014 8:45 pm

Great lesson Richard, thanks :wink:
Discovering LiveCode Community 6.5.2.

gilgml
Posts: 26
Joined: Wed Jun 16, 2021 3:35 am

Re: Copying a line of text into the clipboard [SOLVED]

Post by gilgml » Mon Dec 20, 2021 1:31 am

@magice & @fourthworld : Neat and Slick :D

Post Reply