diff options
Diffstat (limited to 'core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java')
-rw-r--r-- | core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java index a1f108bc289..cea6e25244f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,14 @@ * Markus Schorn - initial API and implementation * Ed Swartz (Nokia) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.viewsupport; +import java.net.URI; + +import org.eclipse.core.filesystem.EFS; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; @@ -25,6 +28,7 @@ import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IPositionConverter; +import org.eclipse.cdt.core.IPositionTrackerManager; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceRange; @@ -32,13 +36,13 @@ import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.core.PositionTrackerManager; import org.eclipse.cdt.internal.core.model.ext.ICElementHandle; import org.eclipse.cdt.internal.ui.util.EditorUtility; /** * An utility to open editors for references or elements. - * @author markus.schorn@windriver.com */ public class EditorOpener { @@ -68,6 +72,21 @@ public class EditorOpener { te.selectAndReveal(region.getOffset(), region.getLength()); } } + + private static void selectRegion(URI locationURI, IRegion region, long timestamp, IEditorPart editor) { + if (editor instanceof ITextEditor) { + ITextEditor te= (ITextEditor) editor; + final IPositionTrackerManager ptm = CCorePlugin.getPositionTrackerManager(); + if (ptm instanceof PositionTrackerManager) { + // will be API in 5.0 + IPositionConverter pc= ((PositionTrackerManager)ptm).findPositionConverter(locationURI, timestamp); + if (pc != null) { + region= pc.historicToActual(region); + } + } + te.selectAndReveal(region.getOffset(), region.getLength()); + } + } /** * Opens the editor for an external location, selecting the given region. @@ -84,6 +103,26 @@ public class EditorOpener { CUIPlugin.log(e); } } + + /** + * Opens the editor for an external EFS location, selecting the given region. + */ + public static void openExternalFile(IWorkbenchPage page, URI locationURI, IRegion region, long timestamp, ICElement context) { + IEditorPart editor= null; + try { + editor= EditorUtility.openInEditor(locationURI, context); + if (timestamp == 0) { + try { + timestamp= EFS.getStore(locationURI).fetchInfo().getLastModified(); + } catch (CoreException e) { + CUIPlugin.log(e); + } + } + selectRegion(locationURI, region, timestamp, editor); + } catch (PartInitException e) { + CUIPlugin.log(e); + } + } /** * Opens the editor for an ICElement, selecting the id. |