Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2004-05-06 19:08:30 +0000
committerDarin Wright2004-05-06 19:08:30 +0000
commited4f031fd6704b1070f39eaafb54c7510b622a58 (patch)
tree83ca4d65d4621da74011d3fe4a641769ae642b49 /org.eclipse.debug.ui
parente95e9a15e5e4075ed3b8f7c7d2f68515f85d4cae (diff)
downloadeclipse.platform.debug-ed4f031fd6704b1070f39eaafb54c7510b622a58.tar.gz
eclipse.platform.debug-ed4f031fd6704b1070f39eaafb54c7510b622a58.tar.xz
eclipse.platform.debug-ed4f031fd6704b1070f39eaafb54c7510b622a58.zip
Bug 53722 - Run As... menu disabled if selection is empty
Diffstat (limited to 'org.eclipse.debug.ui')
-rw-r--r--org.eclipse.debug.ui/schema/launchShortcuts.exsd3
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java21
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java28
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java2
4 files changed, 48 insertions, 6 deletions
diff --git a/org.eclipse.debug.ui/schema/launchShortcuts.exsd b/org.eclipse.debug.ui/schema/launchShortcuts.exsd
index 7667ebda9..e5527b87f 100644
--- a/org.eclipse.debug.ui/schema/launchShortcuts.exsd
+++ b/org.eclipse.debug.ui/schema/launchShortcuts.exsd
@@ -10,7 +10,7 @@
appears in the run and/or debug cascade menus to launch the workbench selection or active editor.
</documentation>
</annotation>
-
+
<include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.mxsd"/>
<element name="extension">
@@ -52,6 +52,7 @@ appears in the run and/or debug cascade menus to launch the workbench selection
<sequence>
<element ref="perspective" minOccurs="0" maxOccurs="unbounded"/>
<element ref="contextualLaunch" minOccurs="0" maxOccurs="1"/>
+ <element ref="enablement" minOccurs="0" maxOccurs="1"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java
index 533bdb46e..6a282a806 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java
@@ -11,6 +11,12 @@
package org.eclipse.debug.internal.ui.actions;
+import java.util.List;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
import org.eclipse.jface.action.Action;
@@ -76,7 +82,20 @@ public class LaunchShortcutAction extends Action {
if (page != null) {
ISelection selection = page.getSelection();
if (selection instanceof IStructuredSelection) {
- enabled = !((IStructuredSelection)selection).isEmpty();
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ try {
+ // check enablement logic, if any
+ Expression expression = fShortcut.getShortcutEnablementExpression();
+ if (expression == null) {
+ enabled = !structuredSelection.isEmpty();
+ } else {
+ List list = structuredSelection.toList();
+ IEvaluationContext context = new EvaluationContext(null, list);
+ context.addVariable("selection", list); //$NON-NLS-1$
+ enabled = fShortcut.evalEnablementExpression(context, expression);
+ }
+ } catch (CoreException e) {
+ }
} else {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java
index 124460d8e..a063856a7 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java
@@ -49,6 +49,7 @@ public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribu
private Set fModes = null;
private IConfigurationElement fContextualLaunchConfigurationElement = null;
private Expression fContextualLaunchExpr = null;
+ private Expression fStandardLaunchExpr = null;
/**
* The configuration element defining this tab.
@@ -159,7 +160,7 @@ public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribu
* Evaluate the given expression within the given context and return
* the result. Returns <code>true</code> iff result is either TRUE or NOT_LOADED.
* This allows optimistic inclusion of shortcuts before plugins are loaded.
- * Returns <code>false</code> if exp is <code>null</code>.
+ * Returns <code>true</code> if exp is <code>null</code>.
*
* @param exp the enablement expression to evaluate or <code>null</code>
* @param context the context of the evaluation. Usually, the
@@ -167,8 +168,8 @@ public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribu
* @return the result of evaluating the expression
* @throws CoreException
*/
- public boolean evalContextualLaunchEnablementExpression(IEvaluationContext context, Expression exp) throws CoreException {
- return (exp != null) ? ((exp.evaluate(context)) != EvaluationResult.FALSE) : false;
+ public boolean evalEnablementExpression(IEvaluationContext context, Expression exp) throws CoreException {
+ return (exp != null) ? ((exp.evaluate(context)) != EvaluationResult.FALSE) : true;
}
/**
@@ -200,6 +201,27 @@ public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribu
}
/**
+ * Returns an expression that represents the enablement logic for the
+ * launch shortcut description or <code>null</code> if none.
+ * @return an evaluatable expression or <code>null</code>
+ * @throws CoreException if the configuration element can't be
+ * converted. Reasons include: (a) no handler is available to
+ * cope with a certain configuration element or (b) the XML
+ * expression tree is malformed.
+ */
+ public Expression getShortcutEnablementExpression() throws CoreException {
+ // all of this stuff is optional, so...tedius testing is required
+ if (fStandardLaunchExpr == null) {
+ IConfigurationElement[] elements = getConfigurationElement().getChildren(ExpressionTagNames.ENABLEMENT);
+ IConfigurationElement enablement = elements.length > 0 ? elements[0] : null;
+ if (enablement != null) {
+ fStandardLaunchExpr= ExpressionConverter.getDefault().perform(enablement);
+ }
+ }
+ return fStandardLaunchExpr;
+ }
+
+ /**
* Returns the id of this shortcut
*
* @return the id of this shortcut, or <code>null</code> if not specified
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java
index dc447e0ac..e17ce38cd 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java
@@ -253,7 +253,7 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I
*/
private boolean isApplicable(LaunchShortcutExtension ext, IEvaluationContext context) throws CoreException {
Expression expr = ext.getContextualLaunchEnablementExpression();
- return ext.evalContextualLaunchEnablementExpression(context, expr);
+ return ext.evalEnablementExpression(context, expr);
}
/**

Back to the top