Another link in text question

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

Post Reply
peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Another link in text question

Post by peter.s » Mon Oct 11, 2010 9:06 am

Thanks to some help from many of you on this forum, I can set a text link in a body of text by specifying the word and also the destination of the link by specifying the word of each of the links.

But now I have a body of text with the same word repeated as a link. How do I differentiate between them by location in the text field?

For example: I want to use the word "Open" in a body of text, as a link to open a PDF. But I have 3 different PDFs and 3 links called "Open" in my text.

I have tried using the wordOffset or lineOffset to define the location of a particular link - but with no success. And I don't understand what the linkText is if it isn't a link in text... I'm baffled.

Peter

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

Re: Another link in text question

Post by jmburnod » Mon Oct 11, 2010 5:05 pm

Hi Peter,

You can do a list with the offset of each link like that:

startWord,EndWord,The handler

34,37,Myhandler1
133,136,MyHandler2
222,225,Myhandler3

and

1.search the mousechunk in the list by lineoffset
2.get item 3 of the found line
3.do it

I hope this help

All the best

Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Another link in text question

Post by bn » Mon Oct 11, 2010 6:42 pm

Peter,
could you explain a little more what exactly you want to do? What is the linktext for the three occurences of open? is it always open? Or do you specify an actual link in the linkText, like pdf1, pdf2, pdf3?
lets say you have a text where word 6 is "open" you could say:

Code: Select all

set  the linktext of word 6 of field 1 to "open" && quote & "myPathToPDF" & quote
then you could ask from the messageBox

Code: Select all

put the linktext of word 6 of field 1
this would give you:
open "myPathToPDF"
or you search all the words "open" in a text and do something like above with wordOffset and get the linkText of the wordOffset like above. You would do a

Code: Select all

wordOffset(wordToFind,stringToSearch[,wordsToSkip])
with the wordsToSkip.-> dictionary.


Or do you want to react to a user clicking?
In the handler of the field you would have a handler

Code: Select all

on mouseUp
   put the linkText of the mouseChunk into tMyVar
   if tMyVar is not empty then doWhatYouWant
end mouseUp
this works only on a lockedText text field, otherwise there is no mouseUp message.

If you want to see where the linkText is actually hidden then make a field, put some text into it, set the linktext of some words and then make a second field and a button. In the button:

Code: Select all

put the htmlText of field 1 into field 2
There is your linktext. If you knew this all already then nevermind.

is this an answer to your question of did I get it all wrong?
regards
Bernd

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Another link in text question

Post by Regulae » Mon Oct 11, 2010 10:35 pm

Hi Peter,

Attached is a stack which may include some of the features you are looking for. It also has some discussion which could add to the suggestions others have made. It's in a folder so as to include a pdf which it uses for demonstration purposes.

Regards,
Michael
Attachments
LinkTestFolder.zip
(12.83 KiB) Downloaded 299 times

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Another link in text question

Post by peter.s » Tue Oct 12, 2010 12:26 am

Thanks again for your terrific example Michael - and to the other responses to my message.

Judging by Bernd's response, I don't think I was very clear in my initial description - writing out of frustration I think - sorry about that.

I am making a presentation stack which will be a standalone on a DVD. The viewer/user will read information in scrolling fields and navigates to different cards for different information, and click on links to web sites, video clips and PDFs. The user does not interact with the text - therefore all the text fields are locked.

In one of my text fields for example, I am referring to several different articles which are (will be) saved as PDFs in a folder on the disc. The text will give the title of the documents (which are so long it will look silly to make a link out of it) along with a brief description and then a link. Eg: "Open" the PDF

I am using the following script to create the links in the text field:

Code: Select all

on opencard
   lock screen 
   repeat with i = 1 to the num of words of fld "field"
      if word i of fld "field" is "Open" then
             set the textstyle of word i of fld "field" to link
         set the textcolor of word i of fld "field" to "blue"
  end if
end repeat
unlock screen
end opencard
My trouble now is that I have several links all called "Open". How do I make the first link open PDF-A, the second open PDF-B, and so on?

Michael's example stack is very good in what it presents and probably offers me the solution to this problem, but I am having trouble getting my head around it - to pare it down to meet my simple requirements. I have already utilised some of it to display little information windows on mouseOver - but this next step…

I feel like I am a bicycle mechanic trying to build a car.

Peter

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Another link in text question

Post by bn » Tue Oct 12, 2010 12:52 am

Peter,
in your example you forget what to link to: the linkText.
That is what the click on the word with the link style fires off in the in the mouseUp handler I provided above does. You have to know in your script which word "open" is supposed to open which pdf and then you set the linkText of word "open" to a reference of the respective pdf.

just setting the link stylewithout a corresponding linkTextwill not be enough.
The text will give the title of the documents (which are so long it will look silly to make a link out of it) along with a brief description and then a link
The linkText is not visible to the user, it is stored in the htmlText of the field. You could easily set the linktext of the title of the article without setting the style of the article title to "link", if the presenter knows that he has to click on the title to show the pdf that is enough. The linktext could be the complete path to the pdf. Then you use the form I mentioned above:

Code: Select all

on mouseUp
   put the linkText of the mouseChunk into tMyVar
   if tMyVar is not empty then open tMyVar
end mouseUp
You would have to display the pdf in the browser object or in an external program.

I hope that makes any sense. If not just say so. We will help you to get over this.

regards
Bernd

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Another link in text question

Post by WaltBrown » Tue Oct 12, 2010 6:23 am

So Bernd, just to clarify, to do this for any N words in a field you would need to do:

Code: Select all

