开发者

Syntax Coloring without Presentation Reconciler

开发者 https://www.devze.com 2023-01-12 16:46 出处:网络
I would like to do coloring in Eclipse without using the presentation reconciler.Therefore, first, I need to figure out how to associ开发者_开发百科ate a TextPresentation object with either my editor

I would like to do coloring in Eclipse without using the presentation reconciler. Therefore, first, I need to figure out how to associ开发者_开发百科ate a TextPresentation object with either my editor or document, but I am having difficulty finding out how to link it either of those. Normally, the CreatePresentation in the IPResentationReconciler interface would give the style range to the textpresentation, and from there Eclipse would know what to do with that presentation object. Is there some way to use a TextPresentation object without the use of PresentationReconciler? It would be nice if I could do coloring without the use of reconciler. Thank you.


I finally figured out how to achieve the coloring without the use of Reconcilers. I discovered that first I needed a way to obtain a reference to my SourceViewer object, as I am extending TextEditor. I also discovered that I could implement the TextListener interface and add my own listener to the SourceViewer object. One must be careful, however, as calling the getSourceViewer() method can result in null if not called at the appropriate spot. Originally, I overwrote the init(...) function in my editor class and made the getSourceViewer() call, but it still resulted in null. After doing a bit of research, I discovered that I could properly obtain a reference to the SourceViewer object by overriding the createPartControl method. I first call super.createPartControl(...) and then make a call to getSourceViewer(). After I obtained that reference, I used that with my listener class I created and was able to do the coloring myself with the setTextColor method the SourceViewer object has. Hope this helps others in the same situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消