Skip to content

Commit 36da22c

Browse files
committed
[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)
1 parent c1d9c58 commit 36da22c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/processing/app/Base.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import processing.app.debug.TargetPackage;
5050
import processing.app.debug.TargetPlatform;
5151
import processing.app.helpers.*;
52+
import processing.app.helpers.OSUtils;
5253
import processing.app.helpers.filefilters.OnlyDirs;
5354
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
5455
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
@@ -931,15 +932,14 @@ public boolean handleClose(Editor editor) {
931932
}
932933

933934
if (editors.size() == 1) {
934-
935+
editor.setVisible(false);
936+
editors.remove(editor);
935937
handleQuit();
936-
937938
} else {
938939
// More than one editor window open,
939940
// proceed with closing the current window.
940941
editor.setVisible(false);
941942
editor.dispose();
942-
943943
editors.remove(editor);
944944
}
945945
return true;
@@ -974,7 +974,7 @@ public boolean handleQuit() {
974974
// Save out the current prefs state
975975
PreferencesData.save();
976976

977-
if (!OSUtils.hasMacOSStyleMenus()) {
977+
if (!OSUtils.isMacOS()) {
978978
// If this was fired from the menu or an AppleEvent (the Finder),
979979
// then Mac OS X will send the terminate signal itself.
980980
System.exit(0);

app/src/processing/app/macosx/ThinkDifferent.java

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
package processing.app.macosx;
2424

2525
import com.apple.eawt.*;
26+
import com.apple.eawt.AppEvent.AppReOpenedEvent;
27+
2628
import processing.app.Base;
2729
import processing.app.Editor;
2830

@@ -45,6 +47,20 @@ public class ThinkDifferent {
4547

4648
static public void init() {
4749
Application application = Application.getApplication();
50+
51+
application.addAppEventListener(new AppReOpenedListener() {
52+
@Override
53+
public void appReOpened(AppReOpenedEvent aroe) {
54+
try {
55+
if (Base.INSTANCE.getEditors().size() == 0) {
56+
Base.INSTANCE.handleNew();
57+
}
58+
} catch (Exception e) {
59+
// TODO Auto-generated catch block
60+
e.printStackTrace();
61+
}
62+
}
63+
});
4864
application.setAboutHandler(new AboutHandler() {
4965
@Override
5066
public void handleAbout(AppEvent.AboutEvent aboutEvent) {

0 commit comments

Comments
 (0)