Saving textstyle property "link" to a file

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Benajah
Posts: 3
Joined: Fri Feb 14, 2020 7:05 pm

Saving textstyle property "link" to a file

Post by Benajah » Fri Feb 14, 2020 7:19 pm

Hello I am a rank beginner trying to create a simple program to remote control qLab, A theatrical sound cue program. A play script is loaded into a field. Links are created within the text using set textstyle to link. By clicking on the links the field generates applescripts that fire qlab cues. My problem is that I do not know how to write the field contents to a file that will retain the textstyle formatting. I have tried rtftext and html text. What file format should I use to retain Live Code textstyle formatting? Or is there another way to create clickable links in the field that does not depend on textstyle "link"

Thank you for your help

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7307
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Saving textstyle property "link" to a file

Post by FourthWorld » Fri Feb 14, 2020 9:20 pm

HtmlText will reproduce field contents with complete fidelity. If that's not working for you we should explore why. Can you show us how you're reading and writing the data to and from disk?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Benajah
Posts: 3
Joined: Fri Feb 14, 2020 7:05 pm

Re: Saving textstyle property "link" to a file

Post by Benajah » Sat Feb 15, 2020 2:06 am

Thank you. I was an avid HyperCard user 30 years ago. So glad this platform exists.

I was looking for a way to send the LiveCode file in the forum but have not found the proper way to do it. I tried to attach the file but it was greyed out.

Here is the code for the save button. I found this code on the forums and adjusted it. In the end I should probably not use a button but do all this in a close stack handler and just hard code the file names.

so here is the code I was trying.

on mouseUp
set the useUnicode to true
ask file "Choose where you wish to export your text"
if the result = "cancel"
then exit mouseUp
else
put the HTMLtext of fld "Main" into url("file:" & it & ".htm")
get the longFilePath of it
set the itemDelimiter to slash
set the defaultFolder to item 1 to -2 of the longFilePath of it
end if
end mouseUp


Here is the code I tried for the read button. I don't know how to read a file properly. I tried to use this other code from the forums. I am obviously using ask file incorrectly because it seems to create or overwrite a file.

on mouseUp
ask file "which file would you like to load"
open file it for read
read from file it until EOF
put the htmltext of it into fld "Main"
close file it
end mouseUp

I have the AppleScript controlling qLab working. Just can't save the field contents.

bogs
Posts: 4211
Joined: Sat Feb 25, 2017 10:45 pm

Re: Saving textstyle property "link" to a file

Post by bogs » Sat Feb 15, 2020 4:03 am

Benajah wrote:
Sat Feb 15, 2020 2:06 am
I was looking for a way to send the LiveCode file in the forum but have not found the proper way to do it. I tried to attach the file but it was greyed out.
Being new to the forum, with only 2 posts at present, you will not have the ability to post links or attach items. Shortly, though, about 8 posts from now, you will 'graduate' to a level where you will be able to attach items.

As a side note, not a criticism, you *can* post scripting code within a 'code' block, which will condense the amount of space it takes up by wrapping it using the following button above your posting area -
Image

A few notes about your script in comments in below snippet -

Code: Select all

on mouseUp
   -- set the useUnicode to true # temporarily disabled as unicode isn't needed for this demo...
   ask file "Choose where you wish to export your text"
   /*
   if the result = "cancel"
   then exit mouseUp
   */
   # instead of testing for cancel this way, I would see if the result is *not* cancel, like so...
   if the result is not "Cancel" then put the effective htmlText of fld "Main" into url("file:" & it & ".htm")
end mouseUp
This is enough to save the file so that it looks like this in a text editor -
Image
Here is the code I tried for the read button. I don't know how to read a file properly. I tried to use this other code from the forums. I am obviously using ask file incorrectly because it seems to create or overwrite a file.
That is correct, ask when you want to save the file, answer when you want to open a file.

To re-open the file, you simply put the url back into the field, in this case I made a second field, but you can re-use your original field.

Code: Select all

on mouseUp
# try 'answer' file, not ask, to open a file...
answer file "which file would you like to load"
if it is not "" then set the htmltext of fld "subMain" to url("file:" & it)
end mouseUp
I've attached this rather small demo, tested and working on 'nix, for you to test out.
htmlText-Test.zip
htmlText-Test...
(11.15 KiB) Downloaded 5 times
*Edit - I have included no error checking at all in the above code snippets, but highly suggest that you should *always* use error checking even for simple operations like the code listed above.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7307
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Saving textstyle property "link" to a file

Post by FourthWorld » Sat Feb 15, 2020 10:55 am

Benajah wrote:
Sat Feb 15, 2020 2:06 am
on mouseUp
ask file "which file would you like to load"
open file it for read
read from file it until EOF
put the htmltext of it into fld "Main"
close file it
end mouseUp
HtmlText is a property of fields, not files. So instead of:

Code: Select all

 put the htmltext of it into fld "Main"
Use:

Code: Select all

 set the htmltext of fld "Main" to it
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Saving textstyle property "link" to a file

Post by dunbarx » Sat Feb 15, 2020 6:24 pm

Hi.

If you were an avid HC user, you will soon be a far more avid LC user.

I was once a rabid HC loser. I am now an avid LC abuser.

Craig
Last edited by dunbarx on Sat Feb 15, 2020 10:02 pm, edited 1 time in total.

Benajah
Posts: 3
Joined: Fri Feb 14, 2020 7:05 pm

Re: Saving textstyle property "link" to a file

Post by Benajah » Sat Feb 15, 2020 7:13 pm

Thank you for your help with the coding. It works like a charm.

Post Reply

Return to “Mac OS”