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