Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Syntax Highlighting

Hi Harish,
 
In my last reply, I said it will give bold. But it is that. Pls follow the code below

protected IRule[] createRules()
 {
  ArrayList<IRule> rules = new ArrayList<IRule>();
  
  IToken keywordToken = new Token(new TextAttribute(

                                                   manager.getColor   (ColorConstants.KEYWORD),null,SWT.BOLD));
  IToken defaultToken = new Token(new TextAttribute(manager.getColor (ColorConstants.DEFAULT)));
  
  IWordDetector wordDetector = new IWordDetector(){
   public boolean isWordStart(char c)
   {
    return Character.isJavaIdentifierStart(c);   
   }

   public boolean isWordPart(char c)
   {
    return Character.isJavaIdentifierPart(c);   
   }};

  IWordDetector includeDetector = new IWordDetector(){
   public boolean isWordStart(char c)
   {
    return c=='#';   
   }

   public boolean isWordPart(char c)
   {
    return Character.isLetterOrDigit(c);   
   }};
   
  rules.add(new WhitespaceRule(new WhitespaceDetector()));  
  rules.add(new SymIncludeDirRule(includeDetector, Token.UNDEFINED,keywordToken,false,'\"','\"'));

  WordRule wordRule = new WordRule(wordDetector,defaultToken);
  
   addWords(wordRule,words.getKeywords(),keywordToken);  //get words gives string array of keywords
  rules.add(wordRule);
  
  
  IRule[] rule = new IRule[ rules.size()];
  return (IRule[])rules.toArray(rule);

}
 
 
Regards..
Shiva Shankar.B
 
On 2/28/06, Harish Dewan <harishd@xxxxxxxxxxxxxxx> wrote:

Hi All,

I have to do syntax highlighting for few keywords in my C Editor

The existing functionality of C Editor should be there along with my key words highlighting.

 

For starting:

 I have created a new editor using 'org.eclipse.ui.editors' extension point

In my class file I have extended from 'CEditor' and in this class, function 'initializeEditor'

 

protected void initializeEditor() {

super.initializeEditor();

            setSourceViewerConfiguration(new MySourceViewerConfig(CUIPlugin.getDefault().getTextTools(),this));

}          

 

In class MySourceViewerConfig I have extended from 'CSourceViewerConfiguration'

 

public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {

                        IPresentationReconciler reconciler = super.getPresentationReconciler(sourceViewer);

                        DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTagScanner());

                        ((PresentationReconciler) reconciler).setDamager(dr, "my_highlight");

                        ((PresentationReconciler) reconciler).setRepairer(dr, "my_highlight");

                       

                        return reconciler;

}

 

 

In my tag scanner 'getTagScanner()' I have created my new Rule scanner

And added few  SingleLineRule for my IToken

 

Problem is that  now my CEditor's syntax highlighting is working but it is not showing my keyword's Highlighting .

 

What else do I need to add? Where am I going wrong?

 

 

Thanks in advance

 

 

 

 

Best Regards,

Harish Dewan

System Executive , Advanced Technology Solutions - Semiconductor Solutions Group | KPIT Cummins Infosystems Ltd. | +91 020 2538 2358 x 421 | harishd@xxxxxxxxxxxxxxx | www.kpitcummins.com

 


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev





--
Thanks & Regards
Shiva Shankar.B
Phone : 09945133039

Back to the top