From fb9b38386a839627623fc886852be8614c51646a Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 31 Jan 2007 08:59:22 +0000 Subject: [PATCH] Fix for 172221, by Ed Swartz, better support for external files in include browser. --- .../ui/includebrowser/IBViewPart.java | 6 ++-- .../ui/navigator/OpenCElementAction.java | 7 ++++- .../internal/ui/viewsupport/EditorOpener.java | 29 +++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java index d7e84910bde..4c0eb062ada 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.includebrowser; @@ -79,6 +80,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.navigator.OpenCElementAction; import org.eclipse.cdt.internal.ui.util.Messages; import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener; import org.eclipse.cdt.internal.ui.viewsupport.ExtendedTreeViewer; @@ -643,7 +645,7 @@ public class IBViewPart extends ViewPart final ITranslationUnit tu= node.getRepresentedTranslationUnit(); if (tu != null) { // open - OpenFileAction ofa= new OpenFileAction(page); + OpenCElementAction ofa= new OpenCElementAction(page); ofa.selectionChanged(selection); m.add(ofa); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java index b8edfbcd28b..bed572735a5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.navigator; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; @@ -63,6 +65,9 @@ public class OpenCElementAction extends OpenFileAction { fOpenElement = null; if (selection.size() == 1) { Object element = selection.getFirstElement(); + if (!(element instanceof ICElement) && element instanceof IAdaptable) { + element = ((IAdaptable) element).getAdapter(ICElement.class); + } if (element instanceof ICElement && (element instanceof ISourceReference || element instanceof IBinary)) { fOpenElement = (ICElement) element; 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 60baeb4e771..2b97360f761 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 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; @@ -16,7 +17,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; -import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; @@ -30,12 +30,11 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.core.model.ext.ICElementHandle; -import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; +import org.eclipse.cdt.internal.ui.util.EditorUtility; /** * An utility to open editors for references or elements. @@ -74,18 +73,16 @@ public class EditorOpener { * Opens the editor for an external location, selecting the given region. */ public static void openExternalFile(IWorkbenchPage page, IPath location, IRegion region, long timestamp) { - IEditorPart editor= null; - if (timestamp == 0) { - timestamp= location.toFile().lastModified(); - } - ExternalEditorInput ei= new ExternalEditorInput(new FileStorage(null, location)); - try { - IEditorDescriptor descriptor = IDE.getEditorDescriptor(location.lastSegment()); - editor= IDE.openEditor(page, ei, descriptor.getId(), false); - } catch (PartInitException e) { - CUIPlugin.getDefault().log(e); - } - selectRegion(location, region, timestamp, editor); + IEditorPart editor= null; + try { + editor= EditorUtility.openInEditor(location, null); + if (timestamp == 0) { + timestamp= location.toFile().lastModified(); + } + selectRegion(location, region, timestamp, editor); + } catch (PartInitException e) { + CUIPlugin.getDefault().log(e); + } } /**