/** Selects a Dart Element in an editor */ public static void revealInEditor(IEditorPart part, Object element) { if (element == null) { return; } // TODO(scheglov) to be removed with method // if (part instanceof DartEditor) { // ((DartEditor) part).setSelection(element); // return; // } // Support for non-Dart editor try { SourceRange range = null; DartX.todo(); if (element instanceof SourceReference) { range = ((SourceReference) element).getSourceRange(); } if (range != null) { revealInEditor(part, range.getOffset(), range.getLength()); } } catch (DartModelException e) { // don't reveal } }
/** * Opens an editor on the given Dart element in the active page. Valid elements are all Dart * elements that are {@link SourceReference}. For elements inside a compilation unit, the parent * is opened in the editor is opened. If there already is an open Dart editor for the given * element, it is returned. * * @param element the input element; either a compilation unit ( <code>CompilationUnit</code>) or * a class file ( <code>IClassFile</code>) or source references inside. * @param activate if set, the editor will be activated. * @param reveal if set, the element will be revealed. * @return returns the editor part of the opened editor or <code>null</code> if the element is not * a {@link SourceReference} or the file was opened in an external editor. * @exception PartInitException if the editor could not be initialized or no workbench page is * active * @exception DartModelException if this element does not exist or if an exception occurs while * accessing its underlying resource */ public static IEditorPart openInEditor(Element element, boolean activate, boolean reveal) throws DartModelException, PartInitException { IEditorPart part = EditorUtility.openInEditor(element, activate); if (reveal && part != null) { EditorUtility.revealInEditor(part, element); } return part; }
/** * Opens an editor on the given Dart element in the active page. Valid elements are all Dart * elements that are {@link SourceReference}. For elements inside a compilation unit, the parent * is opened in the editor is opened. If there already is an open Dart editor for the given * element, it is returned. * * @param element the input element; either a compilation unit ( <code>CompilationUnit</code>) or * a class file ( <code>IClassFile</code>) or source references inside. * @param activate if set, the editor will be activated. * @param reveal if set, the element will be revealed. * @return returns the editor part of the opened editor or <code>null</code> if the element is not * a {@link SourceReference} or the file was opened in an external editor. * @exception PartInitException if the editor could not be initialized or no workbench page is * active * @exception DartModelException if this element does not exist or if an exception occurs while * accessing its underlying resource */ public static IEditorPart openInEditor(DartElement element, boolean activate, boolean reveal) throws DartModelException, PartInitException { if (!(element instanceof SourceReference)) { return null; } IEditorPart part = EditorUtility.openInEditor(element, activate); if (reveal && part != null) { EditorUtility.revealInEditor(part, element); } return part; }
/** * Reveals the given Dart element in the given editor. If the element is not an instance of <code> * SourceReference</code> this method result in a NOP. If it is a source reference no checking is * done if the editor displays a compilation unit or class file that contains the source reference * element. The editor simply reveals the source range denoted by the given element. * * @param part the editor displaying a compilation unit or class file * @param element the element to be revealed */ public static void revealInEditor(IEditorPart part, DartElement element) { EditorUtility.revealInEditor(part, element); }
/** Selects and reveals the given region in the given editor part. */ public static void revealInEditor(IEditorPart part, IRegion region) { if (part != null && region != null) { revealInEditor(part, region.getOffset(), region.getLength()); } }
/** Selects and reveals the given source range in the given editor part. */ public static void revealInEditor( IEditorPart part, com.google.dart.engine.utilities.source.SourceRange range) { if (part != null && range != null) { revealInEditor(part, range.getOffset(), range.getLength()); } }