Sign in to follow this  
benryves

[.net] Syntax highlighting controls?

Recommended Posts

I'm developing a little Z80 IDE, and one of the requirements I've had is syntax highlighting. Unfortunately, this has proved a major speed issue, so I'm wondering if anyone has found a decent free control that is fast and non-buggy. Most of the ones I've found do some magic with the RichTextBox but are full of bugs or painfully slow. The commercial ones are way out of my budget for my little free tool.

Share this post


Link to post
Share on other sites
RTF is a lot like HTML, maybe you could use the RTF control and edit the RTF manually instead of using the "select text->set color->unselect text" process that most of those free controls use.

I know, I've tried setting it up myself before, and it is a pain in the ass. I've thought about just scrapping the text controls all together and writing one from scratch off of the generic System.Windows.Forms.Control class and handling all the events and painting myself. Not fun.

Share this post


Link to post
Share on other sites
Alright, I gave up and wrote my own from scratch. I was already doing a text-to-RTF conversion as capn_midnight suggested, but now track the cursor position and extract and change the SelectedText and SelectedRTF properties (locking the window handle of course to eliminate flickering).

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
Is there any chance of you will be releasing this control? I know there are a lot of people in need of such user control.
It has a few bugs of its own (files > 3000 lines jump the scroll bar to the wrong position - Win32 limitation, I assume) and is still not incredibly fast (5 seconds to load a 2000 line file now) and it's not very well designed in terms of being used as an external control (not adding any seperator characters causes it to delete any source you put in it). Probably not in other words, unless you wanted to tweak it yourself.

EDIT: as a "try before you buy", download this and unzip it, then unzip this on top of it (the second file is an update). If you open one of the sample projects (in the Projects folder), hit Ctrl+Space to see the awesome slowness, or open ti83plus.inc for another demo. [sad]

Share this post


Link to post
Share on other sites
I've been using the rich text control myself...

to give you an idea of what I've managed:

older pic (more complex shader) and a newer pic.

There has definitly been a number of things I've learnt... but a few big ones:

make sure you are only reparsing as little as possilbe :P this is hard but hopfully obvious.
Colour only areas that have changed if typing. if you insert text yourself, you will need to recolour everything.
The big one however, is to overload the 'Text' property of the RTF class with your own variation that does some caching. the Text reconstructs the text in the RTF every single time you call it, it's *really* slow.

The source isn't avaliable just yet, and it ain't pretty eiether..


of course the *vast* majority of the work there was the parser... Oooo boyo that code can get interesting. (yeah I kinda decided to write my own shader fragment format... o well)

Share this post


Link to post
Share on other sites
Quote:
Original post by RipTorn
of course the *vast* majority of the work there was the parser... Oooo boyo that code can get interesting. (yeah I kinda decided to write my own shader fragment format... o well)
True, but parsing itsn't a problem in this case since there are no dependencies between the lines. At least not unless he's using some weird assembler..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this