/*
 * Created on 2004-11-08
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.ui.mmpedit;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.graphics.RGB;

/**
 * @author mikolaj
 *
 * Configures text editor features like syntax highlighting
 */
public class MMPSourceViewerConfiguration extends SourceViewerConfiguration {

    public final static RGB fCommentColor=new RGB( 63, 127, 95);
    public final static RGB fPreprocColor=new RGB(  0, 191,  0);
    
    public MMPSourceViewerConfiguration(ColorManager manager) {
        super();
        fColorManager=manager;
    }
    
	public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
		return new String[] {
			IDocument.DEFAULT_CONTENT_TYPE/*,
			MMPPartitionScanner.PARTITION_COMMENT*/ };
	}
	
    /* (non-Javadoc)
     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAnnotationHover(org.eclipse.jface.text.source.ISourceViewer)
     */
    public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
        return new MMPAnnotationHover();
    }
    
	ITokenScanner getCommandsScanner()
	{
	    RuleBasedScanner scanner=new RuleBasedScanner();
		IRule[] rules = new IRule[2];
		//Add rule for processing instructions
		rules[0]=new EndOfLineRule("//", new Token(new TextAttribute(
				fColorManager.getColor(fCommentColor))));
		
		EndOfLineRule preprocRule=new EndOfLineRule("#", new Token(new TextAttribute(
				fColorManager.getColor(fPreprocColor))));
		preprocRule.setColumnConstraint(0);
		rules[1]=preprocRule;
		
		scanner.setRules(rules);
		return scanner;
	}
	
	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
		PresentationReconciler reconciler = new PresentationReconciler();

		DefaultDamagerRepairer dr =
			new DefaultDamagerRepairer(getCommandsScanner());
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		
		return reconciler;
	}	
    
    ColorManager fColorManager;

}
