Andreas Mülder 14 лет назад
Родитель
Сommit
88fe855e28

+ 3 - 11
de.itemis.xtext.utils/plugins/de.itemis.xtext.utils.jface/src/de/itemis/xtext/utils/jface/viewers/StyledTextXtextAdapter.java

@@ -91,7 +91,7 @@ public class StyledTextXtextAdapter {
 		// create fake resource and containing resource set
 		createFakeResourceContext(injector);
 	}
-	
+
 	public StyledTextXtextAdapter(Injector injector) {
 		this(injector, IXtextFakeContextResourcesProvider.NULL_CONTEXT_PROVIDER);
 	}
@@ -163,7 +163,8 @@ public class StyledTextXtextAdapter {
 	}
 
 	protected void createXtextSourceViewer() {
-		sourceviewer = new XtextSourceViewerEx(styledText);
+		sourceviewer = new XtextSourceViewerEx(styledText,
+				preferenceStoreAccess.getPreferenceStore());
 		sourceviewer.configure(configuration);
 		sourceviewer.setDocument(document, new AnnotationModel());
 		SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(
@@ -172,15 +173,6 @@ public class StyledTextXtextAdapter {
 		configureSourceViewerDecorationSupport(support);
 	}
 
-	protected void initXtextSourceViewer() {
-		sourceviewer.configure(configuration);
-		sourceviewer.setDocument(document, new AnnotationModel());
-		SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(
-				sourceviewer, null, new DefaultMarkerAnnotationAccess(),
-				getSharedColors());
-		configureSourceViewerDecorationSupport(support);
-	}
-	
 	protected ISharedTextColors getSharedColors() {
 		return EditorsPlugin.getDefault().getSharedTextColors();
 	}

+ 23 - 2
de.itemis.xtext.utils/plugins/de.itemis.xtext.utils.jface/src/de/itemis/xtext/utils/jface/viewers/XtextSourceViewerEx.java

@@ -2,15 +2,17 @@ package de.itemis.xtext.utils.jface.viewers;
 
 import java.lang.reflect.Field;
 
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.projection.ProjectionDocument;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
 import org.eclipse.jface.text.source.projection.ProjectionViewer;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
 import org.eclipse.xtext.ui.editor.XtextSourceViewer;
 
-
 /**
  * Source viewer replacement that implements a workaround for Eclipse bug
  * #352847 to enable that offsets are respected.
@@ -21,13 +23,16 @@ import org.eclipse.xtext.ui.editor.XtextSourceViewer;
 class XtextSourceViewerEx extends XtextSourceViewer {
 
 	private final StyledText styledText;
+	private final IPreferenceStore preferenceStore;
 
-	public XtextSourceViewerEx(StyledText styledText) {
+	public XtextSourceViewerEx(StyledText styledText,
+			IPreferenceStore preferenceStore) {
 		// super constructor will create a new text widget by calling
 		// createControl(). As we want to use the passed in styled text, we have
 		// to disable this mechanism.
 		super(null, null, null, false, styledText.getStyle());
 		this.styledText = styledText;
+		this.preferenceStore = preferenceStore;
 		super.createControl(styledText.getParent(), styledText.getStyle());
 	}
 
@@ -75,6 +80,22 @@ class XtextSourceViewerEx extends XtextSourceViewer {
 		return false;
 	}
 
+	@Override
+	public void configure(SourceViewerConfiguration configuration) {
+		// We have to set the preference store via reflection here because Xtext
+		// uses package visibility for the setter
+		Field declaredField;
+		try {
+			declaredField = TextSourceViewerConfiguration.class
+					.getDeclaredField("fPreferenceStore");
+			declaredField.setAccessible(true);
+			declaredField.set(configuration, preferenceStore);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		super.configure(configuration);
+	}
+
 	/**
 	 * Set the private fHandleProjectionChanges field value.
 	 *