set the linkText of word 37 in field "myField" to linkToFile1
set the linkText of word 162 in field "myField" to linkToFile2
set the linkText of word 195 in field "myField" to linkToFile3
set the linkText of word 267 in field "myField" to linkToFile4
-- etc, etc, for each word needing a link
The word positions would have to be known ahead of time, especially if the word was also used in the text content.

Or as alternative, intuiting from the initial description with the word "Open", if there was a specific unique token one wanted to link and their order was known, one could have?

Code: Select all

put "For More Details, Click Here" into tMyToken
find empty -- To clean up if there were any previous finds
repeat with tCounter = 1 to the number of lines in field "fMyLinks"
      find tMyToken in field "fMyDisplayText"
      set the linkText of the foundChunk to line tCounter of field "fMyLinks"
end repeat
Just a thought,
Walt
Walt Brown
Omnis traductor traditor

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Another link in text question

Post by bn » Tue Oct 12, 2010 1:33 pm

Walt,
if your post was a question then yes. If it was a help for Peter then it helps to understand.

If Peter insists on using the word open then he could look at the words before the word open if they match a title of his PDFs and then set the linkText to that.

I would do the setting of the linkText a little differently in a semi-structured text as Peter is apparently working on. With semi-structured I mean that Peter always has the title of a pdf in the text. Peter knows the paths to the pdfs. If he wanted to he could take a list of the title of the pdfs lets say title & tab & fullpathToPDF. He could set the itemdelimiter to tab and search for the item 1 of line x in the text-> that would be the title, then set the linktext to item 2 of the of the list.

@ Michael
I think Michael's extensive sample stack with clearly commented scripts is a very good introduction to the linkText problem. Michael you might consider to make a lesson from that for Rev.

but now lets wait whether Peter recovers from frustration... :)

regards
Bernd

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Another link in text question

Post by peter.s » Tue Oct 12, 2010 11:36 pm

Thanks Bernd - I am recovering from my frustrations. :)

I think I understand the linkText property (it's a bit like the identity of the link?), but I'm not sure if my problem is about the linkText.

I will re-read the post and the supporting rev documents about linkText and write again soon.

Cheers for now...

Peter

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Another link in text question

Post by Regulae » Wed Oct 13, 2010 4:43 pm

Hi Peter,

I think you’re fast closing in on a successful approach to links that meets your requirements. As a matter of interest, I thought I’d examine how a script you posted earlier:

Code: Select all

on opencard
   lock screen 
   repeat with i = 1 to the num of words of fld "field"
      if word i of fld "field" is "Open" then
             set the textstyle of word i of fld "field" to link
         set the textcolor of word i of fld "field" to "blue"
  end if
end repeat
unlock screen
end opencard
... might be adapted to allow you to set the linkText for each occurrence of the word “open”. It’s a good way to explore how linkText may be used. I’ve attached a small stack for this purpose.

@ Bernd
I appreciate the suggestion concerning the previous stack- it would have to be slightly re-worked to generalise it, as it presupposes the specifics of some of Peter’s earlier questions. Something that has been on my mind for some time now is that LiveCode, by being accessable to a wide range of users and also highly communicable, raises some interesting, and somewhat new, explanatory challenges. We see on the forum people from diverse programming backgrounds and in different countries discussing things that would be quite a challenge to communicate, even if you were standing face-to-face. Perhaps LiveCode developers can develop more effective ways of using LiveCode to explain LiveCode to other developers. The previous sentence does look odd- it’s rather self-referential, but I think there’s something in the thought. Perhaps developments in the area of explanation techniques could act as a “knowledge multiplier”, further expanding the LiveCode user-base. Just a speculation on my part.

Regards,
Michael
Attachments
LinkText Discussion.zip
(4.28 KiB) Downloaded 287 times

peter.s
Posts: 99
Joined: Thu Jul 10, 2008 11:47 am

Re: Another link in text question

Post by peter.s » Thu Oct 14, 2010 1:20 pm

I’ve attached a small stack for this purpose.
Hi Michael,

The "small" stack is larger than you think!

Thank you so much for breaking it down so clearly for me... I think I finally get it.

To be sure I do understand it correctly - I can use the script to "set up" the program in the development stage and then delete the script before saving it as a standalone application? Presumably the textStyle and linkText of the text in the fields will remain?

Further from this - I guess I can create the link textStyle with the "Text" controls in the Rev menu bar rather than using the first part of the script?

If this is so, it has made my whole life so much better! My project has grown exponentially and the idea of fussing over every link has kept me up at nights.

I will be putting this into practice on the weekend and I trust I will happily meet with success.

All the best,

Peter

By the way - I agree with Bernd, they would make excellent lessons for Rev

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Another link in text question

Post by Regulae » Thu Oct 14, 2010 4:14 pm

Hi Peter,

Glad to hear the stack was informative. You are quite correct- once you’ve set the textStyle to "link", and established the linkText for each link using the script, all these settings are now incorporated in the htmlText of the field, and are preserved when you save the stack as a standalone application. Having done its job for you as the stack’s developer, buttons like the “Create the links” button are no longer needed. You can delete it before building the standalone. Naturally, the only script that has to be there for the links to work is the linkClicked handler, in the card script, or if you want it accessible to links on several different cards, the stack script.

You’re also right that you can set the textStyle to link using the text controls in the Rev menu bar, and it’s really only the linkText that must be set by script- though as you’ve seen, this is straight forward. This is something Bernd checked out in another thread (Re: Formatting text in text fields?), and he includes a neat script that lets you check and set the linkText for individual links if desired.

So I do think you’re heading in the right direction. You mention the project is growing exponentially- that’s so often the way of things, and a byproduct of good progress. Keep firing questions at the forum if you hit any problems. I’m sure that current and future readers will benefit from the discussion that ensues.

Regards,
Michael

Post Reply