Use colorized text computed by SyntaxEditor in an other component

SyntaxEditor for WPF Forum

Posted 6 months ago by Stéphane Grenier
Version: 19.1.0685
Avatar

Hi,

I wanted to know if it's possible to have a read only component to show the colorized text computed by the syntax editor.

Let me explain the reason.

I would like to have a diagram, with a lot of boxes. Each box has text in it.

For example you can imagine a driagram with a lot of boxes representing C# files and in each box the C# code of the file.

I would like to show the colorized C# in each box, but without using the SyntaxEditor as component, because if I have a lot of boxes (more than 1000) I think that performances will be bad using SyntaxEditor (too many things in it).

The SyntaxEditor would be useful to edit one box at a time (for example: double click on the box could open a specific SyntaxEditor to edit the file)

Do you have a component to do that or something to create such component?

Thank you

Comments (5)

Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

SyntaxEditor can export colorized RTF, which you could then display in a RichTextBox.  That's one option for this kind of thing.

Alternatively and at a lower level, you could make a new EditorDocument with the syntax language set, and then get a snapshot reader and iterate the tokens.  You'd have to build up the colored text yourself based on the tokens you encounter.  The RTF way would be a lot easier.


Actipro Software Support

Posted 6 months ago by Stéphane Grenier
Avatar

Hello,

Thanks for your answer.

I've just tried your first option but performances aren't good enough.

I will try the second.

Thanks again

Posted 6 months ago by Stéphane Grenier
Avatar

By the way, how to know if the token is a comment, a keyword,...?

I've found the info in debug on classificationType attribute but it is not accessible

Thanks

Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm curious where the performance issue was you mentioned with the first option.  I would think that as long as you only loaded up the first 200 or so characters of your text into the document before exporting (so you aren't doing a lex of the entire document), it should be able to highlight that and export it fairly fast.  I would imagine you only need the first certain number of characeters anyhow as a preview.  And you should be able to load up an EditorDocument without any SyntaxEditor attached to do the export too.  That might help save on performance too.

For the other question, the core IToken interface is basic and doesn't have a ClassificationType property.  But the IMergableToken interface does, so your can cast to that (if it's implemented by the token) and get the IClassificationType that way.


Actipro Software Support

Posted 6 months ago by Stéphane Grenier
Avatar

Thank you.

No, export performances are good, my problem is not here but using the RichTextBox component

In my test I have more than 4000 RichTextBox and RichtTextBox have bad performances to load RTF and also to show the text

I've tested with TextBlock (in black), results are greater but now I have to pretty print from your AST to these TextBlock (using Runs)

-----

Edit: Now I can Pretty Print in my TextBlock, thanks to IMergableToken

Thanks again

[Modified 6 months ago]

The latest build of this product (v2020.1.1) was released 15 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.