package com.gwtplugins.gwt.eclipse.gss.model; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.formatter.IContentFormatter; import org.eclipse.jface.text.formatter.MultiPassContentFormatter; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.wst.css.core.text.ICSSPartitions; import org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS; import org.eclipse.wst.sse.core.text.IStructuredPartitions; import com.gwtplugins.gwt.eclipse.gss.ExtractingGssFormattingStrategy; /** * Source viewer configuration for CssResource CSS files. */ public class GssResourceSourceViewerConfiguration extends StructuredTextViewerConfigurationCSS { /* * Derived from StructuredTextViewerConfigurationCSS. We fix their corrupting formatting when the CSS is not * well-formed. This bug exists without any extra CssResource extensions, e.g. with "@media { b { } }". */ @Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { IContentFormatter formatter = super.getContentFormatter(sourceViewer); // super was unable to create a formatter, probably because // sourceViewer does not have document set yet, so just create a // generic one if (!(formatter instanceof MultiPassContentFormatter)) { formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), ICSSPartitions.STYLE); } ((MultiPassContentFormatter) formatter).setMasterStrategy(new ExtractingGssFormattingStrategy()); return formatter; } /* * Derived from StructuredTextViewerConfigurationCSS. We fix their improper indentation in the code generated by their * proposals. This bug exists without any extra CssResource extensions, e.g. with "@media { b<ctrl-space> }". */ @Override protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) { IContentAssistProcessor[] processors = super.getContentAssistProcessors(sourceViewer, partitionType); if ((partitionType == ICSSPartitions.STYLE) || (partitionType == IStructuredPartitions.UNKNOWN_PARTITION)) { processors = new IContentAssistProcessor[] { new IndentationFixingGssContentAssistProcessor() }; } return processors; } }