changeset 6868:09e61c65f172

RT-35401 [Menu, Mac] Dynamic menus that open stages cause focus to be assigned to the parent stage Reviewed by: anthony
author Martin Sladecek <martin.sladecek@oracle.com>
date Fri, 25 Apr 2014 07:53:11 +0200
parents 638fa2b3848b
children bbc5c4272696
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Thu Apr 24 17:28:23 2014 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Fri Apr 25 07:53:11 2014 +0200
@@ -27,10 +27,8 @@
 
 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
 import javafx.beans.InvalidationListener;
-import javafx.beans.Observable;
 import javafx.beans.property.ReadOnlyProperty;
 import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
 import javafx.beans.value.WeakChangeListener;
 import javafx.collections.ListChangeListener;
 import javafx.collections.MapChangeListener;
@@ -66,12 +64,9 @@
 import com.sun.javafx.scene.SceneHelper;
 import com.sun.javafx.scene.control.GlobalMenuAdapter;
 import com.sun.javafx.scene.control.behavior.BehaviorBase;
-import com.sun.javafx.scene.traversal.Direction;
-import com.sun.javafx.scene.traversal.TraversalEngine;
 import com.sun.javafx.scene.traversal.TraverseListener;
 import com.sun.javafx.stage.StageHelper;
 import com.sun.javafx.tk.Toolkit;
-import static com.sun.javafx.scene.traversal.Direction.DOWN;
 import javafx.stage.Window;
 
 
@@ -463,8 +458,24 @@
         }
         unSelectMenus();
     };
-    
+
+    private ListChangeListener<MenuItem> menuItemListener = (c) -> {
+        while (c.next()) {
+            for (MenuItem mi : c.getAddedSubList()) {
+                mi.addEventHandler(ActionEvent.ACTION, menuActionEventHandler);
+            }
+            for (MenuItem mi: c.getRemoved()) {
+                mi.removeEventHandler(ActionEvent.ACTION, menuActionEventHandler);
+            }
+        }
+    };
+
     private void updateActionListeners(Menu m, boolean add) {
+        if (add) {
+            m.getItems().addListener(menuItemListener);
+        } else {
+            m.getItems().removeListener(menuItemListener);
+        }
         for (MenuItem mi : m.getItems()) {
             if (mi instanceof Menu) {
                 updateActionListeners((Menu)mi, add);