diff --git a/launch/org.eclipse.cdt.launch/plugin.properties b/launch/org.eclipse.cdt.launch/plugin.properties index de0ff3f8491..27020f95899 100644 --- a/launch/org.eclipse.cdt.launch/plugin.properties +++ b/launch/org.eclipse.cdt.launch/plugin.properties @@ -13,3 +13,8 @@ providerName=Eclipse.org LocalCDTLaunch.name= C/C++ Local CoreFileCDTLaunch.name= C/C++ Postmortem debugger + +CApplicationShortcut.label=C Local Application +ContextualRunJavaApplication.label=Run C Local Application +ContextualDebugJavaApplication.label=Debug C Local Application + diff --git a/launch/org.eclipse.cdt.launch/plugin.xml b/launch/org.eclipse.cdt.launch/plugin.xml index 197d1145948..06f78003658 100644 --- a/launch/org.eclipse.cdt.launch/plugin.xml +++ b/launch/org.eclipse.cdt.launch/plugin.xml @@ -73,11 +73,21 @@ + + + diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java index 4cdf80a20fd..33443777a65 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java @@ -7,6 +7,7 @@ import java.util.List; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; @@ -16,6 +17,7 @@ import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.core.boot.BootLoader; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -28,6 +30,7 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.ILaunchFilter; import org.eclipse.debug.ui.ILaunchShortcut; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; @@ -43,7 +46,7 @@ import org.eclipse.ui.dialogs.TwoPaneElementSelector; /** */ -public class CApplicationLaunchShortcut implements ILaunchShortcut { +public class CApplicationLaunchShortcut implements ILaunchShortcut, ILaunchFilter { /** * @see org.eclipse.debug.ui.ILaunchShortcut#launch(IEditorPart, String) @@ -288,8 +291,8 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut { if (element instanceof IBinary) { IBinary bin = (IBinary)element; StringBuffer name = new StringBuffer(); - name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); - name.append(" - "); + name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); //$NON-NLS-1$ //$NON-NLS-2$ + name.append(" - "); //$NON-NLS-1$ name.append(bin.getPath().toString()); return name.toString(); } @@ -385,4 +388,27 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut { } } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchFilter#testAttribute(org.eclipse.core.resources.IResource, java.lang.String, java.lang.String) + */ + public boolean testAttribute(IResource target, String name, String value) { + if ("ContextualLaunchActionFilter".equals(name)) { //$NON-NLS-1$ + return isExecutable(target); + } + return false; + } + + /** + * Look for executable. + * @return true if the target resource has a main method, + * false otherwise. + */ + private boolean isExecutable(IResource target) { + ICElement celement = null; + if (target instanceof IFile) { + celement = CoreModel.getDefault().create(target); + } + return (celement != null && celement instanceof IBinary); + } + }