From 36da22c08646d8ac62245ac0b2c05bb8e009ca06 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 21 Sep 2018 18:40:05 +0200 Subject: [PATCH] [macOS] Modify behaviour when last editor gets closed Don't call System.exit() but trust the ThinkDifferent handler Handle reopen only if no editor is visible Don't dispose last closing editor (so its toolbars are still in active state) --- app/src/processing/app/Base.java | 8 ++++---- .../processing/app/macosx/ThinkDifferent.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b118dbae2..62057e71b 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -49,6 +49,7 @@ import processing.app.debug.TargetBoard; import processing.app.debug.TargetPackage; import processing.app.debug.TargetPlatform; import processing.app.helpers.*; +import processing.app.helpers.OSUtils; import processing.app.helpers.filefilters.OnlyDirs; import processing.app.helpers.filefilters.OnlyFilesWithExtension; import processing.app.javax.swing.filechooser.FileNameExtensionFilter; @@ -931,15 +932,14 @@ public class Base { } if (editors.size() == 1) { - + editor.setVisible(false); + editors.remove(editor); handleQuit(); - } else { // More than one editor window open, // proceed with closing the current window. editor.setVisible(false); editor.dispose(); - editors.remove(editor); } return true; @@ -974,7 +974,7 @@ public class Base { // Save out the current prefs state PreferencesData.save(); - if (!OSUtils.hasMacOSStyleMenus()) { + if (!OSUtils.isMacOS()) { // 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/macosx/ThinkDifferent.java b/app/src/processing/app/macosx/ThinkDifferent.java index e946bdc0f..590196ace 100644 --- a/app/src/processing/app/macosx/ThinkDifferent.java +++ b/app/src/processing/app/macosx/ThinkDifferent.java @@ -23,6 +23,8 @@ package processing.app.macosx; import com.apple.eawt.*; +import com.apple.eawt.AppEvent.AppReOpenedEvent; + import processing.app.Base; import processing.app.Editor; @@ -45,6 +47,20 @@ public class ThinkDifferent { static public void init() { Application application = Application.getApplication(); + + application.addAppEventListener(new AppReOpenedListener() { + @Override + public void appReOpened(AppReOpenedEvent aroe) { + try { + if (Base.INSTANCE.getEditors().size() == 0) { + Base.INSTANCE.handleNew(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); application.setAboutHandler(new AboutHandler() { @Override public void handleAbout(AppEvent.AboutEvent aboutEvent) {