Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2012-08-29 17:40:22 +0000
committerPaul Webster2012-08-29 17:41:55 +0000
commit3c7f1f384d4de226f52410c7d0c88d72a5498be2 (patch)
tree7bec135972ad5bcd1ce37f888a1e918d5f636d75
parentc9d2cf8499a982c88cafcf6754daa554c74cee93 (diff)
downloadeclipse.platform.ui-3c7f1f384d4de226f52410c7d0c88d72a5498be2.tar.gz
eclipse.platform.ui-3c7f1f384d4de226f52410c7d0c88d72a5498be2.tar.xz
eclipse.platform.ui-3c7f1f384d4de226f52410c7d0c88d72a5498be2.zip
Bug 384545 - Wrong selection used to find the handler
Fix uses 2 things: 1) Look to the IEvaluationContext default variable and create one in the ExpressionContext, which doesn't have a default variable that can be set 2) Use the passed in context to request and evaluate the HandlerSelectionFunction.
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java28
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java4
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java8
3 files changed, 30 insertions, 10 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
index 33699124254..80632256294 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
@@ -60,6 +60,7 @@ import org.eclipse.ui.internal.e4.compatibility.E4Util;
import org.eclipse.ui.internal.expressions.AndExpression;
import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+import org.eclipse.ui.internal.services.EvaluationService;
import org.eclipse.ui.services.IEvaluationService;
import org.eclipse.ui.services.ISourceProviderService;
@@ -138,12 +139,7 @@ public class LegacyHandlerService implements IHandlerService {
return bestActivation.proxy;
}
- // "super call"
- IEclipseContext parent = context.getParent();
- if (parent == null) {
- return null;
- }
- return parent.get(HandlerServiceImpl.H_ID + commandId);
+ return null;
}
}
@@ -537,6 +533,7 @@ public class LegacyHandlerService implements IHandlerService {
NotEnabledException, NotHandledException {
IEclipseContext staticContext = null;
boolean disposeContext = false;
+ Object defaultVar = null;
if (context instanceof ExpressionContext) {
// create a child context so that the primary context doesn't get
// populated by parameters by the EHS
@@ -548,8 +545,21 @@ public class LegacyHandlerService implements IHandlerService {
staticContext.set(Event.class, event);
}
staticContext.set(IEvaluationContext.class, context);
+ defaultVar = context.getDefaultVariable();
}
- EHandlerService hs = eclipseContext.get(EHandlerService.class);
+ IEclipseContext lookupContext = eclipseContext;
+ IEvaluationContext contextPtr = context;
+ while (contextPtr != null) {
+ if (contextPtr instanceof ExpressionContext) {
+ lookupContext = ((ExpressionContext) contextPtr).eclipseContext;
+ if (defaultVar != null && defaultVar != IEvaluationContext.UNDEFINED_VARIABLE) {
+ lookupContext.set(EvaluationService.DEFAULT_VAR, defaultVar);
+ }
+ break;
+ }
+ contextPtr = contextPtr.getParent();
+ }
+ EHandlerService hs = lookupContext.get(EHandlerService.class);
try {
final Object rc = hs.executeHandler(command, staticContext);
if (staticContext.get(HandlerServiceImpl.NOT_HANDLED) == Boolean.TRUE) {
@@ -604,8 +614,8 @@ public class LegacyHandlerService implements IHandlerService {
*/
public IEvaluationContext createContextSnapshot(boolean includeSelection) {
IEvaluationContext tmpContext = getCurrentState();
- IEvaluationContext context = new EvaluationContext(null,
- IEvaluationContext.UNDEFINED_VARIABLE);
+ IEclipseContext snapshotContext = eclipseContext.createChild("snapshotContext"); //$NON-NLS-1$
+ IEvaluationContext context = new ExpressionContext(snapshotContext);
if (includeSelection) {
for (String variable : SELECTION_VARIABLES) {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java
index 2ab99ae8bab..289bde5dbd7 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java
@@ -18,6 +18,7 @@ import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
@@ -109,6 +110,9 @@ public class CommandProvider extends QuickAccessProvider {
protected void doReset() {
idToElement = null;
+ if (currentSnapshot instanceof ExpressionContext) {
+ ((ExpressionContext) currentSnapshot).eclipseContext.dispose();
+ }
currentSnapshot = null;
}
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
index 033f492b8dc..c225ace39aa 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
@@ -46,6 +46,7 @@ import org.eclipse.ui.services.IEvaluationService;
*
*/
public final class EvaluationService implements IEvaluationService {
+ public static final String DEFAULT_VAR = "org.eclipse.ui.internal.services.EvaluationService.default_var"; //$NON-NLS-1$
private static final String RE_EVAL = "org.eclipse.ui.internal.services.EvaluationService.evaluate"; //$NON-NLS-1$
private boolean evaluate = false;
private ExpressionContext legacyContext;
@@ -85,7 +86,12 @@ public final class EvaluationService implements IEvaluationService {
ExpressionContext.defaultVariableConverter = new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
- Object defaultVariable = context.getActive(IServiceConstants.ACTIVE_SELECTION);
+ Object defaultVariable = context.getLocal(DEFAULT_VAR);
+ if (defaultVariable != null
+ && defaultVariable != IEvaluationContext.UNDEFINED_VARIABLE) {
+ return defaultVariable;
+ }
+ defaultVariable = context.getActive(IServiceConstants.ACTIVE_SELECTION);
if (defaultVariable instanceof IStructuredSelection) {
final IStructuredSelection selection = (IStructuredSelection) defaultVariable;
return selection.toList();

Back to the top