CodeEditorComponent

FYI I’ve just checked-in an extremely “alpha” version of some source code editing classes.

I mentioned this a while back and a few people expressed an interest, so feel free to have a look and see what you think of the approach I’ve taken.

Obviously it’s very fresh code, and I’ve not even added a demo for it yet, but would like to hear what you think!

atom@suonko:~/devel/juce$ git pull
Already up-to-date.
atom@suonko:~/devel/juce$ grep -R CodeEditorComponent *
atom@suonko:~/devel/juce$

what’s the name of the component ?

Sorry, I checked it in but forgot to do a ‘git push’… It’s there now!

it works !

very nice, i didn’t do any extensive tests for now, should we expect any increased performance then the TextEditor ?

Will it handle NULLs in code ?

the tokenizer class looks complicated at first glance. the CPP tokeniser looks impressive, and a good codebase for other tokenisers i think.

great stuff.

Yes, it’ll be vastly faster than the texteditor. I tried using it to open the mighty juce_amalgamated.cpp and it handled it just fine.

[quote]
Will it handle NULLs in code ?[/quote]
no chance!

Just an idea.

Do you think it would be more flexible to make the tokenizer class read some sort of a serialized file, that would hold all keywords, functions and reserved words, instead of hard-coding it in the class.

This is what SCITE does, it has special .api files that you can load on demand, and the code highlighting changes. It’s opensource, and you can have a look at some examples here: http://groups.google.com/group/scite-interest/web/extras?pli=1

i guess it would be better if those files where XML files with a strict schema described for those tokeniser classes.

Well, the tokeniser base class could be used to write a parser for those scite files, no problem. But I just wanted to get something going, which is why I wrote the c++ one.

It’d have to be very well optimised though - the tokeniser is the main thing that eats cpu in the editor, and even with my simple c++ parser I had to hand-optimise bits of it to make it run nicely.

Since i wanted to use the code editor for plaintext files, i just added this code, it would be a nice fallback class

class PlainTextTokeniser : public CodeTokeniser
{
	public:
		int readNextToken (CodeDocument::Iterator& source) 
		{
			source.skip();
			return (0);
		}
		
		const StringArray getTokenTypes()
		{
			StringArray s;
			s.add (String::empty);
			return (s);
		}

		const Colour getDefaultColour (const int tokenType) 
		{ 
			return (Colours::black); 
		}
};

You can actually pass 0 for the tokeniser to do plain-text.

Does that means that I can use this component instead of Text Editor(since efficiency is better)

well i didn’t know that :), i’ll do that

also since i have a find feature in my editor, there was a nice handy method for selecting a portion of text in the TextEditor, i can’t find that in the new component i have to do

CodeDocument::Position pos(dataSource, matchIndex);
editorComponent->moveCaretTo (pos, false);
pos.setPosition (matchIndex + match.length());
editorComponent->moveCaretTo (pos, true);

Just checked in a version with better comments and a few tweaks.

I’ll be adding a lot more useful methods for finding and selection as it progresses…

[quote]
Does that means that I can use this component instead of Text Editor(since efficiency is better)[/quote]

Of course - if you’re ok with fixed-width fonts and no line wrapping.

[quote=“jules”]Just checked in a version with better comments and a few tweaks.

I’ll be adding a lot more useful methods for finding and selection as it progresses…

[quote]
Does that means that I can use this component instead of Text Editor(since efficiency is better)[/quote]

Of course - if you’re ok with fixed-width fonts and no line wrapping.[/quote]

In that case, it can’t replace text editor everywhere but there are places where I can find it useful. Thanks Jules

wow this came just on time!!! amaizing stuff!

i have a request for a function:
setScrollbarThickness(int);

and
setScrollbarListener(Listener);

so i can make a line numbers module
:slight_smile:

Speaking as one of those happy few, I love you man.

I’ll dig into this just as soon as I have time enough to stop and breathe. :slight_smile:

[quote]i have a request for a function:
setScrollbarThickness(int);

and
setScrollbarListener(Listener); [/quote]

Probably be better to have a listener that gets told when the cursor moves?

I’m also planning on allowing the gutter to be a custom component, so that might be better for what you’re trying to do.

the cursor itself? or the top line position?
yes indeed a custom gutter component or a virtual paintGutter would do,
i thought about just editing the paint function

A listener would be able to provide both.