Skip to content

Commit edaa2cb

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 b7728be commit edaa2cb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

app/src/processing/app/Base.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import processing.app.debug.TargetPackage;
4949
import processing.app.debug.TargetPlatform;
5050
import processing.app.helpers.*;
51+
import processing.app.helpers.OSUtils;
5152
import processing.app.helpers.filefilters.OnlyDirs;
5253
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
5354
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
@@ -935,7 +936,10 @@ public boolean handleClose(Editor editor) {
935936
storeSketches();
936937

937938
// This will store the sketch count as zero
939+
editor.setVisible(false);
940+
//editor.dispose();
938941
editors.remove(editor);
942+
939943
try {
940944
Editor.serialMonitor.close();
941945
} catch (Exception e) {
@@ -946,9 +950,10 @@ public boolean handleClose(Editor editor) {
946950
// Save out the current prefs state
947951
PreferencesData.save();
948952

949-
// Since this wasn't an actual Quit event, call System.exit()
950-
System.exit(0);
951-
953+
// Since this wasn't an actual Quit event, call System.exit() (not on OSX)
954+
if (!OSUtils.isMacOS()) {
955+
System.exit(0);
956+
}
952957
} else {
953958
// More than one editor window open,
954959
// proceed with closing the current window.

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)