diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java index d90ef7f8f06..2ecc86d864b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SelectionConverter.java @@ -67,7 +67,25 @@ public class SelectionConverter { return StructuredSelection.EMPTY; } - public static IStructuredSelection convertSelectionToCElements(ISelection s) { + /** + * Converts objects of a structured selection to c elements if possible. + * This is a convenience method, fully equivalent to + * convertSelectionToCElements(s, false). + * @param s The structured selection + * @return The converted selection + */ + public static IStructuredSelection convertSelectionToCElements(ISelection s) { + return convertSelectionToCElements(s, false); + } + + /** + * Converts objects of a structured selection to c elements if possible. + * @param s The structured selection + * @param keepNonCElements Whether to keep objects in selection if they cannot be converted + * @return The converted selection + */ + public static IStructuredSelection convertSelectionToCElements(ISelection s, + boolean keepNonCElements) { List converted = new ArrayList(); if (s instanceof StructuredSelection) { Object[] elements = ((StructuredSelection) s).toArray(); @@ -79,8 +97,10 @@ public class SelectionConverter { ICElement c = (ICElement) ((IAdaptable) e).getAdapter(ICElement.class); if (c != null) { converted.add(c); - } - } + } else if (keepNonCElements) + converted.add(e); + } else if (keepNonCElements) + converted.add(e); } } return new StructuredSelection(converted.toArray()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java index 32bd26a01a2..2f02641e345 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java @@ -208,7 +208,7 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha * @see ISetSelectionTarget#selectReveal(ISelection) */ public void selectReveal(ISelection selection) { - IStructuredSelection ssel = SelectionConverter.convertSelectionToCElements(selection); + IStructuredSelection ssel = SelectionConverter.convertSelectionToCElements(selection, true); if (!ssel.isEmpty()) { getViewer().setSelection(ssel, true); }