mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 12:25:35 +02:00
OpenInclude action
This commit is contained in:
parent
c7b33d247f
commit
506adaf4b1
3 changed files with 150 additions and 2 deletions
|
@ -107,6 +107,11 @@ AddBuildTargetAction.description=Add make Target
|
|||
AddBuildTargetAction.tooltip= Add make Target
|
||||
AddBuildTargetAction.exception.internal=Internal Error
|
||||
|
||||
OpenIncludeAction.title=Open include directive
|
||||
OpenIncludeAction.description=Open an include directive
|
||||
OpenIncludeAction.tooltip= Include Directive
|
||||
OpenIncludeAction.exception.internal=Internal Error
|
||||
|
||||
TargetBuild.execption.message=Target Build Error
|
||||
TargetBuild.monitor.beginTask=Building Targets...
|
||||
TargetBuild.backgroundTask.name=Building Targets.
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.eclipse.jface.action.IMenuManager;
|
|||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
|
@ -219,11 +221,13 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
|||
protected MakefileEditor fEditor;
|
||||
protected Object fInput;
|
||||
protected AddBuildTargetAction fAddBuildTargetAction;
|
||||
protected OpenIncludeAction fOpenIncludeAction;
|
||||
|
||||
public MakefileContentOutlinePage(MakefileEditor editor) {
|
||||
super();
|
||||
fEditor = editor;
|
||||
fAddBuildTargetAction = new AddBuildTargetAction(this);
|
||||
fOpenIncludeAction = new OpenIncludeAction(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -248,7 +252,18 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
|||
Control tree = viewer.getControl();
|
||||
Menu menu = manager.createContextMenu(tree);
|
||||
tree.setMenu(menu);
|
||||
|
||||
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
|
||||
*/
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
if (fOpenIncludeAction != null) {
|
||||
fOpenIncludeAction.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
IPageSite site= getSite();
|
||||
site.registerContextMenu(MakeUIPlugin.getPluginId() + ".outline", manager, viewer); //$NON-NLS-1$
|
||||
site.setSelectionProvider(viewer);
|
||||
|
@ -259,8 +274,12 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
|||
* called to create the context menu of the outline
|
||||
*/
|
||||
protected void contextMenuAboutToShow(IMenuManager menu) {
|
||||
if (fAddBuildTargetAction.canActionBeAdded(getSelection()))
|
||||
if (fOpenIncludeAction.canActionBeAdded(getSelection())) {
|
||||
menu.add(fOpenIncludeAction);
|
||||
}
|
||||
if (fAddBuildTargetAction.canActionBeAdded(getSelection())) {
|
||||
menu.add(fAddBuildTargetAction);
|
||||
}
|
||||
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||
import org.eclipse.cdt.make.core.makefile.gnu.IInclude;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
/**
|
||||
* OpenIncludeAction
|
||||
*/
|
||||
public class OpenIncludeAction extends Action {
|
||||
|
||||
ISelectionProvider fSelectionProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public OpenIncludeAction(ISelectionProvider provider) {
|
||||
super(MakeUIPlugin.getResourceString("OpenIncludeAction.title")); //$NON-NLS-1$
|
||||
setDescription(MakeUIPlugin.getResourceString("OpenIncludeAction.description")); //$NON-NLS-1$
|
||||
setToolTipText(MakeUIPlugin.getResourceString("OpenIncludeAction.tooltip")); //$NON-NLS-1$
|
||||
fSelectionProvider= provider;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.action.IAction#run()
|
||||
*/
|
||||
public void run() {
|
||||
IInclude[] includes= getIncludeDirective(fSelectionProvider.getSelection());
|
||||
if (includes != null) {
|
||||
for (int i = 0; i < includes.length; ++i) {
|
||||
IDirective[] directives = includes[i].getDirectives();
|
||||
for (int j = 0; j < directives.length; ++j) {
|
||||
try {
|
||||
openInEditor(directives[j]);
|
||||
} catch (PartInitException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEditorPart openInEditor(IDirective directive) throws PartInitException {
|
||||
String filename = directive.getFileName();
|
||||
IPath path = new Path(filename);
|
||||
IFile file = MakeUIPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||
if (file != null) {
|
||||
IWorkbenchPage p = MakeUIPlugin.getActivePage();
|
||||
if (p != null) {
|
||||
IEditorPart editorPart = IDE.openEditor(p, file, true);
|
||||
if (editorPart instanceof MakefileEditor) {
|
||||
((MakefileEditor)editorPart).setSelection(directive, true);
|
||||
}
|
||||
return editorPart;
|
||||
}
|
||||
} else {
|
||||
// External file
|
||||
IStorage storage = new FileStorage(path);
|
||||
IStorageEditorInput input = new ExternalEditorInput(storage);
|
||||
IWorkbenchPage p = MakeUIPlugin.getActivePage();
|
||||
if (p != null) {
|
||||
String editorID = "org.eclipse.cdt.make.editor"; //$NON-NLS-1$
|
||||
IEditorPart editorPart = IDE.openEditor(p, input, editorID, true);
|
||||
if (editorPart instanceof MakefileEditor) {
|
||||
((MakefileEditor)editorPart).setSelection(directive, true);
|
||||
}
|
||||
return editorPart;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
IInclude[] getIncludeDirective(ISelection sel) {
|
||||
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
|
||||
List list= ((IStructuredSelection)sel).toList();
|
||||
if (list.size() > 0) {
|
||||
List includes = new ArrayList(list.size());
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
Object element= list.get(i);
|
||||
if (element instanceof IInclude) {
|
||||
includes.add(element);
|
||||
}
|
||||
}
|
||||
return (IInclude[]) includes.toArray(new IInclude[includes.size()]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canActionBeAdded(ISelection selection) {
|
||||
return getIncludeDirective(selection) != null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue