Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2005-07-10 19:43:05 -0400
committerAlain Magloire2005-07-10 19:43:05 -0400
commit1a6f8649961bc4c5506afb12408942aea946248a (patch)
treed4466cf034d9a3d4ae7952c86436b96baa6ec80e
parent8112953dc94410c33d35a3b84de97b642e8ab2e7 (diff)
downloadorg.eclipse.cdt-1a6f8649961bc4c5506afb12408942aea946248a.tar.gz
org.eclipse.cdt-1a6f8649961bc4c5506afb12408942aea946248a.tar.xz
org.eclipse.cdt-1a6f8649961bc4c5506afb12408942aea946248a.zip
2005-07-09 Alain Magloire
Fix PR 97963 * src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferncePage.java + src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java269
3 files changed, 278 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 381f9be753..bf5eb31873 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,4 +1,9 @@
2005-07-09 Alain Magloire
+ Fix PR 97963
+ * src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferncePage.java
+ + src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java
+
+2005-07-09 Alain Magloire
Fix PR 90419
* src/org/eclipse/cdt/internal/coreext/util/CodeFormatterUtil.java
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
index 36af4918da..6cbb88df56 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
@@ -275,7 +275,10 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
fCTextTools = CUIPlugin.getDefault().getTextTools();
CSourceViewerConfiguration configuration = new CSourceViewerConfiguration(fCTextTools, null);
- fPreviewViewer = new SourceViewer(parent, null, SWT.V_SCROLL | SWT.H_SCROLL);
+ //fPreviewViewer = new SourceViewer(parent, null, SWT.V_SCROLL | SWT.H_SCROLL);
+ PreviewSourceViewer asv = new PreviewSourceViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL);
+ asv.setPreferenceStore(CUIPlugin.getDefault().getCombinedPreferenceStore());
+ fPreviewViewer = asv;
fPreviewViewer.configure(configuration);
fPreviewViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
fPreviewViewer.setEditable(false);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java
new file mode 100644
index 0000000000..2aef0750dd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreviewSourceViewer.java
@@ -0,0 +1,269 @@
+/*******************************************************************************
+ * Copyright (c) 2005 QnX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Qnx Software Systems - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.ui.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+class PreviewSourceViewer extends SourceViewer implements IPropertyChangeListener {
+
+ /**
+ * This viewer's foreground color.
+ *
+ * @since 3.0
+ */
+ private Color fForegroundColor;
+
+ /**
+ * The viewer's background color.
+ *
+ * @since 3.0
+ */
+ private Color fBackgroundColor;
+
+ /**
+ * This viewer's selection foreground color.
+ *
+ * @since 3.0
+ */
+ private Color fSelectionForegroundColor;
+
+ /**
+ * The viewer's selection background color.
+ *
+ * @since 3.0
+ */
+ private Color fSelectionBackgroundColor;
+
+ /**
+ * The preference store.
+ *
+ * @since 3.0
+ */
+ private IPreferenceStore fPreferenceStore;
+
+ /**
+ * Is this source viewer configured?
+ *
+ * @since 3.0
+ */
+ private boolean fIsConfigured;
+
+ public PreviewSourceViewer(Composite parent, int styles) {
+ super(parent, null, styles);
+ }
+
+ protected void initializeViewerColors() {
+ if (fPreferenceStore != null) {
+
+ StyledText styledText = getTextWidget();
+
+ // ----------- foreground color --------------------
+ Color color = fPreferenceStore
+ .getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null
+ : createColor(fPreferenceStore,
+ AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND,
+ styledText.getDisplay());
+ styledText.setForeground(color);
+
+ if (fForegroundColor != null)
+ fForegroundColor.dispose();
+
+ fForegroundColor = color;
+
+ // ---------- background color ----------------------
+ color = fPreferenceStore
+ .getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
+ : createColor(fPreferenceStore,
+ AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND,
+ styledText.getDisplay());
+ styledText.setBackground(color);
+
+ if (fBackgroundColor != null)
+ fBackgroundColor.dispose();
+
+ fBackgroundColor = color;
+
+ // ----------- selection foreground color --------------------
+ color = fPreferenceStore
+ .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR) ? null
+ : createColor(
+ fPreferenceStore,
+ AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR,
+ styledText.getDisplay());
+ styledText.setSelectionForeground(color);
+
+ if (fSelectionForegroundColor != null)
+ fSelectionForegroundColor.dispose();
+
+ fSelectionForegroundColor = color;
+
+ // ---------- selection background color ----------------------
+ color = fPreferenceStore
+ .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR) ? null
+ : createColor(
+ fPreferenceStore,
+ AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR,
+ styledText.getDisplay());
+ styledText.setSelectionBackground(color);
+
+ if (fSelectionBackgroundColor != null)
+ fSelectionBackgroundColor.dispose();
+
+ fSelectionBackgroundColor = color;
+ }
+ }
+
+ /*
+ * @see ISourceViewer#configure(SourceViewerConfiguration)
+ */
+ public void configure(SourceViewerConfiguration configuration) {
+
+ /*
+ * Prevent access to colors disposed in unconfigure(), see:
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
+ */
+ StyledText textWidget = getTextWidget();
+ if (textWidget != null && !textWidget.isDisposed()) {
+ Color foregroundColor = textWidget.getForeground();
+ if (foregroundColor != null && foregroundColor.isDisposed())
+ textWidget.setForeground(null);
+ Color backgroundColor = textWidget.getBackground();
+ if (backgroundColor != null && backgroundColor.isDisposed())
+ textWidget.setBackground(null);
+ }
+
+ super.configure(configuration);
+
+ if (fPreferenceStore != null) {
+ fPreferenceStore.addPropertyChangeListener(this);
+ initializeViewerColors();
+ }
+
+ fIsConfigured = true;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
+ * @since 3.0
+ */
+ public void unconfigure() {
+ if (fForegroundColor != null) {
+ fForegroundColor.dispose();
+ fForegroundColor = null;
+ }
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor = null;
+ }
+
+ if (fPreferenceStore != null) {
+ fPreferenceStore.removePropertyChangeListener(this);
+ }
+
+ super.unconfigure();
+
+ fIsConfigured = false;
+ }
+
+ /**
+ * Creates a color from the information stored in the given preference
+ * store. Returns <code>null</code> if there is no such information
+ * available.
+ *
+ * @param store
+ * the store to read from
+ * @param key
+ * the key used for the lookup in the preference store
+ * @param display
+ * the display used create the color
+ * @return the created color according to the specification in the
+ * preference store
+ * @since 3.0
+ */
+ private Color createColor(IPreferenceStore store, String key,
+ Display display) {
+
+ RGB rgb = null;
+
+ if (store.contains(key)) {
+
+ if (store.isDefault(key))
+ rgb = PreferenceConverter.getDefaultColor(store, key);
+ else
+ rgb = PreferenceConverter.getColor(store, key);
+
+ if (rgb != null)
+ return new Color(display, rgb);
+ }
+
+ return null;
+ }
+
+ /**
+ * Sets the preference store on this viewer.
+ *
+ * @param store
+ * the preference store
+ *
+ * @since 3.0
+ */
+ public void setPreferenceStore(IPreferenceStore store) {
+ if (fIsConfigured && fPreferenceStore != null) {
+ fPreferenceStore.removePropertyChangeListener(this);
+ }
+
+ fPreferenceStore = store;
+
+ if (fIsConfigured && fPreferenceStore != null) {
+ fPreferenceStore.addPropertyChangeListener(this);
+ initializeViewerColors();
+ }
+ }
+
+ /*
+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property)
+ || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT
+ .equals(property)
+ || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND
+ .equals(property)
+ || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT
+ .equals(property)
+ || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR
+ .equals(property)
+ || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR
+ .equals(property)
+ || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR
+ .equals(property)
+ || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR
+ .equals(property)) {
+ initializeViewerColors();
+ }
+ }
+
+} \ No newline at end of file

Back to the top