diff options
author | Nathan Ridge | 2015-07-26 05:59:37 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-08-03 23:44:30 +0000 |
commit | 3b4d359fa69ae108aea9d64bbf2f3fa1f9105b4d (patch) | |
tree | 7e85079960497522c4144e20444442a8c9fd6aa0 | |
parent | 0292fcf13598fd5900faa4222cec9baf5cdee5da (diff) | |
download | org.eclipse.cdt-3b4d359fa69ae108aea9d64bbf2f3fa1f9105b4d.tar.gz org.eclipse.cdt-3b4d359fa69ae108aea9d64bbf2f3fa1f9105b4d.tar.xz org.eclipse.cdt-3b4d359fa69ae108aea9d64bbf2f3fa1f9105b4d.zip |
Bug 473577 - If there are multiple markers on a line, give each one,
from top to bottom, a chance to handle a click
Change-Id: I294b5511e65dfe593dfbb58beda6888da1870779
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
-rw-r--r-- | core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/correction/CSelectAnnotationRulerAction.java | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/correction/CSelectAnnotationRulerAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/correction/CSelectAnnotationRulerAction.java index f3f0daec9f8..87526272733 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/correction/CSelectAnnotationRulerAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/correction/CSelectAnnotationRulerAction.java @@ -11,8 +11,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.correction; +import java.util.Comparator; import java.util.Iterator; import java.util.ResourceBundle; +import java.util.TreeMap; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.IDocument; @@ -45,9 +47,17 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { private Position fPosition; private AnnotationPreferenceLookup fAnnotationPreferenceLookup; private IPreferenceStore fStore; - private boolean fHasCorrection; private ResourceBundle fBundle; - private Annotation fAnnotation; + // Annotations at the ruler's current line of activity, keyed by their presentation layer, + // in decreasing order (i.e. top to bottom). + private static Comparator<Integer> decreasingOrder = new Comparator<Integer>(){ + @Override + public int compare(Integer a, Integer b) { + return b - a; + }}; + private TreeMap<Integer, Annotation> fAnnotations = new TreeMap<>(decreasingOrder); + // For each layer, whether the annotation at that layer has a correction. + private TreeMap<Integer, Boolean> fHasCorrection = new TreeMap<>(decreasingOrder); public CSelectAnnotationRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) { super(bundle, prefix, editor, ruler); @@ -72,20 +82,25 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { */ @Override public void runWithEvent(Event event) { - if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) { - ((OverrideIndicatorManager.OverrideIndicator)fAnnotation).open(); - return; - } - - if (fHasCorrection) { - ITextOperationTarget operation= fTextEditor.getAdapter(ITextOperationTarget.class); - final int opCode= ISourceViewer.QUICK_ASSIST; - if (operation != null && operation.canDoOperation(opCode)) { - fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); - operation.doOperation(opCode); - } - return; - } + // Give each annotation at the current line, from top to bottom, a chance to handle + // the action. If there are no takers, fall back to the super class implementation. + for (Integer layer : fAnnotations.keySet()) { + Annotation annotation = fAnnotations.get(layer); + if (annotation instanceof OverrideIndicatorManager.OverrideIndicator) { + ((OverrideIndicatorManager.OverrideIndicator)annotation).open(); + return; + } + + if (fHasCorrection.get(layer)) { + ITextOperationTarget operation= fTextEditor.getAdapter(ITextOperationTarget.class); + final int opCode= ISourceViewer.QUICK_ASSIST; + if (operation != null && operation.canDoOperation(opCode)) { + fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); + operation.doOperation(opCode); + } + return; + } + } super.run(); } @@ -99,14 +114,17 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { findCAnnotation(); setEnabled(true); - if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) { - initialize(fBundle, "CSelectAnnotationRulerAction.OpenSuperImplementation."); //$NON-NLS-1$ - return; - } - if (fHasCorrection) { - initialize(fBundle, "CSelectAnnotationRulerAction.QuickFix."); //$NON-NLS-1$ - return; - } + for (Integer layer : fAnnotations.keySet()) { + Annotation annotation = fAnnotations.get(layer); + if (annotation instanceof OverrideIndicatorManager.OverrideIndicator) { + initialize(fBundle, "CSelectAnnotationRulerAction.OpenSuperImplementation."); //$NON-NLS-1$ + return; + } + if (fHasCorrection.get(layer)) { + initialize(fBundle, "CSelectAnnotationRulerAction.QuickFix."); //$NON-NLS-1$ + return; + } + } initialize(fBundle, "CSelectAnnotationRulerAction.GotoAnnotation."); //$NON-NLS-1$; super.update(); @@ -114,8 +132,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { private void findCAnnotation() { fPosition= null; - fAnnotation = null; - fHasCorrection= false; + fAnnotations.clear(); + fHasCorrection.clear(); AbstractMarkerAnnotationModel model= getAnnotationModel(); IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension(); @@ -125,18 +143,15 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { return ; Iterator<?> iter= model.getAnnotationIterator(); - int layer= Integer.MIN_VALUE; while (iter.hasNext()) { Annotation annotation= (Annotation) iter.next(); if (annotation.isMarkedDeleted()) continue; - int annotationLayer= layer; + int layer = IAnnotationAccessExtension.DEFAULT_LAYER; if (annotationAccess != null) { - annotationLayer= annotationAccess.getLayer(annotation); - if (annotationLayer < layer) - continue; + layer= annotationAccess.getLayer(annotation); } Position position= model.getPosition(annotation); @@ -148,9 +163,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { if (!isReadOnly && CCorrectionProcessor.hasCorrections(annotation)) { fPosition= position; - fAnnotation = annotation; - fHasCorrection= true; - layer= annotationLayer; + fAnnotations.put(layer, annotation); + fHasCorrection.put(layer, true); continue; } AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation); @@ -163,9 +177,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction { if (fStore.getBoolean(key)) { fPosition= position; - fAnnotation = annotation; - fHasCorrection= false; - layer= annotationLayer; + fAnnotations.put(layer, annotation); + fHasCorrection.put(layer, false); } } } |