changeset 9221:f7860462626b

8087709: [Mac] Can set only second menu as system, when trying to set two menus at once Reviewed-By: ddhill, kcr, leifs
author Morris Meyer <morris.meyer@oracle.com>
date Fri, 14 Aug 2015 14:40:44 -0400
parents 7e6d5c16ff4a
children d0fd05a0a79e
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java modules/controls/src/main/java/javafx/scene/control/MenuBar.java modules/graphics/src/main/native-glass/mac/GlassMenu.m
diffstat 3 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Tue Aug 11 10:55:58 2015 +0300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Fri Aug 14 14:40:44 2015 -0400
@@ -528,9 +528,9 @@
             // remove action listeners 
             updateActionListeners(m, false);
         }
-        for(Node n : container.getChildren()) {
-            //Stop observing menu's showing & disable property for changes.
-            //Need to unbind before clearing container's children.
+        for (Node n : container.getChildren()) {
+            // Stop observing menu's showing & disable property for changes.
+            // Need to unbind before clearing container's children.
             MenuBarButton menuButton = (MenuBarButton)n;
             menuButton.hide();
             menuButton.menu.showingProperty().removeListener(menuButton.menuListener);
@@ -569,6 +569,11 @@
                                         currentMenuBarStage = null;
                                         setSystemMenu(stage);
                                     }
+                                } else {
+                                    if (curMBSkin != null && curMBSkin.getSkinnable() != null &&
+                                            curMBSkin.getSkinnable().isUseSystemMenuBar()) {
+                                        curMBSkin.getSkinnable().setUseSystemMenuBar(false);
+                                    }
                                 }
                             }
                         }
@@ -580,12 +585,8 @@
                                     if (systemMenuMap == null) {
                                         initSystemMenuBar();
                                     }
-                                    if (wrappedMenus == null) {
-                                        wrappedMenus = new ArrayList<>();
-                                        systemMenuMap.put(stage, new WeakReference<>(this));
-                                    } else {
-                                        wrappedMenus.clear();
-                                    }
+                                    wrappedMenus = new ArrayList<>();
+                                    systemMenuMap.put(stage, new WeakReference<>(this));
                                     for (Menu menu : getSkinnable().getMenus()) {
                                         wrappedMenus.add(GlobalMenuAdapter.adapt(menu));
                                     }
--- a/modules/controls/src/main/java/javafx/scene/control/MenuBar.java	Tue Aug 11 10:55:58 2015 +0300
+++ b/modules/controls/src/main/java/javafx/scene/control/MenuBar.java	Fri Aug 14 14:40:44 2015 -0400
@@ -33,6 +33,7 @@
 
 import javafx.beans.DefaultProperty;
 import javafx.beans.property.BooleanProperty;
+import javafx.beans.value.ObservableValue;
 import javafx.beans.value.WritableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
@@ -130,7 +131,13 @@
      *
      * This should not be set on more than one MenuBar instance per
      * Stage. If this property is set to true on more than one
-     * MenuBar in the same Stage, then the behavior is undefined.
+     * MenuBar in the same Stage, then the last menu set is allowed
+     * to modify the system menu bar, and if there is an existing installed
+     * system menu it is unset and removed from the system menu bar.
+     *
+     * Note that trying to uni-directionally bind to this property
+     * will throw a RuntimeException.  Please use
+     * bi-directional binding to this property instead.
      *
      * @since JavaFX 2.1
      */
@@ -152,10 +159,19 @@
                 public String getName() {
                     return "useSystemMenuBar";
                 }
+                
+                @Override
+                public void bind(final ObservableValue<? extends Boolean> rawObservable) {
+                    throw new RuntimeException(BIND_MSG);
+                }
+
             };
         }
         return useSystemMenuBar;
     }
+    private String BIND_MSG =
+        "cannot uni-directionally bind to the system menu bar - use bindBidrectional instead";
+                                               
     private BooleanProperty useSystemMenuBar;
     public final void setUseSystemMenuBar(boolean value) {
         useSystemMenuBarProperty().setValue(value);
--- a/modules/graphics/src/main/native-glass/mac/GlassMenu.m	Tue Aug 11 10:55:58 2015 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassMenu.m	Fri Aug 14 14:40:44 2015 -0400
@@ -67,7 +67,7 @@
 
 - (void)dealloc
 {
-    NSLog(@"GlassMenubar dealloc: %p", self);
+    LOG("GlassMenubar dealloc: %p", self);
     [super dealloc];
 }