From bae54f4e476a43a0f683c7cc1ccc3ab44d0a3f8e Mon Sep 17 00:00:00 2001 From: David Inglis Date: Fri, 10 Sep 2004 14:38:50 +0000 Subject: [PATCH] put error ticks in outline view --- .../ui/editor/CContentOutlinePage.java | 3 ++- .../viewsupport/ProblemsLabelDecorator.java | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index a76530f7657..e4ff3f2e241 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.internal.ui.actions.AbstractToggleLinkingAction; import org.eclipse.cdt.internal.ui.actions.ActionMessages; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; +import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider; import org.eclipse.cdt.internal.ui.viewsupport.StandardCElementLabelProvider; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; @@ -231,7 +232,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS //treeViewer.setContentProvider(new CElementContentProvider(true, true)); treeViewer.setContentProvider(new CContentOutlinerProvider(this)); - treeViewer.setLabelProvider(new StandardCElementLabelProvider()); + treeViewer.setLabelProvider(new DecoratingCLabelProvider(new StandardCElementLabelProvider(), true)); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); treeViewer.addSelectionChangedListener(this); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 68efa80cf23..bbc5fd772a7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -41,6 +41,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.texteditor.MarkerAnnotation; +import org.eclipse.ui.texteditor.MarkerUtilities; /** * LabelDecorator that decorates an element's image with error and warning overlays that @@ -168,7 +169,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe case ICElement.C_METHOD: ITranslationUnit tu= ((ISourceReference)element).getTranslationUnit(); if (tu != null && tu.exists()) { - return getErrorTicksFromMarkers(tu.getResource(), IResource.DEPTH_ONE, tu); + return getErrorTicksFromMarkers(tu.getResource(), IResource.DEPTH_ONE, (ISourceReference)element); } default: } @@ -216,7 +217,14 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe private boolean isMarkerInRange(IMarker marker, ISourceReference sourceElement) throws CoreException { if (marker.isSubtypeOf(IMarker.TEXT)) { int pos= marker.getAttribute(IMarker.CHAR_START, -1); - return isInside(pos, sourceElement); + if (pos == -1) { + int line= MarkerUtilities.getLineNumber(marker); + if (line >= 0) { + return isInside( -1, line, sourceElement); + } + } + return isInside(pos, -1, sourceElement); + } return false; } @@ -249,7 +257,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe IMarker marker= ((MarkerAnnotation) annot).getMarker(); if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) { Position pos= model.getPosition(annot); - if (pos != null && (sourceElement == null || isInside(pos.getOffset(), sourceElement))) { + if (pos != null && (sourceElement == null || isInside(pos.getOffset(), -1, sourceElement))) { return marker; } } @@ -266,11 +274,14 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe * * @since 2.1 */ - protected boolean isInside(int pos, ISourceReference sourceElement) throws CoreException { + protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException { ISourceRange range= sourceElement.getSourceRange(); if (range != null) { + if (offSet ==-1) { + return (line >= range.getStartLine() && line <= range.getEndLine()); + } int rangeOffset= range.getStartPos(); - return (rangeOffset <= pos && rangeOffset + range.getLength() > pos); + return (rangeOffset <= offSet && rangeOffset + range.getLength() > offSet); } return false; }