From 369b23a7d2176903c01dfda937c765feb85d6c44 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 28 Sep 2017 12:57:56 +0200 Subject: [PATCH] Refactored function to get status of menus in MacOSX --- app/src/processing/app/Base.java | 2 +- app/src/processing/app/Editor.java | 6 +++--- arduino-core/src/processing/app/helpers/OSUtils.java | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 3f3158c98..7e9827c96 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -971,7 +971,7 @@ public class Base { // Save out the current prefs state PreferencesData.save(); - if (!OSUtils.isMacOS() || System.getProperty("apple.laf.useScreenMenuBar") == "false") { + if (!OSUtils.hasMacOSStyleMenus()) { // If this was fired from the menu or an AppleEvent (the Finder), // then Mac OS X will send the terminate signal itself. System.exit(0); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index deb6870a9..79c6174bb 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -619,7 +619,7 @@ public class Editor extends JFrame implements RunnerListener { fileMenu.add(item); // macosx already has its own preferences and quit menu - if (!OSUtils.isMacOS() || System.getProperty("apple.laf.useScreenMenuBar") == "false") { + if (!OSUtils.hasMacOSStyleMenus()) { fileMenu.addSeparator(); item = newJMenuItem(tr("Preferences"), ','); @@ -1252,7 +1252,7 @@ public class Editor extends JFrame implements RunnerListener { menu.add(item); // macosx already has its own about menu - if (!OSUtils.isMacOS() || System.getProperty("apple.laf.useScreenMenuBar") == "false") { + if (!OSUtils.hasMacOSStyleMenus()) { menu.addSeparator(); item = new JMenuItem(tr("About Arduino")); item.addActionListener(new ActionListener() { @@ -1812,7 +1812,7 @@ public class Editor extends JFrame implements RunnerListener { String prompt = I18n.format(tr("Save changes to \"{0}\"? "), sketch.getName()); - if (!OSUtils.isMacOS() || System.getProperty("apple.laf.useScreenMenuBar") == "false") { + if (!OSUtils.hasMacOSStyleMenus()) { int result = JOptionPane.showConfirmDialog(this, prompt, tr("Close"), JOptionPane.YES_NO_CANCEL_OPTION, diff --git a/arduino-core/src/processing/app/helpers/OSUtils.java b/arduino-core/src/processing/app/helpers/OSUtils.java index 80a36b9e9..50719af31 100644 --- a/arduino-core/src/processing/app/helpers/OSUtils.java +++ b/arduino-core/src/processing/app/helpers/OSUtils.java @@ -26,4 +26,7 @@ public class OSUtils { return System.getProperty("os.name").contains("Mac"); } + static public boolean hasMacOSStyleMenus() { + return OSUtils.isMacOS() && System.getProperty("apple.laf.useScreenMenuBar").equals("true"); + } }