1 package org.simantics.scl.ui.editor;
3 import org.eclipse.jface.text.DefaultTextHover;
4 import org.eclipse.jface.text.IDocument;
5 import org.eclipse.jface.text.ITextHover;
6 import org.eclipse.jface.text.TextAttribute;
7 import org.eclipse.jface.text.presentation.IPresentationReconciler;
8 import org.eclipse.jface.text.presentation.PresentationReconciler;
9 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
10 import org.eclipse.jface.text.rules.IRule;
11 import org.eclipse.jface.text.rules.ITokenScanner;
12 import org.eclipse.jface.text.rules.IWordDetector;
13 import org.eclipse.jface.text.rules.MultiLineRule;
14 import org.eclipse.jface.text.rules.PatternRule;
15 import org.eclipse.jface.text.rules.RuleBasedScanner;
16 import org.eclipse.jface.text.rules.Token;
17 import org.eclipse.jface.text.rules.WordRule;
18 import org.eclipse.jface.text.source.DefaultAnnotationHover;
19 import org.eclipse.jface.text.source.IAnnotationHover;
20 import org.eclipse.jface.text.source.ISharedTextColors;
21 import org.eclipse.jface.text.source.ISourceViewer;
22 import org.eclipse.jface.text.source.SourceViewerConfiguration;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.graphics.Device;
25 import org.eclipse.swt.graphics.Font;
26 import org.eclipse.swt.graphics.RGB;
28 public class SCLSourceViewerConfiguration extends SourceViewerConfiguration {
30 public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };
33 ISharedTextColors sharedTextColors;
35 public SCLSourceViewerConfiguration(Device device,
36 ISharedTextColors sharedTextColors) {
38 this.sharedTextColors = sharedTextColors;
41 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
43 IDocument.DEFAULT_CONTENT_TYPE
47 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
48 PresentationReconciler reconciler = new PresentationReconciler();
50 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());
52 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
53 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
58 ITokenScanner getSclTokenScanner() {
59 RuleBasedScanner scanner = new RuleBasedScanner();
61 Font font = new Font(device, "Courier New", 10, SWT.NORMAL);
62 Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD);
64 Token defaultToken = new Token(
66 sharedTextColors.getColor(new RGB(0, 0, 0)),
71 Token string = new Token(new TextAttribute(
72 sharedTextColors.getColor(new RGB(42, 0, 255)),
77 Token reserved = new Token(
79 sharedTextColors.getColor(new RGB(127, 0, 85)),
84 Token comment = new Token(new TextAttribute(
85 sharedTextColors.getColor(new RGB(63, 127, 95)),
91 WordRule reservedWord = new WordRule(new IWordDetector() {
93 public boolean isWordStart(char c) {
94 return Character.isJavaIdentifierStart(c);
98 public boolean isWordPart(char c) {
99 return Character.isJavaIdentifierPart(c) || c=='.';
103 reservedWord.addWord("if", reserved);
104 reservedWord.addWord("then", reserved);
105 reservedWord.addWord("else", reserved);
106 reservedWord.addWord("match", reserved);
107 reservedWord.addWord("with", reserved);
108 reservedWord.addWord("data", reserved);
109 reservedWord.addWord("type", reserved);
110 reservedWord.addWord("class", reserved);
112 IRule[] rules = new IRule[] {
113 //new MultiLineRule("\"\"\"", "\"\"\"", string),
114 new PatternRule("\"", "\"", string, '\\', true),
115 new MultiLineRule("/*", "*/", comment),
116 new PatternRule("//", null, comment, '\0', true),
119 scanner.setRules(rules);
120 scanner.setDefaultReturnToken(defaultToken);
126 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
127 return new DefaultTextHover(sourceViewer);
131 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
132 return new DefaultAnnotationHover();