From ad88076d703440f909c8d91e8e8822fe9327b0d6 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Tue, 10 Oct 2006 09:05:06 +0000 Subject: [PATCH] Cleanup handling of editor preference changes --- .../cdt/internal/ui/compare/CMergeViewer.java | 57 +++++----- .../cdt/internal/ui/editor/CEditor.java | 106 +++++++++++------- .../cdt/internal/ui/editor/CSourceViewer.java | 50 +++++++++ .../SimpleCSourceViewerConfiguration.java | 28 ++--- .../hover/SourceViewerInformationControl.java | 62 ++++++++-- 5 files changed, 214 insertions(+), 89 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java index 680a85f3b1b..0ab775b007e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java @@ -8,17 +8,16 @@ * Contributors: * IBM Corporation - initial API and implementation * QNX Software System + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.compare; -import org.eclipse.cdt.internal.ui.text.*; -import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.contentmergeviewer.TextMergeViewer; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.text.*; -import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.TextViewer; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; @@ -27,6 +26,12 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.texteditor.AbstractTextEditor; +import org.eclipse.cdt.ui.CUIPlugin; + +import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; +import org.eclipse.cdt.internal.ui.text.CTextTools; +import org.eclipse.cdt.internal.ui.text.ICColorConstants; + public class CMergeViewer extends TextMergeViewer { private static final String TITLE= "CMergeViewer.title"; //$NON-NLS-1$ @@ -38,26 +43,32 @@ public class CMergeViewer extends TextMergeViewer { public CMergeViewer(Composite parent, int styles, CompareConfiguration mp) { super(parent, styles, mp); - fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore(); - if (fPreferenceStore != null) { - fPreferenceChangeListener= new IPropertyChangeListener() { + + IPreferenceStore store = getPreferenceStore(); + + fUseSystemColors= store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT); + if (! fUseSystemColors) { + RGB bg= createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); + setBackgroundColor(bg); + RGB fg= createColor(store, ICColorConstants.C_DEFAULT); + setForegroundColor(fg); + } + + } + + private IPreferenceStore getPreferenceStore() { + if (fPreferenceStore == null) { + fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore(); + fPreferenceChangeListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { handlePropertyChange(event); } }; fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener); } - - fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT); - if (! fUseSystemColors) { - RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); - setBackgroundColor(bg); - RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT); - setForegroundColor(fg); - } - + return fPreferenceStore; } - + protected void handleDispose(DisposeEvent event) { if (fPreferenceChangeListener != null) { fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener); @@ -97,8 +108,8 @@ public class CMergeViewer extends TextMergeViewer { } } - if (getSourceViewerConfiguration().affectsBehavior(event)) { - getSourceViewerConfiguration().adaptToPreferenceChange(event); + if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) { + getSourceViewerConfiguration().handlePropertyChangeEvent(event); invalidateTextPresentation(); } } @@ -118,12 +129,8 @@ public class CMergeViewer extends TextMergeViewer { private CSourceViewerConfiguration getSourceViewerConfiguration() { if (fSourceViewerConfiguration == null) { CTextTools tools= CUIPlugin.getDefault().getTextTools(); - fSourceViewerConfiguration = new CSourceViewerConfiguration(tools, null) { - public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { - return IDocumentExtension3.DEFAULT_PARTITIONING; - } - - }; + IPreferenceStore store = getPreferenceStore(); + fSourceViewerConfiguration = new CSourceViewerConfiguration(tools.getColorManager(), store, null, null); } return fSourceViewerConfiguration; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index f0239af459f..2b6f20dadf9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -131,6 +131,7 @@ import org.eclipse.ui.part.EditorActionBarContributor; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.IShowInTargetList; import org.eclipse.ui.part.ShowInContext; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; @@ -217,7 +218,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR private boolean fIgnoreTextConverters= false; public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, - boolean showAnnotationsOverview, int styles) { + boolean showAnnotationsOverview, int styles, IPreferenceStore store) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); } @@ -305,11 +306,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR if (prefixes != null && prefixes.length > 0) setIndentPrefixes(prefixes, types[i]); } - - StyledText textWidget= getTextWidget(); - int tabWidth= configuration.getTabWidth(this); - if (textWidget.getTabs() != tabWidth) - textWidget.setTabs(tabWidth); } /* @@ -1601,15 +1597,16 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor() */ protected void initializeEditor() { + IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore(); + setPreferenceStore(store); CTextTools textTools = CUIPlugin.getDefault().getTextTools(); - setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools, this)); + setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools.getColorManager(), store, this, textTools.getDocumentPartitioning())); setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider()); setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$ setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$ - setPreferenceStore(CUIPlugin.getDefault().getCombinedPreferenceStore()); fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this); } @@ -1731,11 +1728,21 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR * @param event the property change event */ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { + String property = event.getProperty(); + + if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) { + /* + * Ignore tab setting since we rely on the formatter preferences. + * We do this outside the try-finally block to avoid that EDITOR_TAB_WIDTH + * is handled by the sub-class (AbstractDecoratedTextEditor). + */ + return; + } + try { AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); if (asv != null) { - String property = event.getProperty(); if (CLOSE_BRACKETS.equals(property)) { fBracketInserter.setCloseBracketsEnabled(getPreferenceStore().getBoolean(property)); @@ -1753,11 +1760,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR } if (SPACES_FOR_TABS.equals(property)) { - SourceViewerConfiguration configuration = getSourceViewerConfiguration(); - String[] types = configuration.getConfiguredContentTypes(asv); - for (int i = 0; i < types.length; i++) { - asv.setIndentPrefixes(configuration.getIndentPrefixes(asv, types[i]), types[i]); - } if (isTabConversionEnabled()) startTabConversion(); else @@ -1768,9 +1770,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR if (PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property)) updateHoverBehavior(); + ((CSourceViewerConfiguration)getSourceViewerConfiguration()).handlePropertyChangeEvent(event); if (PreferenceConstants.EDITOR_SMART_TAB.equals(property)) { - if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) { + if (getPreferenceStore().getBoolean(property)) { setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$ } else { removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$ @@ -1802,6 +1805,16 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR return; } + if (DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property) + || DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE.equals(property) + || DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property)) { + StyledText textWidget= asv.getTextWidget(); + int tabWidth= getSourceViewerConfiguration().getTabWidth(asv); + if (textWidget.getTabs() != tabWidth) + textWidget.setTabs(tabWidth); + return; + } + if (SemanticHighlightings.affectsEnablement(getPreferenceStore(), event)) { if (isSemanticHighlightingEnabled()) { installSemanticHighlighting(); @@ -2344,29 +2357,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR } }; - fInformationPresenter = new InformationPresenter( - informationControlCreator); + fInformationPresenter = new InformationPresenter(informationControlCreator); fInformationPresenter.setSizeConstraints(60, 10, true, true); fInformationPresenter.install(getSourceViewer()); - fInformationPresenter - .setDocumentPartitioning(ICPartitions.C_PARTITIONING); + fInformationPresenter.setDocumentPartitioning(ICPartitions.C_PARTITIONING); - - ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); - - fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); - fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ - fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ - fProjectionSupport.addSummarizableAnnotationType("org.eclipse.search.results"); //$NON-NLS-1$ - fProjectionSupport.install(); - - fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); - if (fProjectionModelUpdater != null) - fProjectionModelUpdater.install(this, projectionViewer); - - if (isFoldingEnabled()) - projectionViewer.doOperation(ProjectionViewer.TOGGLE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICHelpContextIds.CEDITOR_VIEW); fEditorSelectionChangedListener = new EditorSelectionChangedListener(); @@ -2657,11 +2652,44 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int) */ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { + IPreferenceStore store= getPreferenceStore(); ISourceViewer sourceViewer = - new AdaptedSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles); + new AdaptedSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles, store); CUIHelp.setHelp(this, sourceViewer.getTextWidget(), ICHelpContextIds.CEDITOR_VIEW); + CSourceViewer cSourceViewer= null; + if (sourceViewer instanceof CSourceViewer) { + cSourceViewer= (CSourceViewer) sourceViewer; + } + + /* + * This is a performance optimization to reduce the computation of + * the text presentation triggered by {@link #setVisibleDocument(IDocument)} + */ + if (cSourceViewer != null && isFoldingEnabled() && (store == null || !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS))) + cSourceViewer.prepareDelayedProjection(); + + ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer; + + fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); + fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ + fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ + fProjectionSupport.addSummarizableAnnotationType("org.eclipse.search.results"); //$NON-NLS-1$ + fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell shell) { + return new SourceViewerInformationControl(shell, SWT.TOOL | SWT.NO_TRIM | getOrientation(), SWT.NONE); + } + }); + fProjectionSupport.install(); + + fProjectionModelUpdater = CUIPlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); + if (fProjectionModelUpdater != null) + fProjectionModelUpdater.install(this, projectionViewer); + + if (isFoldingEnabled()) + projectionViewer.doOperation(ProjectionViewer.TOGGLE); + getSourceViewerDecorationSupport(sourceViewer); return sourceViewer; @@ -2677,20 +2705,20 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR fOutlinerContextMenuId = menuId; } - /* (non-Javadoc) + /* * @see org.eclipse.ui.editors.text.TextEditor#initializeKeyBindingScopes() */ protected void initializeKeyBindingScopes() { setKeyBindingScopes(new String [] { "org.eclipse.cdt.ui.cEditorScope" } ); //$NON-NLS-1$ } - /* (non-Javadoc) + /* * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) */ protected boolean affectsTextPresentation(PropertyChangeEvent event) { SourceViewerConfiguration configuration = getSourceViewerConfiguration(); if (configuration instanceof CSourceViewerConfiguration) { - return ((CSourceViewerConfiguration)configuration).affectsBehavior(event); + return ((CSourceViewerConfiguration)configuration).affectsTextPresentation(event); } return false; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java index 12ba125958a..40d038d2b26 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java @@ -19,6 +19,7 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextPresentationListener; import org.eclipse.jface.text.Region; @@ -91,6 +92,16 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi */ private boolean fIsConfigured; + /** + * Whether to delay setting the visual document until the projection has been computed. + *

+ * Added for performance optimization. + *

+ * @see #prepareDelayedProjection() + * @since 4.0 + */ + private boolean fIsSetVisibleDocumentDelayed; + /** * Creates new source viewer. * @param parent @@ -382,7 +393,46 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi fTextPresentationListeners.remove(listener); fTextPresentationListeners.add(0, listener); } + + /** + * Delays setting the visual document until after the projection has been computed. + * This method must only be called before the document is set on the viewer. + *

+ * This is a performance optimization to reduce the computation of + * the text presentation triggered by setVisibleDocument(IDocument). + *

+ * + * @see #setVisibleDocument(IDocument) + * @since 4.0 + */ + void prepareDelayedProjection() { + Assert.isTrue(!fIsSetVisibleDocumentDelayed); + fIsSetVisibleDocumentDelayed= true; + } + /** + * {@inheritDoc} + *

+ * This is a performance optimization to reduce the computation of + * the text presentation triggered by {@link #setVisibleDocument(IDocument)} + *

+ * @see #prepareDelayedProjection() + * @since 4.0 + */ + protected void setVisibleDocument(IDocument document) { + if (fIsSetVisibleDocumentDelayed) { + fIsSetVisibleDocumentDelayed= false; + IDocument previous= getVisibleDocument(); + enableProjection(); // will set the visible document if anything is folded + IDocument current= getVisibleDocument(); + // if the visible document was not replaced, continue as usual + if (current != null && current != previous) + return; + } + + super.setVisibleDocument(document); + } + /** * {@inheritDoc} *

diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleCSourceViewerConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleCSourceViewerConfiguration.java index 22a1bf7ba03..2673cfb2212 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleCSourceViewerConfiguration.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleCSourceViewerConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 IBM Corporation 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Sergey Prigogin, Google + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text; @@ -53,7 +54,7 @@ public class SimpleCSourceViewerConfiguration extends CSourceViewerConfiguration } /* - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String) + * @see SourceViewerConfiguration#getAutoEditStrategies(ISourceViewer, String) */ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { return null; @@ -119,23 +120,16 @@ public class SimpleCSourceViewerConfiguration extends CSourceViewerConfiguration } /* - * @see org.eclipse.cdt.ui.text.CSourceViewerConfiguration#getOutlinePresenter(org.eclipse.jface.text.source.ISourceViewer, boolean) - */ - public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) { - return null; - } - - /* - * @see org.eclipse.cdt.ui.text.CSourceViewerConfiguration#getHierarchyPresenter(org.eclipse.jface.text.source.ISourceViewer, boolean) - */ - public IInformationPresenter getHierarchyPresenter(ISourceViewer sourceViewer, boolean doCodeResolve) { - return null; - } - - /* - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer) + * @see SourceViewerConfiguration#getHyperlinkDetectors(ISourceViewer) */ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { return null; } + + /* + * @see CSourceViewerConfiguration#getOutlinePresenter(ISourceViewer) + */ + public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer) { + return null; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java index e41357d90a0..0bc98b9de69 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java @@ -7,12 +7,13 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.c.hover; -import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; -import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IInformationControl; @@ -38,6 +39,13 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; + +import org.eclipse.cdt.internal.ui.editor.CSourceViewer; +import org.eclipse.cdt.internal.ui.text.CTextTools; +import org.eclipse.cdt.internal.ui.text.SimpleCSourceViewerConfiguration; + /** * SourceViewerInformationControl * Source viewer based implementation of IInformationControl. @@ -72,6 +80,16 @@ public class SourceViewerInformationControl implements IInformationControl, IInf * @since 3.0 */ private Font fStatusTextFont; + /** + * The width size constraint. + * @since 4.0 + */ + private int fMaxWidth= SWT.DEFAULT; + /** + * The height size constraint. + * @since 4.0 + */ + private int fMaxHeight= SWT.DEFAULT; /** * Creates a default information control with the given shell as parent. The given @@ -128,9 +146,10 @@ public class SourceViewerInformationControl implements IInformationControl, IInf } // Source viewer - //IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore(); - fViewer= new SourceViewer(composite, null, null, false, style); - fViewer.configure(new CSourceViewerConfiguration(CUIPlugin.getDefault().getTextTools(), null)); + IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore(); + fViewer= new CSourceViewer(composite, null, null, false, style, store); + CTextTools tools= CUIPlugin.getDefault().getTextTools(); + fViewer.configure(new SimpleCSourceViewerConfiguration(tools.getColorManager(), store, null, tools.getDocumentPartitioning(), false)); fViewer.setEditable(false); fText= fViewer.getTextWidget(); @@ -138,7 +157,9 @@ public class SourceViewerInformationControl implements IInformationControl, IInf fText.setLayoutData(gd); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - + + initializeFont(); + fText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { @@ -229,6 +250,17 @@ public class SourceViewerInformationControl implements IInformationControl, IInf this(parent, SWT.NONE, statusFieldText); } + /** + * Initialize the font to the editor font. + * + * @since 4.0 + */ + private void initializeFont() { + Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); + StyledText styledText= getViewer().getTextWidget(); + styledText.setFont(font); + } + /* * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) */ @@ -315,14 +347,28 @@ public class SourceViewerInformationControl implements IInformationControl, IInf * @see IInformationControl#setSizeConstraints(int, int) */ public void setSizeConstraints(int maxWidth, int maxHeight) { - maxWidth= maxHeight; + fMaxWidth= maxWidth; + fMaxHeight= maxHeight; } /* * @see IInformationControl#computeSizeHint() */ public Point computeSizeHint() { - return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT); + // compute the preferred size + int x= SWT.DEFAULT; + int y= SWT.DEFAULT; + Point size= fShell.computeSize(x, y); + if (size.x > fMaxWidth) + x= fMaxWidth; + if (size.y > fMaxHeight) + y= fMaxHeight; + + // recompute using the constraints if the preferred size is larger than the constraints + if (x != SWT.DEFAULT || y != SWT.DEFAULT) + size= fShell.computeSize(x, y, false); + + return size; } /*