Page 1 of 1
_internal script colorize [SOLVED]
Posted: Fri Nov 25, 2022 10:34 am
by stam
Hi all,
I know this is not supported API and that it's a bit of a dark art...
I format/auto-indent fields that contain liveCodeScript using Mark Waddingham's advice
here the code, which works seamlessly and always.
I colourise the script in a field using the code shown by James Hale James Hale's advice
here.:
Code: Select all
_internal script colorize char 1 to (the number of chars in field "x") of field "x"
Colorisation is great, but weirdly doesn't work all the time. Specifically once I get it to work then it always works until quitting LC. If I launch the stack directly (i.e. it's the first stack to be opened) it's just doesn't work through any script.
I finally realised that the simple action of opening the message box or the script editor actually fixes that so a clunky work around is to open/close the message box at preOpenStack, and then the colorisation works as expected.
Clearly there is some sort of initialisation that happens when opening the msg box but or script editor which doesn't happen when I just open my stack -- does anyone have any idea what this is and how I can include it in my stack so I don't have to use the clunky workaround of opening/closing msgBox?
Many thanks
Stam
Re: _internal script colorize
Posted: Fri Nov 25, 2022 11:11 am
by bn
Stam,
maybe you can try
Code: Select all
_internal script colorize char 1 to (the number of chars in field "x") the long id of field "x" of this stack
It could be that without the long id field "x" is not resolved properly somehow.
In tinyDictionary I use a different way by the intermediary of stack "revSEUtilities
Code: Select all
dispatch "revSEColorizeField" to stack "revSEUtilities" with the long id of field "fRes" of this stack, tStartChar, tEndChar
I have not seen this fail.
Kind regards
Bernd
Re: _internal script colorize
Posted: Fri Nov 25, 2022 12:33 pm
by AndyP
Nearly right.
Try this with xxxx being the id of the fld x
Code: Select all
_internal script colorize line 1 to (the number of lines in fld "x") of fld id xxxx of this stack
Re: _internal script colorize
Posted: Fri Nov 25, 2022 2:35 pm
by bn
Hi Andy,
OK, I goofed up in my sample code to pass the long id.
This code does not work!
Code: Select all
_internal script colorize char 1 to (the number of chars in field "x") the long id of field "x" of this stack
This code compiles and actually works and sends the long id instead of just the id of the field
Code: Select all
put the long id of field "xField" into tLongID
_internal script colorize char 1 to (the number of chars in field "xField") of tLongID
Of course field "xField" has to be unique.
Kind regards
Bernd
Re: _internal script colorize
Posted: Fri Nov 25, 2022 3:04 pm
by AndyP
Hi Bernd,
I like this variation, one for my scrapbook
Code: Select all
dispatch "revSEColorizeField" to stack "revSEUtilities" with the long id of field "fRes" of this stack, tStartChar, tEndChar
Re: _internal script colorize
Posted: Fri Nov 25, 2022 3:59 pm
by LCMark
The internal colorize stuff needs to be configured before it will do anything useful. The code the SE (and message box uses) is in revseutilities... This doesn't get initialized until it is first used - the easiest thing to do is to use the utility handler Bernd suggested in there, as that ensures the current IDE's colorization theme is configured before it colorizes.
(Alternatively just prod around in that script a bit - basically you can configure keywords and classes - the former are specific colors/styles for different keyword tokens, the latter are the colors/styles for different kinds of token).
Re: _internal script colorize
Posted: Fri Nov 25, 2022 5:48 pm
by dunbarx
I have a plug-in that colorizes one or more portions of text in the SE. I place markers, say "XXX" at the beginning and end of the sections I want. I then just find the lines those two string live on, and (Abbreviated):
Code: Select all
set the backColor of line startLine to endLIne of fld 1 of stack "revScriptEditor1" to "yellow"
I am at my home computer, where I do not do this, so I am not quite sure I have the precise name of the SE at work correctly.
Anyway, I can leave one or more pairs of markers in the SE, and colorize whenever I want.
Craig
Re: _internal script colorize
Posted: Fri Nov 25, 2022 9:55 pm
by stam
Thanks Craig - to clarify this is regarding syntax colouring (as in the SE) but in a normal field...
My problem was that as Mark mentioned there is some initialisation required, but it's a bit dark-magic.
Not been able to yet, but I'll try the suggestions above and report back - thank you all!
S.
Re: _internal script colorize [SOLVED]
Posted: Sat Nov 26, 2022 5:38 pm
by stam
Thanks to LCMark, AndyP and Bernd - the solution that worked easiest is:
AndyP wrote: ↑Sat Nov 26, 2022 1:53 pm
Code: Select all
put the num of chars of fld "myField" of this stack into tEndChar
dispatch "revSEColorizeField" to stack "revseutilities" with the long id of field "myField" of this stack, 1, tEndChar