Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2012-04-04 09:47:12 +0000
committerMarkus Keller2012-04-04 09:47:12 +0000
commitdd9c5941944a935a022f5373f65ff5f306f79e2d (patch)
tree641aa6f5b2fa25e577861ae7eeb59ae1440340b5
parented55274cf0c3ed1f0ed010b28deab7a94ec025ae (diff)
downloadeclipse.platform.ui-dd9c5941944a935a022f5373f65ff5f306f79e2d.tar.gz
eclipse.platform.ui-dd9c5941944a935a022f5373f65ff5f306f79e2d.tar.xz
eclipse.platform.ui-dd9c5941944a935a022f5373f65ff5f306f79e2d.zip
Bug 374320: ContextMenuHandler should use new MenuDetect API so controls
can position context menu
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/ContextMenuHandler.java52
1 files changed, 31 insertions, 21 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/ContextMenuHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/ContextMenuHandler.java
index 86b57566a77..d43987ef7cf 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/ContextMenuHandler.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/ContextMenuHandler.java
@@ -1,13 +1,3 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
package org.eclipse.ui.internal.handlers;
import org.eclipse.core.commands.AbstractHandler;
@@ -24,30 +14,50 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class ContextMenuHandler extends AbstractHandler {
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
+ /**
+ * @throws ExecutionException
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent exEvent) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(exEvent);
Display display = shell == null ? Display.getCurrent() : shell.getDisplay();
Control focusControl = display.getFocusControl();
if (focusControl != null) {
+ Point pt = display.getCursorLocation();
+ Event event = new Event();
+ event.x = pt.x;
+ event.y = pt.y;
+ event.detail = SWT.MENU_KEYBOARD;
+ focusControl.notifyListeners(SWT.MenuDetect, event);
+ if (focusControl.isDisposed())
+ return null;
+ if (!event.doit)
+ return null;
Menu menu = focusControl.getMenu();
- if (menu != null) {
+
+ if (menu != null && !menu.isDisposed()) {
+ if (event.x != pt.x || event.y != pt.y) {
+ menu.setLocation(event.x, event.y);
+ }
menu.setVisible(true);
+
} else {
Point size = focusControl.getSize();
- Point center = focusControl.toDisplay(Geometry.divide(size, 2));
-
Point location = focusControl.toDisplay(0, 0);
Event mouseEvent = new Event();
mouseEvent.widget = focusControl;
- mouseEvent.x = center.x;
- mouseEvent.y = center.y;
- Point cursorLoc = display.getCursorLocation();
- if (cursorLoc.x < location.x || location.x + size.x <= cursorLoc.x
- || cursorLoc.y < location.y || location.y + size.y <= cursorLoc.y) {
+ if (event.x < location.x || location.x + size.x <= event.x || event.y < location.y
+ || location.y + size.y <= event.y) {
+ Point center = focusControl.toDisplay(Geometry.divide(size, 2));
+ mouseEvent.x = center.x;
+ mouseEvent.y = center.y;
mouseEvent.type = SWT.MouseMove;
display.post(mouseEvent);
+ } else {
+ mouseEvent.x = event.x;
+ mouseEvent.y = event.y;
}
mouseEvent.button = 3;
@@ -60,4 +70,4 @@ public class ContextMenuHandler extends AbstractHandler {
}
return null;
}
-}
+} \ No newline at end of file

Back to the top