Saving textstyle property "link" to a file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Saving textstyle property "link" to a file
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
Thank you for your help
-
- VIP Livecode Opensource Backer
- Posts: 9847
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Saving textstyle property "link" to a file
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Saving textstyle property "link" to a file
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.
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.
Re: Saving textstyle property "link" to a file
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 -
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
That is correct, ask when you want to save the file, answer when you want to open a file.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.
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
-
- VIP Livecode Opensource Backer
- Posts: 9847
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Saving textstyle property "link" to a file
HtmlText is a property of fields, not files. So instead of:
Code: Select all
put the htmltext of it into fld "Main"
Code: Select all
set the htmltext of fld "Main" to it
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9695
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Saving textstyle property "link" to a file
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
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.
Re: Saving textstyle property "link" to a file
Thank you for your help with the coding. It works like a charm.