1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

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>
This commit is contained in:
Nathan Ridge 2015-07-26 01:59:37 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 0292fcf135
commit 3b4d359fa6

View file

@ -11,8 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text.correction; package org.eclipse.cdt.internal.ui.text.correction;
import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.TreeMap;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -45,9 +47,17 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
private Position fPosition; private Position fPosition;
private AnnotationPreferenceLookup fAnnotationPreferenceLookup; private AnnotationPreferenceLookup fAnnotationPreferenceLookup;
private IPreferenceStore fStore; private IPreferenceStore fStore;
private boolean fHasCorrection;
private ResourceBundle fBundle; 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) { public CSelectAnnotationRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) {
super(bundle, prefix, editor, ruler); super(bundle, prefix, editor, ruler);
@ -72,20 +82,25 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
*/ */
@Override @Override
public void runWithEvent(Event event) { public void runWithEvent(Event event) {
if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) { // Give each annotation at the current line, from top to bottom, a chance to handle
((OverrideIndicatorManager.OverrideIndicator)fAnnotation).open(); // the action. If there are no takers, fall back to the super class implementation.
return; for (Integer layer : fAnnotations.keySet()) {
} Annotation annotation = fAnnotations.get(layer);
if (annotation instanceof OverrideIndicatorManager.OverrideIndicator) {
if (fHasCorrection) { ((OverrideIndicatorManager.OverrideIndicator)annotation).open();
ITextOperationTarget operation= fTextEditor.getAdapter(ITextOperationTarget.class); return;
final int opCode= ISourceViewer.QUICK_ASSIST; }
if (operation != null && operation.canDoOperation(opCode)) {
fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); if (fHasCorrection.get(layer)) {
operation.doOperation(opCode); ITextOperationTarget operation= fTextEditor.getAdapter(ITextOperationTarget.class);
} final int opCode= ISourceViewer.QUICK_ASSIST;
return; if (operation != null && operation.canDoOperation(opCode)) {
} fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength());
operation.doOperation(opCode);
}
return;
}
}
super.run(); super.run();
} }
@ -99,14 +114,17 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
findCAnnotation(); findCAnnotation();
setEnabled(true); setEnabled(true);
if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) { for (Integer layer : fAnnotations.keySet()) {
initialize(fBundle, "CSelectAnnotationRulerAction.OpenSuperImplementation."); //$NON-NLS-1$ Annotation annotation = fAnnotations.get(layer);
return; if (annotation instanceof OverrideIndicatorManager.OverrideIndicator) {
} initialize(fBundle, "CSelectAnnotationRulerAction.OpenSuperImplementation."); //$NON-NLS-1$
if (fHasCorrection) { return;
initialize(fBundle, "CSelectAnnotationRulerAction.QuickFix."); //$NON-NLS-1$ }
return; if (fHasCorrection.get(layer)) {
} initialize(fBundle, "CSelectAnnotationRulerAction.QuickFix."); //$NON-NLS-1$
return;
}
}
initialize(fBundle, "CSelectAnnotationRulerAction.GotoAnnotation."); //$NON-NLS-1$; initialize(fBundle, "CSelectAnnotationRulerAction.GotoAnnotation."); //$NON-NLS-1$;
super.update(); super.update();
@ -114,8 +132,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
private void findCAnnotation() { private void findCAnnotation() {
fPosition= null; fPosition= null;
fAnnotation = null; fAnnotations.clear();
fHasCorrection= false; fHasCorrection.clear();
AbstractMarkerAnnotationModel model= getAnnotationModel(); AbstractMarkerAnnotationModel model= getAnnotationModel();
IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension(); IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension();
@ -125,18 +143,15 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
return ; return ;
Iterator<?> iter= model.getAnnotationIterator(); Iterator<?> iter= model.getAnnotationIterator();
int layer= Integer.MIN_VALUE;
while (iter.hasNext()) { while (iter.hasNext()) {
Annotation annotation= (Annotation) iter.next(); Annotation annotation= (Annotation) iter.next();
if (annotation.isMarkedDeleted()) if (annotation.isMarkedDeleted())
continue; continue;
int annotationLayer= layer; int layer = IAnnotationAccessExtension.DEFAULT_LAYER;
if (annotationAccess != null) { if (annotationAccess != null) {
annotationLayer= annotationAccess.getLayer(annotation); layer= annotationAccess.getLayer(annotation);
if (annotationLayer < layer)
continue;
} }
Position position= model.getPosition(annotation); Position position= model.getPosition(annotation);
@ -148,9 +163,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
if (!isReadOnly && CCorrectionProcessor.hasCorrections(annotation)) { if (!isReadOnly && CCorrectionProcessor.hasCorrections(annotation)) {
fPosition= position; fPosition= position;
fAnnotation = annotation; fAnnotations.put(layer, annotation);
fHasCorrection= true; fHasCorrection.put(layer, true);
layer= annotationLayer;
continue; continue;
} }
AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation); AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation);
@ -163,9 +177,8 @@ public class CSelectAnnotationRulerAction extends SelectMarkerRulerAction {
if (fStore.getBoolean(key)) { if (fStore.getBoolean(key)) {
fPosition= position; fPosition= position;
fAnnotation = annotation; fAnnotations.put(layer, annotation);
fHasCorrection= false; fHasCorrection.put(layer, false);
layer= annotationLayer;
} }
} }
} }