jules
November 3, 2009, 7:01pm
1
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
November 3, 2009, 7:52pm
2
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 ?
jules
November 3, 2009, 9:03pm
3
Sorry, I checked it in but forgot to do a ‘git push’… It’s there now!
atom
November 3, 2009, 9:58pm
4
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.
jules
November 3, 2009, 10:13pm
5
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!
atom
November 4, 2009, 10:32am
6
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.
jules
November 4, 2009, 10:52am
7
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.
atom
November 4, 2009, 1:06pm
8
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);
}
};
jules
November 4, 2009, 1:12pm
9
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)
atom
November 4, 2009, 1:21pm
11
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);
jules
November 4, 2009, 1:28pm
12
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
valley
November 7, 2009, 2:09am
15
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.
jules
November 8, 2009, 6:51pm
16
[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
jules
November 9, 2009, 12:32pm
18
A listener would be able to provide both.