]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/SCLSourceViewerConfigurationNew.java
Merge "Ensure GetElementClassRequest is not constructed without elementFactory"
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor / SCLSourceViewerConfigurationNew.java
1 package org.simantics.scl.ui.editor;\r
2 \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
25 \r
26 public class SCLSourceViewerConfigurationNew extends SourceViewerConfiguration {\r
27 \r
28     public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };\r
29     \r
30     ResourceManager resourceManager;\r
31     IPreferenceStore preferenceStore;\r
32     \r
33     private SCLTextEditorEnvironment sclTextEditorEnvironment;\r
34     \r
35     public SCLSourceViewerConfigurationNew(ResourceManager resourceManager) {\r
36         this.resourceManager = resourceManager;\r
37         this.preferenceStore = EditorsUI.getPreferenceStore();\r
38         \r
39         this.sclTextEditorEnvironment = new SCLTextEditorEnvironment("");\r
40     }\r
41 \r
42     public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
43         return new String[] {\r
44             IDocument.DEFAULT_CONTENT_TYPE\r
45         };\r
46     }\r
47     \r
48         @Override\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
53         }\r
54 \r
55         @Override\r
56         public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {\r
57                 String[] indentPrefixes = getIndentPrefixesForTab(getTabWidth(sourceViewer));\r
58                 if (indentPrefixes == null)\r
59                         return null;\r
60 \r
61                 int length = indentPrefixes.length;\r
62                 if (length > 2) {\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
67                 }\r
68 \r
69                 return indentPrefixes;\r
70         }\r
71     \r
72     public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
73         return new SCLPresentationReconciler(resourceManager);\r
74     }\r
75     \r
76     @Override\r
77     public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {\r
78         //return new SCLEditorTextHover(sourceViewer, sclTextEditorEnvironment);\r
79         return new DefaultTextHover(sourceViewer);\r
80     }\r
81     \r
82     @Override\r
83     public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {\r
84         return new DefaultAnnotationHover();\r
85     }\r
86     \r
87     @Override\r
88     public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {\r
89         ContentAssistant assistant = new ContentAssistant();\r
90         assistant.enableColoredLabels(true);\r
91         assistant.setStatusLineVisible(true);\r
92 \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
98         return assistant;\r
99     }\r
100     \r
101     private static final IInformationControlCreator CREATOR = new IInformationControlCreator() {\r
102         \r
103         @Override\r
104         public IInformationControl createInformationControl(Shell parent) {\r
105             return new DefaultInformationControl(parent);\r
106         }\r
107     };\r
108     \r
109     public void updateCompletionAssistModuleName(String moduleName) {\r
110         sclTextEditorEnvironment.updateModuleName(moduleName);\r
111     }\r
112     \r
113 //    @Override\r
114 //    public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {\r
115 //        return new ContentFormatter();\r
116 //    }\r
117     \r
118     public SCLTextEditorEnvironment getSclTextEditorEnvironment() {\r
119         return sclTextEditorEnvironment;\r
120     }\r
121 }\r