diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewerDecorationSupport.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewerDecorationSupport.java index af1fab9c60d..6f0d4edfffa 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewerDecorationSupport.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewerDecorationSupport.java @@ -224,10 +224,6 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor * @see org.eclipse.ui.texteditor.SourceViewerDecorationSupport#uninstall() */ public void uninstall() { - if (fInactiveCodeHighlighting != null) { - fInactiveCodeHighlighting.dispose(); - fInactiveCodeHighlighting= null; - } uninstallLineBackgroundPainter(); super.uninstall(); } @@ -252,12 +248,16 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor */ private void uninstallLineBackgroundPainter() { if (fLineBackgroundPainter != null) { + if (fInactiveCodeHighlighting != null) { + fInactiveCodeHighlighting.uninstall(); + fInactiveCodeHighlighting= null; + } if (fViewer instanceof ITextViewerExtension2) { ((ITextViewerExtension2)fViewer).removePainter(fLineBackgroundPainter); - fLineBackgroundPainter.deactivate(true); - fLineBackgroundPainter.dispose(); - fLineBackgroundPainter = null; } + fLineBackgroundPainter.deactivate(true); + fLineBackgroundPainter.dispose(); + fLineBackgroundPainter = null; } } @@ -269,8 +269,8 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor private void showInactiveCodePositions(boolean refresh) { installLineBackgroundPainter(); if (fLineBackgroundPainter != null) { - fInactiveCodeHighlighting= new InactiveCodeHighlighting(fLineBackgroundPainter, INACTIVE_CODE_KEY); - fInactiveCodeHighlighting.install(fEditor); + fInactiveCodeHighlighting= new InactiveCodeHighlighting(INACTIVE_CODE_KEY); + fInactiveCodeHighlighting.install(fEditor, fLineBackgroundPainter); if (refresh) { fInactiveCodeHighlighting.refresh(); } @@ -283,7 +283,7 @@ public class CSourceViewerDecorationSupport extends SourceViewerDecorationSuppor private void hideInactiveCodePositions() { if (fLineBackgroundPainter != null) { if (fInactiveCodeHighlighting != null) { - fInactiveCodeHighlighting.dispose(); + fInactiveCodeHighlighting.uninstall(); fInactiveCodeHighlighting= null; } if (!isCLPActive()) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java index 7ce2a91e7df..9f4db33b83b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java @@ -81,10 +81,10 @@ public class InactiveCodeHighlighting implements ICReconcilingListener { private List fInactiveCodePositions= Collections.EMPTY_LIST; /** - * @param lineBackgroundPainter + * Create a highlighter for the given key. + * @param highlightKey */ - public InactiveCodeHighlighting(LineBackgroundPainter lineBackgroundPainter, String highlightKey) { - fLineBackgroundPainter= lineBackgroundPainter; + public InactiveCodeHighlighting(String highlightKey) { fHighlightKey= highlightKey; } @@ -116,13 +116,16 @@ public class InactiveCodeHighlighting implements ICReconcilingListener { } /** - * Install this highlighting on the given editor. + * Install this highlighting on the given editor and line background painter. * * @param editor + * @param lineBackgroundPainter */ - public void install(CEditor editor) { + public void install(CEditor editor, LineBackgroundPainter lineBackgroundPainter) { assert fEditor == null; + assert editor != null && lineBackgroundPainter != null; fEditor= editor; + fLineBackgroundPainter= lineBackgroundPainter; fEditor.addReconcileListener(this); ICElement cElement= fEditor.getInputCElement(); if (cElement instanceof ITranslationUnit) { @@ -136,9 +139,15 @@ public class InactiveCodeHighlighting implements ICReconcilingListener { * Uninstall this highlighting from the editor. Does nothing if already uninstalled. */ public void uninstall() { - if (fLineBackgroundPainter != null) { + synchronized (fJobLock) { + if (fUpdateJob != null && fUpdateJob.getState() == Job.RUNNING) { + fUpdateJob.cancel(); + } + } + if (fLineBackgroundPainter != null && !fLineBackgroundPainter.isDisposed()) { fLineBackgroundPainter.removeHighlightPositions(fInactiveCodePositions); fInactiveCodePositions= Collections.EMPTY_LIST; + fLineBackgroundPainter= null; } if (fEditor != null) { fEditor.removeReconcileListener(this); @@ -147,11 +156,6 @@ public class InactiveCodeHighlighting implements ICReconcilingListener { } } - public void dispose() { - uninstall(); - fLineBackgroundPainter= null; - } - /** * Force refresh. */