Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-08-21 13:47:11 +0000
committerMatthias Becker2018-08-23 06:50:23 +0000
commite352f348c21c994af3ec8aeea61baa2466d79984 (patch)
treea5b5eee896b537f3641bafc512a6ac2f53398151
parent7d83a92eaecf2aa01c5ae4c4cf60c1a5a6c1dacc (diff)
downloadeclipse.platform.swt-e352f348c21c994af3ec8aeea61baa2466d79984.tar.gz
eclipse.platform.swt-e352f348c21c994af3ec8aeea61baa2466d79984.tar.xz
eclipse.platform.swt-e352f348c21c994af3ec8aeea61baa2466d79984.zip
Bug 538003: cocoa: Fix context menu not closing on left mouse click
Commit e385fcb changed the way context menus are created. This caused context menus to appear twice (once on right click and a second time on left click). Change-Id: I830d1f1f0c353162b7e7daea868b3a152e4fb0d1 Signed-off-by: Matthias Becker <ma.becker@sap.com> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java38
1 files changed, 24 insertions, 14 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
index 31eccc88fb..2f1aae9037 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
@@ -2506,18 +2506,34 @@ long /*int*/ menuForEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ theEv
NSEvent nsEvent = new NSEvent(theEvent);
event.detail = nsEvent.buttonNumber() > 0 ? SWT.MENU_MOUSE : SWT.MENU_KEYBOARD;
- int count = 0;
+ int initialNumberOfPopups = 0;
+ boolean menuAlreadyHandledByDisplay = false;
if (display.popups != null) {
- while (count < display.popups.length && display.popups[count] != null) {
- count++;
+ while (initialNumberOfPopups < display.popups.length && display.popups[initialNumberOfPopups] != null) {
+ if (display.popups[initialNumberOfPopups] == menu) {
+ menuAlreadyHandledByDisplay = true;
+ }
+ initialNumberOfPopups++;
}
}
sendEvent(SWT.MenuDetect, event);
- //widget could be disposed at this point
+ // widget could be disposed at this point
if (isDisposed ()) return 0;
Menu menu = getMenu ();
- if (event.doit && menu != null && !menu.isDisposed ()) {
+ // Count popups again: if it's different, the last one should be our menu.
+ int newNumberOfPopups = 0;
+ if (display.popups != null) {
+ while (newNumberOfPopups < display.popups.length && display.popups[newNumberOfPopups] != null) {
+ newNumberOfPopups++;
+ }
+ }
+ if (event.doit && menu != null && !menu.isDisposed () && !menuAlreadyHandledByDisplay) {
+ // If our new menu is in popups, we need to remove it, otherwise it may appear twice: once
+ // from being handled by Cocoa (return of the id), and once from the deferred popup.
+ if (newNumberOfPopups != initialNumberOfPopups && newNumberOfPopups > 0 && display.popups[newNumberOfPopups - 1] == menu) {
+ display.popups[newNumberOfPopups - 1] = null;
+ }
if (x != event.x || y != event.y) {
menu.setLocation (event.x, event.y);
}
@@ -2526,15 +2542,9 @@ long /*int*/ menuForEvent (long /*int*/ id, long /*int*/ sel, long /*int*/ theEv
// There is either no popup menu set for the Control or event.doit = false.
// If a popup was triggered in the MenuDetect listener, return it.
- int count2 = 0;
- if (display.popups != null) {
- while (count2 < display.popups.length && display.popups[count2] != null) {
- count2++;
- }
- }
- if (count2 != count && count2 > 0) {
- Menu menu1 = display.popups[count2 - 1];
- display.popups[count2 - 1] = null;
+ if (newNumberOfPopups != initialNumberOfPopups && newNumberOfPopups > 0) {
+ Menu menu1 = display.popups[newNumberOfPopups - 1];
+ display.popups[newNumberOfPopups - 1] = null;
return menu1.nsMenu.id;
}
if (!event.doit) return 0;

Back to the top