1 package org.simantics.scl.ui.editor;
3 import org.eclipse.jface.preference.IPreferenceStore;
4 import org.eclipse.jface.resource.ResourceManager;
5 import org.eclipse.jface.text.DefaultInformationControl;
6 import org.eclipse.jface.text.DefaultTextHover;
7 import org.eclipse.jface.text.IDocument;
8 import org.eclipse.jface.text.IInformationControl;
9 import org.eclipse.jface.text.IInformationControlCreator;
10 import org.eclipse.jface.text.ITextHover;
11 import org.eclipse.jface.text.contentassist.ContentAssistant;
12 import org.eclipse.jface.text.contentassist.IContentAssistant;
13 import org.eclipse.jface.text.presentation.IPresentationReconciler;
14 import org.eclipse.jface.text.source.DefaultAnnotationHover;
15 import org.eclipse.jface.text.source.IAnnotationHover;
16 import org.eclipse.jface.text.source.ISourceViewer;
17 import org.eclipse.jface.text.source.SourceViewerConfiguration;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.editors.text.EditorsUI;
20 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
21 import org.simantics.scl.ui.Activator;
22 import org.simantics.scl.ui.editor.completion.SCLCompletionAssistProcessor;
23 import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment;
24 import org.simantics.scl.ui.editor2.SCLPresentationReconciler;
26 public class SCLSourceViewerConfigurationNew extends SourceViewerConfiguration {
28 public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };
30 ResourceManager resourceManager;
31 IPreferenceStore preferenceStore;
33 private SCLTextEditorEnvironment sclTextEditorEnvironment;
35 public SCLSourceViewerConfigurationNew(ResourceManager resourceManager) {
36 this.resourceManager = resourceManager;
37 this.preferenceStore = EditorsUI.getPreferenceStore();
39 this.sclTextEditorEnvironment = new SCLTextEditorEnvironment("");
42 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
44 IDocument.DEFAULT_CONTENT_TYPE
49 public int getTabWidth(ISourceViewer sourceViewer) {
50 if (preferenceStore == null)
51 return super.getTabWidth(sourceViewer);
52 return preferenceStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
56 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
57 String[] indentPrefixes = getIndentPrefixesForTab(getTabWidth(sourceViewer));
58 if (indentPrefixes == null)
61 int length = indentPrefixes.length;
63 // Swap first with second last
64 String first = indentPrefixes[0];
65 indentPrefixes[0] = indentPrefixes[length - 2];
66 indentPrefixes[length - 2] = first;
69 return indentPrefixes;
72 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
73 return new SCLPresentationReconciler(resourceManager);
77 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
78 //return new SCLEditorTextHover(sourceViewer, sclTextEditorEnvironment);
79 return new DefaultTextHover(sourceViewer);
83 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
84 return new DefaultAnnotationHover();
88 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
89 ContentAssistant assistant = new ContentAssistant();
90 assistant.enableColoredLabels(true);
91 assistant.setStatusLineVisible(true);
93 assistant.enableAutoActivation(true);
94 assistant.enableAutoInsert(true);
95 assistant.setContentAssistProcessor(new SCLCompletionAssistProcessor(sclTextEditorEnvironment), IDocument.DEFAULT_CONTENT_TYPE);
96 assistant.setInformationControlCreator(CREATOR);
97 assistant.setRestoreCompletionProposalSize(Activator.getInstance().getDialogSettings());
101 private static final IInformationControlCreator CREATOR = new IInformationControlCreator() {
104 public IInformationControl createInformationControl(Shell parent) {
105 return new DefaultInformationControl(parent);
109 public void updateCompletionAssistModuleName(String moduleName) {
110 sclTextEditorEnvironment.updateModuleName(moduleName);
114 // public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
115 // return new ContentFormatter();
118 public SCLTextEditorEnvironment getSclTextEditorEnvironment() {
119 return sclTextEditorEnvironment;