From 7d0d46df458669a6ae90f1aa8b991675c70422d3 Mon Sep 17 00:00:00 2001 From: Jan Gassen Date: Wed, 6 Jul 2016 21:11:06 +0200 Subject: [PATCH] Create option to disable quitting the app on cmd-q --- .../java/de/codecentric/centerdevice/MenuToolkit.java | 4 ++++ .../centerdevice/glass/MacApplicationAdapter.java | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/codecentric/centerdevice/MenuToolkit.java b/src/main/java/de/codecentric/centerdevice/MenuToolkit.java index e34fce6..b5c0e32 100644 --- a/src/main/java/de/codecentric/centerdevice/MenuToolkit.java +++ b/src/main/java/de/codecentric/centerdevice/MenuToolkit.java @@ -194,6 +194,10 @@ public void autoAddWindowMenuItems(Menu menu) { StageHelper.getStages().addListener(new WindowMenuUpdateListener(menu)); } + public void setForceQuitOnCmdQ(boolean forceQuit) { + applicationAdapter.setForceQuitOnCmdQ(forceQuit); + } + protected Menu extractApplicationMenu(MenuBar menuBar) { return menuBar.getMenus().get(0); } diff --git a/src/main/java/de/codecentric/centerdevice/glass/MacApplicationAdapter.java b/src/main/java/de/codecentric/centerdevice/glass/MacApplicationAdapter.java index 4790061..deb347e 100644 --- a/src/main/java/de/codecentric/centerdevice/glass/MacApplicationAdapter.java +++ b/src/main/java/de/codecentric/centerdevice/glass/MacApplicationAdapter.java @@ -14,6 +14,8 @@ public class MacApplicationAdapter { private Application app; + private boolean forceQuitOnCmdQ = true; + public MacApplicationAdapter() throws ReflectiveOperationException { app = Application.GetApplication(); @@ -39,6 +41,12 @@ public void quit() { if (eh != null) { eh.handleQuitAction(Application.GetApplication(), System.nanoTime()); } - Platform.exit(); + if (forceQuitOnCmdQ) { + Platform.exit(); + } + } + + public void setForceQuitOnCmdQ(boolean forceQuit) { + this.forceQuitOnCmdQ = forceQuit; } }