Syntax coloring without preview

I would like to do coloring in Eclipse without using a presentation conciliator. Therefore, firstly, I need to figure out how to associate a TextPresentation object with my editor or document, but I find it difficult to understand how to associate it with either this. Typically, CreatePresentation in the IPResentationReconciler interface will provide a range of styles in textpresentation, and from there Eclipse will know what to do with this presentation object. Can I use a TextPresentation without using PresentationReconciler? It would be nice if I could do the coloring without using a conciliator. Thanks.

+4
source share
1 answer

I finally figured out how to achieve coloring without using Reconcilers. I found that first I needed a way to get a reference to my SourceViewer object, as I am extending TextEditor. I also found that I could implement the TextListener interface and add my own listener to the SourceViewer object. However, you need to be careful, since calling the getSourceViewer () method can lead to null if not called in the appropriate place. I originally overwrote the init (...) function in my editor class and called the getSourceViewer () call, but it still led to null. After doing a bit of research, I found that I could correctly get a reference to the SourceViewer object by overriding the createPartControl method. First I call super.createPartControl (...) and then I call getSourceViewer (). After I got this link, I used it with my listener class, which I created, and was able to paint myself using the setTextColor method, which has a SourceViewer object. Hope this helps others in the same situation.

+5
source

All Articles