Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Colouring In A Custom Editor
Colouring In A Custom Editor [message #444729] Mon, 20 February 2006 08:26 Go to next message
Dave Hewitson is currently offline Dave HewitsonFriend
Messages: 56
Registered: July 2009
Member
Hi, I'm trying to create a custom source editor for my users and have
nearly completed it with keyword colouring etc, but I'm struggling to
fulfill one requirement.

This source is for a bespoke language, and contains a list of variables at
the end after a line that looks like this [Local Variables].

As this can be edited and not a fixed list like the keywords, I have tried
to work out a way to do this but can't find any examples. Can anyone point
me in the right direction?

Thanks for any help.

Dave.
Re: Colouring In A Custom Editor [message #444735 is a reply to message #444729] Mon, 20 February 2006 10:25 Go to previous messageGo to next message
Armen Polischuk is currently offline Armen PolischukFriend
Messages: 7
Registered: July 2009
Junior Member
On Mon, 20 Feb 2006 10:26:43 +0200, Dave H <david.hewitson@cdl.co.uk> =

wrote:

> Hi, I'm trying to create a custom source editor for my users and have =
=

> nearly completed it with keyword colouring etc, but I'm struggling to =
=

> fulfill one requirement.
>
> This source is for a bespoke language, and contains a list of variable=
s =

> at the end after a line that looks like this [Local Variables].
>
> As this can be edited and not a fixed list like the keywords, I have =

> tried to work out a way to do this but can't find any examples. Can =

> anyone point me in the right direction?
>
> Thanks for any help.
>
> Dave.
>
>
>

I don't know which widget you use, but I use SourceViewer from jdt.
In such case you just should install object , implemented =

SourceViewerConfiguration class:

editor =3D new SourceViewer(parent, null, SWT.V_SCROLL | SWT.WRAP);
configuration =3D new MessageEditorConfiguration(editor);
editor.configure(configuration);

And you should overrride method
public IPresentationReconciler getPresentationReconciler(ISourceViewer =

sourceViewer)
from SourceViewerConfiguration
I have same task - colouring some words. For this, you could use :
DefaultDamagerRepairer repairer =3D new DefaultDamagerRepairer(<your =

scanner>);
PresentationReconciler reconciler =3D new PresentationReconcile=
r();
reconciler.setDocumentPartitioning(<your partition>);
reconciler.setDamager(repairer, IDocument.DEFAULT_CONTENT_TYPE)=
;
reconciler.setRepairer(repairer, IDocument.DEFAULT_CONTENT_TYPE=
);
return reconciler;

Next step - writing scanner which will be scann text and seek your =

predefined words. You could write your own scanner or
extend RuleBasedScanner;
Simply override constructor: create token( set color, font), and create =
=

rules for each word like this:
List<IRule> rules =3D new LinkedList<IRule>();
final WordRule wordRule =3D new WordRule(<detector>);
for (int i =3D 0; i < <your words>.length; i++) {
wordRule.addWord(<your words>[i], token);
}
rules.add(wordRule);
setRules(rules.toArray(new IRule[0]));
where <your words> - array your predefined words, which you could read =

from prefs or file
<detector> - class which implements interface IWordDetector. Exactly =

there you should define when your word starts and finishes.
-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: Colouring In A Custom Editor [message #444743 is a reply to message #444735] Mon, 20 February 2006 12:45 Go to previous messageGo to next message
Dave Hewitson is currently offline Dave HewitsonFriend
Messages: 56
Registered: July 2009
Member
Hi Armen,

I have already done something very similar to this to colour my keywords.

The problem I have is that there are some other "keywords" (in fact they
are variables) at the bottom of the file that the user may change on the
fly - the list is not static.

It's very similar to the way class attributes are coloured in the JDT,
maybe I should check out how they do it there, though I expect that would
be a bit tricky to decipher !

Dave.
Re: Colouring In A Custom Editor [message #444747 is a reply to message #444729] Mon, 20 February 2006 13:40 Go to previous messageGo to next message
Tom Hofmann is currently offline Tom HofmannFriend
Messages: 770
Registered: July 2009
Senior Member
Hi Dave,

see also this other discussion on eclipse.platform:

news://news.eclipse.org:119/dtbs0s$uua$1@utils.eclipse.org

-tom

Dave H wrote:
> Hi, I'm trying to create a custom source editor for my users and have
> nearly completed it with keyword colouring etc, but I'm struggling to
> fulfill one requirement.
>
> This source is for a bespoke language, and contains a list of variables
> at the end after a line that looks like this [Local Variables].
>
> As this can be edited and not a fixed list like the keywords, I have
> tried to work out a way to do this but can't find any examples. Can
> anyone point me in the right direction?
Re: Colouring In A Custom Editor [message #444748 is a reply to message #444743] Mon, 20 February 2006 13:43 Go to previous message
Armen Polischuk is currently offline Armen PolischukFriend
Messages: 7
Registered: July 2009
Junior Member
On Mon, 20 Feb 2006 14:45:42 +0200, Dave H <david.hewitson@cdl.co.uk>
wrote:
Ok. I see. In your document in some place are defined some vars, which
will be colored in others parts of the document.
So you should add single line rule in the scanner. Something like this:
rules.add(SingleLineRule("var ",";", token));
where var - specific word used to declare vars in your language.
So every time when user add text:
var i;
it will be colored.

How to color 'i' like var in the document I've already told.
Previous Topic:[RCP Export] ClassNotFoundException - Solution
Next Topic:non-moveable view
Goto Forum:
  


Current Time: Fri Apr 19 20:42:34 GMT 2024

Powered by FUDForum. Page generated in 0.03380 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top