Bug 537491 - Photon@MacOS - Wrong context menu in Project/Package
Explorer due to outdated selection


Revert "Bug 538003: cocoa: Fix context menu not closing on left mouse
click"

This reverts commit e352f348c21c994af3ec8aeea61baa2466d79984.

Revert "Bug 378202 - Two-finger tap to simulate right-click results in
multiple click events"

This reverts commit e385fcbbec9141cfa9f82f55c4d03c505943c11e.

Change-Id: Ic8233cceb29931ba883c4dff2bd2bd09a9665227
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
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 2f1aae9..bc09cd7 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
@@ -2505,49 +2505,18 @@
 	event.y = y;
 	NSEvent nsEvent = new NSEvent(theEvent);
 	event.detail = nsEvent.buttonNumber() > 0 ? SWT.MENU_MOUSE : SWT.MENU_KEYBOARD;
-
-	int initialNumberOfPopups = 0;
-	boolean menuAlreadyHandledByDisplay = false;
-	if (display.popups != null) {
-		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
+	sendEvent (SWT.MenuDetect, event);
+	//widget could be disposed at this point
 	if (isDisposed ()) return 0;
+	if (!event.doit) return 0;
 	Menu menu = getMenu ();
-	// 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 (menu != null && !menu.isDisposed ()) {
 		if (x != event.x || y != event.y) {
 			menu.setLocation (event.x, event.y);
 		}
-		return menu.nsMenu.id;
+		menu.setVisible(true);
+		return 0;
 	}
-
-	// 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.
-	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;
 	return super.menuForEvent (id, sel, theEvent);
 }