A link conundrum

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
ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

A link conundrum

Post by ajperks » Sun Nov 11, 2018 4:52 pm

I have been adding the facility of links to my project.
The experimental code below works fine in the text field it is attached to when I want to create a link or remove an existing one. In so doing, I have no way to actually click and run the link.
How is this typically done?

Code: Select all

on mouseup
   select the clickChunk
   if the textStyle of the clickChunk =  "link" then
      set the textStyle of the clickChunk to  "plain"
   else
      set the textStyle of the clickChunk to  "link"
      set the linkText of the clickChunk to  "https://www.livecode.com"
   end if

end mouseup

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: A link conundrum

Post by jmburnod » Sun Nov 11, 2018 6:29 pm

Hi,
I see to ways now:
1. If that is for desktop app you may use option key to open your edit tools.
2. Using the delay between mouseDown and mouseUp to decide what your script does.
Best regards
Jean-Marc
https://alternatic.ch

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

Re: A link conundrum

Post by dunbarx » Sun Nov 11, 2018 10:01 pm

Hi.
I have no way to actually click and run the link
Why not include a line containing the "launch url..." command?

Craig Newman

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: A link conundrum

Post by quailcreek » Sun Nov 11, 2018 11:11 pm

I'm not sure why you're adding a removing the links that way. I usually set up all the links in the IDE and leave them.

Code: Select all

set the textStyle of line 1 of fld "The Fld" to  "link"
      set the linkText of line 1 of fld "The Fld" to  "https://www.livecode.com"
Then in the fld script do your navigation to the URL or whatever.
Tom
MacBook Pro OS Mojave 10.14

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: A link conundrum

Post by jmburnod » Mon Nov 12, 2018 10:23 am

Here is a way with a timer to get one difference for mouseup message.

Code: Select all

local sDepTime
on mousedown
   put the seconds into sDepTime
end mousedown

on mouseup
   if the seconds - sDepTime > 3 then 
      select the clickChunk
      if the textStyle of the clickChunk =  "link" then
         set the textStyle of the clickChunk to  "plain"
      else
         set the textStyle of the clickChunk to  "link"
         set the linkText of the clickChunk to  "https://www.livecode.com"
      end if
   else
      if the textStyle of the clickChunk =  "link" then -- 
         get the linkText of the clickChunk
         launch url it
      end if
   end if
end mouseup
https://alternatic.ch

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: A link conundrum

Post by ajperks » Mon Nov 12, 2018 10:37 am

Hi, Craig. The act of adding or removing a link by touch or click of it prevents the option of clicking on it to run it. Adding the url code is fine, but how can you click on the link to run it if so doing removes or adds it. That is the problem here.
Quailcreek, this text is not static or predictable so the user needs 3 options.
1. Create a link at the word of choice. A dialogue box would ask for the destination of the new link.
2. To remove a link created by mistake, by the user. Finger trouble...
3. To click the link to do what the link intended.
Obviously, only the first 2 are possible the way I have approached it. It needs to be simple and intuitive, not the pot luck approach of typical social apps i have looked at. All of which have a poor user interface, according to those who pontificate on the subject.

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: A link conundrum

Post by ajperks » Mon Nov 12, 2018 10:42 am

Jmburnod, I think you are on the right lines here. Very imaginative. Your my kinda guy.
I see no actual downside to your idea, because once the link is created and correct, it won't need to change. Brilliant...

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: A link conundrum

Post by ajperks » Mon Nov 12, 2018 4:34 pm

The final result of the challenge is in the attached ZIP
I tidied it up and made it so some other newbie can copy and paste the field, button and the scripts into their own project.

It is quite easy to follow I believe and I hope you find it interesting / useful.
Link or unlink or run link.zip
(2.09 KiB) Downloaded 227 times

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

Re: A link conundrum

Post by dunbarx » Mon Nov 12, 2018 5:58 pm

I don't use links much, but what is missing from this, with regard to what you say you cannot do "in line"?

Given a locked field with a few lines of correctly formed urls, in the field script:

Code: Select all

on mouseup
   put the value of the clickLine into tLink
   select the clickChunk
   if the textStyle of the clickChunk =  "link" then
      set the textStyle of the clickChunk to  "plain"
   else
      set the textStyle of the clickChunk to  "link"
      set the linkText of the clickChunk to  "https://www.livecode.com"
   end if
launch url tLink
end mouseUp
Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: A link conundrum

Post by jmburnod » Mon Nov 12, 2018 6:36 pm

Hi Craig,
what is missing from this, with regard to what you say you cannot do "in line"?

Code: Select all

put the value of the clickLine into tLink

only works if each line = a whole url.
ajperks use linktext to store url in a string and he need a condition to make 3 different things
Jean-Marc
https://alternatic.ch

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

Re: A link conundrum

Post by dunbarx » Mon Nov 12, 2018 7:11 pm

Fair enough. Then is the point that if one has:

Code: Select all

 some words here   http://www.liveCode.com  some more words here
the "clickText" will not include the "http://" portion? Certainly unless a string of text is "grouped" via having its link property set, LC will not see it as a single "word". And similarly "the value of the clickLine" is perhaps a bit too inclusive?

But is that the sole issue here? If so, it seems that there is a simple way forward.

Craig

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: A link conundrum

Post by ajperks » Tue Nov 13, 2018 6:05 pm

The complete stack I attached earlier, a couple of posts up) is the final, working solution.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”