Skip to content

[macOS] Modify behaviour when last editor gets closed #8023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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;
Expand Down Expand Up @@ -931,15 +932,14 @@ public boolean handleClose(Editor editor) {
}

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;
Expand Down Expand Up @@ -974,7 +974,7 @@ public boolean handleQuit() {
// 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);
Expand Down
16 changes: 16 additions & 0 deletions app/src/processing/app/macosx/ThinkDifferent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better error handling here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely (no idea about how to handle it anyway)

}
}
});
application.setAboutHandler(new AboutHandler() {
@Override
public void handleAbout(AppEvent.AboutEvent aboutEvent) {
Expand Down