Bug 346390 - Ctrl+A (select all) is not applied to the (right) focused area
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 8ed3a2f..a32e9a0 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
@@ -14,6 +14,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import org.eclipse.core.commands.Command;
 import org.eclipse.core.commands.ExecutionEvent;
@@ -80,10 +81,18 @@
 		@Override
 		public Object compute(IEclipseContext context) {
 
-			List<HandlerActivation> handlerActivations = (List<HandlerActivation>) context
-					.get(LEGACY_H_ID + commandId);
+			HashSet<HandlerActivation> activationSet = new HashSet<HandlerActivation>();
+			IEclipseContext current = context;
+			while (current != null) {
+				List<HandlerActivation> handlerActivations = (List<HandlerActivation>) current
+						.getLocal(LEGACY_H_ID + commandId);
+				if (handlerActivations != null) {
+					activationSet.addAll(handlerActivations);
+				}
+				current = current.getParent();
+			}
 
-			if (handlerActivations == null) {
+			if (activationSet.isEmpty()) {
 				return null;
 			}
 
@@ -91,7 +100,7 @@
 
 			ExpressionContext legacyEvalContext = new ExpressionContext(context);
 
-			for (HandlerActivation handlerActivation : handlerActivations) {
+			for (HandlerActivation handlerActivation : activationSet) {
 				if (!handlerActivation.participating)
 					continue;
 				if (handlerActivation.evaluate(legacyEvalContext)) {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
index 697a0ad..f0300de 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
@@ -16,7 +16,16 @@
 import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionInfo;
+import org.eclipse.core.expressions.IEvaluationContext;
 import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
 import org.eclipse.jface.dialogs.IDialogSettings;
@@ -43,10 +52,13 @@
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWorkbenchCommandConstants;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
 import org.eclipse.ui.internal.WorkbenchImages;
 import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.swt.IFocusService;
 
 public class SearchField {
 
@@ -81,6 +93,8 @@
 		GridDataFactory.fillDefaults().hint(130, SWT.DEFAULT).applyTo(text);
 		text.setMessage(QuickAccessMessages.QuickAccess_EnterSearch);
 
+		hookUpSelectAll();
+
 		final CommandProvider commandProvider = new CommandProvider();
 		QuickAccessProvider[] providers = new QuickAccessProvider[] { new PreviousPicksProvider(),
 				new EditorProvider(), new ViewProvider(application, window),
@@ -164,6 +178,52 @@
 		});
 	}
 
+	private void hookUpSelectAll() {
+		final IEclipseContext windowContext = window.getContext();
+		IFocusService focus = windowContext.get(IFocusService.class);
+		focus.addFocusTracker(text, SearchField.class.getName());
+
+		Expression focusExpr = new Expression() {
+			@Override
+			public void collectExpressionInfo(ExpressionInfo info) {
+				info.addVariableNameAccess(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME);
+			}
+
+			@Override
+			public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
+				return EvaluationResult.valueOf(SearchField.class.getName().equals(
+						context.getVariable(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME)));
+			}
+		};
+
+		IHandlerService whService = windowContext.get(IHandlerService.class);
+		whService.activateHandler(IWorkbenchCommandConstants.EDIT_SELECT_ALL,
+				new AbstractHandler() {
+					public Object execute(ExecutionEvent event) throws ExecutionException {
+						text.selectAll();
+						return null;
+					}
+				}, focusExpr);
+		whService.activateHandler(IWorkbenchCommandConstants.EDIT_CUT, new AbstractHandler() {
+			public Object execute(ExecutionEvent event) throws ExecutionException {
+				text.cut();
+				return null;
+			}
+		}, focusExpr);
+		whService.activateHandler(IWorkbenchCommandConstants.EDIT_COPY, new AbstractHandler() {
+			public Object execute(ExecutionEvent event) throws ExecutionException {
+				text.copy();
+				return null;
+			}
+		}, focusExpr);
+		whService.activateHandler(IWorkbenchCommandConstants.EDIT_PASTE, new AbstractHandler() {
+			public Object execute(ExecutionEvent event) throws ExecutionException {
+				text.paste();
+				return null;
+			}
+		}, focusExpr);
+	}
+
 	/**
 	 * This method was copy/pasted from JFace.
 	 *