mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Cleanup handling of editor preference changes
This commit is contained in:
parent
c3fbed60b8
commit
ad88076d70
5 changed files with 214 additions and 89 deletions
|
@ -8,17 +8,16 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* QNX Software System
|
* QNX Software System
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.compare;
|
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.CompareConfiguration;
|
||||||
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
|
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.preference.PreferenceConverter;
|
import org.eclipse.jface.preference.PreferenceConverter;
|
||||||
import org.eclipse.jface.text.*;
|
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.TextViewer;
|
||||||
import org.eclipse.jface.text.source.SourceViewer;
|
import org.eclipse.jface.text.source.SourceViewer;
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
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.swt.widgets.Composite;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
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 {
|
public class CMergeViewer extends TextMergeViewer {
|
||||||
|
|
||||||
private static final String TITLE= "CMergeViewer.title"; //$NON-NLS-1$
|
private static final String TITLE= "CMergeViewer.title"; //$NON-NLS-1$
|
||||||
|
@ -38,8 +43,22 @@ public class CMergeViewer extends TextMergeViewer {
|
||||||
|
|
||||||
public CMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
|
public CMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
|
||||||
super(parent, styles, mp);
|
super(parent, styles, mp);
|
||||||
|
|
||||||
|
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();
|
fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||||
if (fPreferenceStore != null) {
|
|
||||||
fPreferenceChangeListener= new IPropertyChangeListener() {
|
fPreferenceChangeListener= new IPropertyChangeListener() {
|
||||||
public void propertyChange(PropertyChangeEvent event) {
|
public void propertyChange(PropertyChangeEvent event) {
|
||||||
handlePropertyChange(event);
|
handlePropertyChange(event);
|
||||||
|
@ -47,15 +66,7 @@ public class CMergeViewer extends TextMergeViewer {
|
||||||
};
|
};
|
||||||
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
|
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
|
||||||
}
|
}
|
||||||
|
return fPreferenceStore;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDispose(DisposeEvent event) {
|
protected void handleDispose(DisposeEvent event) {
|
||||||
|
@ -97,8 +108,8 @@ public class CMergeViewer extends TextMergeViewer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getSourceViewerConfiguration().affectsBehavior(event)) {
|
if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) {
|
||||||
getSourceViewerConfiguration().adaptToPreferenceChange(event);
|
getSourceViewerConfiguration().handlePropertyChangeEvent(event);
|
||||||
invalidateTextPresentation();
|
invalidateTextPresentation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,12 +129,8 @@ public class CMergeViewer extends TextMergeViewer {
|
||||||
private CSourceViewerConfiguration getSourceViewerConfiguration() {
|
private CSourceViewerConfiguration getSourceViewerConfiguration() {
|
||||||
if (fSourceViewerConfiguration == null) {
|
if (fSourceViewerConfiguration == null) {
|
||||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||||
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools, null) {
|
IPreferenceStore store = getPreferenceStore();
|
||||||
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
|
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools.getColorManager(), store, null, null);
|
||||||
return IDocumentExtension3.DEFAULT_PARTITIONING;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return fSourceViewerConfiguration;
|
return fSourceViewerConfiguration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,7 @@ import org.eclipse.ui.part.EditorActionBarContributor;
|
||||||
import org.eclipse.ui.part.IShowInSource;
|
import org.eclipse.ui.part.IShowInSource;
|
||||||
import org.eclipse.ui.part.IShowInTargetList;
|
import org.eclipse.ui.part.IShowInTargetList;
|
||||||
import org.eclipse.ui.part.ShowInContext;
|
import org.eclipse.ui.part.ShowInContext;
|
||||||
|
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
|
||||||
import org.eclipse.ui.texteditor.ContentAssistAction;
|
import org.eclipse.ui.texteditor.ContentAssistAction;
|
||||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
import org.eclipse.ui.texteditor.IEditorStatusLine;
|
import org.eclipse.ui.texteditor.IEditorStatusLine;
|
||||||
|
@ -217,7 +218,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
private boolean fIgnoreTextConverters= false;
|
private boolean fIgnoreTextConverters= false;
|
||||||
|
|
||||||
public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
|
public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
|
||||||
boolean showAnnotationsOverview, int styles) {
|
boolean showAnnotationsOverview, int styles, IPreferenceStore store) {
|
||||||
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
|
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,11 +306,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
if (prefixes != null && prefixes.length > 0)
|
if (prefixes != null && prefixes.length > 0)
|
||||||
setIndentPrefixes(prefixes, types[i]);
|
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()
|
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
|
||||||
*/
|
*/
|
||||||
protected void initializeEditor() {
|
protected void initializeEditor() {
|
||||||
|
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||||
|
setPreferenceStore(store);
|
||||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||||
setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools, this));
|
setSourceViewerConfiguration(new CSourceViewerConfiguration(textTools.getColorManager(), store, this, textTools.getDocumentPartitioning()));
|
||||||
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider());
|
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider());
|
||||||
|
|
||||||
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$
|
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$
|
||||||
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$
|
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$
|
||||||
setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
|
setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
|
||||||
|
|
||||||
setPreferenceStore(CUIPlugin.getDefault().getCombinedPreferenceStore());
|
|
||||||
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this);
|
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1731,11 +1728,21 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
* @param event the property change event
|
* @param event the property change event
|
||||||
*/
|
*/
|
||||||
protected void handlePreferenceStoreChanged(PropertyChangeEvent 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 {
|
try {
|
||||||
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
||||||
|
|
||||||
if (asv != null) {
|
if (asv != null) {
|
||||||
String property = event.getProperty();
|
|
||||||
|
|
||||||
if (CLOSE_BRACKETS.equals(property)) {
|
if (CLOSE_BRACKETS.equals(property)) {
|
||||||
fBracketInserter.setCloseBracketsEnabled(getPreferenceStore().getBoolean(property));
|
fBracketInserter.setCloseBracketsEnabled(getPreferenceStore().getBoolean(property));
|
||||||
|
@ -1753,11 +1760,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SPACES_FOR_TABS.equals(property)) {
|
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())
|
if (isTabConversionEnabled())
|
||||||
startTabConversion();
|
startTabConversion();
|
||||||
else
|
else
|
||||||
|
@ -1768,9 +1770,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
if (PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property))
|
if (PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property))
|
||||||
updateHoverBehavior();
|
updateHoverBehavior();
|
||||||
|
|
||||||
|
((CSourceViewerConfiguration)getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
|
||||||
|
|
||||||
if (PreferenceConstants.EDITOR_SMART_TAB.equals(property)) {
|
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$
|
setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
|
||||||
} else {
|
} else {
|
||||||
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$
|
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$
|
||||||
|
@ -1802,6 +1805,16 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
return;
|
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 (SemanticHighlightings.affectsEnablement(getPreferenceStore(), event)) {
|
||||||
if (isSemanticHighlightingEnabled()) {
|
if (isSemanticHighlightingEnabled()) {
|
||||||
installSemanticHighlighting();
|
installSemanticHighlighting();
|
||||||
|
@ -2344,28 +2357,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fInformationPresenter = new InformationPresenter(
|
fInformationPresenter = new InformationPresenter(informationControlCreator);
|
||||||
informationControlCreator);
|
|
||||||
fInformationPresenter.setSizeConstraints(60, 10, true, true);
|
fInformationPresenter.setSizeConstraints(60, 10, true, true);
|
||||||
fInformationPresenter.install(getSourceViewer());
|
fInformationPresenter.install(getSourceViewer());
|
||||||
fInformationPresenter
|
fInformationPresenter.setDocumentPartitioning(ICPartitions.C_PARTITIONING);
|
||||||
.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);
|
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICHelpContextIds.CEDITOR_VIEW);
|
||||||
|
|
||||||
|
@ -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)
|
* @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) {
|
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
||||||
|
IPreferenceStore store= getPreferenceStore();
|
||||||
ISourceViewer sourceViewer =
|
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);
|
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);
|
getSourceViewerDecorationSupport(sourceViewer);
|
||||||
|
|
||||||
return sourceViewer;
|
return sourceViewer;
|
||||||
|
@ -2677,20 +2705,20 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
fOutlinerContextMenuId = menuId;
|
fOutlinerContextMenuId = menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see org.eclipse.ui.editors.text.TextEditor#initializeKeyBindingScopes()
|
* @see org.eclipse.ui.editors.text.TextEditor#initializeKeyBindingScopes()
|
||||||
*/
|
*/
|
||||||
protected void initializeKeyBindingScopes() {
|
protected void initializeKeyBindingScopes() {
|
||||||
setKeyBindingScopes(new String [] { "org.eclipse.cdt.ui.cEditorScope" } ); //$NON-NLS-1$
|
setKeyBindingScopes(new String [] { "org.eclipse.cdt.ui.cEditorScope" } ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
|
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
|
||||||
*/
|
*/
|
||||||
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
|
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
|
||||||
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
|
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
|
||||||
if (configuration instanceof CSourceViewerConfiguration) {
|
if (configuration instanceof CSourceViewerConfiguration) {
|
||||||
return ((CSourceViewerConfiguration)configuration).affectsBehavior(event);
|
return ((CSourceViewerConfiguration)configuration).affectsTextPresentation(event);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.preference.PreferenceConverter;
|
import org.eclipse.jface.preference.PreferenceConverter;
|
||||||
import org.eclipse.jface.text.Assert;
|
import org.eclipse.jface.text.Assert;
|
||||||
import org.eclipse.jface.text.DocumentCommand;
|
import org.eclipse.jface.text.DocumentCommand;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextPresentationListener;
|
import org.eclipse.jface.text.ITextPresentationListener;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
|
@ -91,6 +92,16 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
|
||||||
*/
|
*/
|
||||||
private boolean fIsConfigured;
|
private boolean fIsConfigured;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to delay setting the visual document until the projection has been computed.
|
||||||
|
* <p>
|
||||||
|
* Added for performance optimization.
|
||||||
|
* </p>
|
||||||
|
* @see #prepareDelayedProjection()
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
private boolean fIsSetVisibleDocumentDelayed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new source viewer.
|
* Creates new source viewer.
|
||||||
* @param parent
|
* @param parent
|
||||||
|
@ -383,6 +394,45 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
|
||||||
fTextPresentationListeners.add(0, 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.
|
||||||
|
* <p>
|
||||||
|
* This is a performance optimization to reduce the computation of
|
||||||
|
* the text presentation triggered by <code>setVisibleDocument(IDocument)</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see #setVisibleDocument(IDocument)
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
void prepareDelayedProjection() {
|
||||||
|
Assert.isTrue(!fIsSetVisibleDocumentDelayed);
|
||||||
|
fIsSetVisibleDocumentDelayed= true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* <p>
|
||||||
|
* This is a performance optimization to reduce the computation of
|
||||||
|
* the text presentation triggered by {@link #setVisibleDocument(IDocument)}
|
||||||
|
* </p>
|
||||||
|
* @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}
|
* {@inheritDoc}
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Sergey Prigogin, Google
|
* Sergey Prigogin, Google
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text;
|
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) {
|
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
|
||||||
return null;
|
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)
|
* @see SourceViewerConfiguration#getHyperlinkDetectors(ISourceViewer)
|
||||||
*/
|
|
||||||
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)
|
|
||||||
*/
|
*/
|
||||||
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
|
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see CSourceViewerConfiguration#getOutlinePresenter(ISourceViewer)
|
||||||
|
*/
|
||||||
|
public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.jface.resource.JFaceResources;
|
||||||
import org.eclipse.jface.text.Document;
|
import org.eclipse.jface.text.Document;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IInformationControl;
|
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.Label;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
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
|
* SourceViewerInformationControl
|
||||||
* Source viewer based implementation of <code>IInformationControl</code>.
|
* Source viewer based implementation of <code>IInformationControl</code>.
|
||||||
|
@ -72,6 +80,16 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
private Font fStatusTextFont;
|
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
|
* 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
|
// Source viewer
|
||||||
//IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||||
fViewer= new SourceViewer(composite, null, null, false, style);
|
fViewer= new CSourceViewer(composite, null, null, false, style, store);
|
||||||
fViewer.configure(new CSourceViewerConfiguration(CUIPlugin.getDefault().getTextTools(), null));
|
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||||
|
fViewer.configure(new SimpleCSourceViewerConfiguration(tools.getColorManager(), store, null, tools.getDocumentPartitioning(), false));
|
||||||
fViewer.setEditable(false);
|
fViewer.setEditable(false);
|
||||||
|
|
||||||
fText= fViewer.getTextWidget();
|
fText= fViewer.getTextWidget();
|
||||||
|
@ -139,6 +158,8 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
|
||||||
fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
|
fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
|
||||||
fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
|
fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
|
||||||
|
|
||||||
|
initializeFont();
|
||||||
|
|
||||||
fText.addKeyListener(new KeyListener() {
|
fText.addKeyListener(new KeyListener() {
|
||||||
|
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
|
@ -229,6 +250,17 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
|
||||||
this(parent, SWT.NONE, statusFieldText);
|
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)
|
* @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)
|
* @see IInformationControl#setSizeConstraints(int, int)
|
||||||
*/
|
*/
|
||||||
public void setSizeConstraints(int maxWidth, int maxHeight) {
|
public void setSizeConstraints(int maxWidth, int maxHeight) {
|
||||||
maxWidth= maxHeight;
|
fMaxWidth= maxWidth;
|
||||||
|
fMaxHeight= maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see IInformationControl#computeSizeHint()
|
* @see IInformationControl#computeSizeHint()
|
||||||
*/
|
*/
|
||||||
public Point 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue