* Fix for Mac OS X quit behaviour (Dock->Quit, CTRL+Q) not being executed when application is closed via Quit rather than clicking [X] on the main window

This commit is contained in:
Reinhard Pointner 2014-10-09 13:37:15 +00:00
parent 69ac55c9f8
commit 3455ea9e0e
4 changed files with 32 additions and 17 deletions

View File

@ -30,6 +30,7 @@
<classpathentry kind="lib" path="lib/xmlrpc.jar"/> <classpathentry kind="lib" path="lib/xmlrpc.jar"/>
<classpathentry kind="lib" path="lib/xz.jar"/> <classpathentry kind="lib" path="lib/xz.jar"/>
<classpathentry kind="lib" path="lib/ObjCBridge.jar"/> <classpathentry kind="lib" path="lib/ObjCBridge.jar"/>
<classpathentry kind="lib" path="lib/build/AppleJavaExtensions.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -642,8 +642,7 @@
<!-- compile --> <!-- compile -->
<javac srcdir="${dir.source}:${dir.test}" destdir="${dir.build}" target="1.8" source="1.8" encoding="utf-8" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"> <javac srcdir="${dir.source}:${dir.test}" destdir="${dir.build}" target="1.8" source="1.8" encoding="utf-8" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false">
<classpath> <classpath>
<fileset dir="${dir.lib}" includes="*.jar" /> <fileset dir="${dir.lib}" includes="**/*.jar" />
<pathelement location="${dir.lib}/build/junit.jar" />
</classpath> </classpath>
</javac> </javac>

View File

@ -1,4 +1,3 @@
//TODO MOVE package net.filebot to net.filebot
package net.filebot; package net.filebot;
import static java.awt.GraphicsEnvironment.*; import static java.awt.GraphicsEnvironment.*;
@ -284,8 +283,8 @@ public class Main {
}); });
// window settings // window settings
if (Settings.isMacApp()) { if (isMacApp()) {
MacAppUtilities.setUIDefaults(); MacAppUtilities.initializeApplication();
MacAppUtilities.setWindowCanFullScreen(frame); MacAppUtilities.setWindowCanFullScreen(frame);
} }
frame.setLocationByPlatform(true); frame.setLocationByPlatform(true);

View File

@ -1,8 +1,9 @@
package net.filebot.mac; package net.filebot.mac;
import java.awt.EventQueue;
import java.awt.Window; import java.awt.Window;
import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.lang.reflect.Method;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -10,6 +11,10 @@ import javax.swing.UIManager;
import ca.weblite.objc.Client; import ca.weblite.objc.Client;
import com.apple.eawt.Application;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;
public class MacAppUtilities { public class MacAppUtilities {
private static Client _objc; private static Client _objc;
@ -35,9 +40,7 @@ public class MacAppUtilities {
public static void setWindowCanFullScreen(Window window) { public static void setWindowCanFullScreen(Window window) {
try { try {
Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities"); com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true);
Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, boolean.class });
setWindowCanFullScreen.invoke(null, window, true);
} catch (Throwable t) { } catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t); Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
} }
@ -45,10 +48,7 @@ public class MacAppUtilities {
public static void requestForeground() { public static void requestForeground() {
try { try {
Class<?> application = Class.forName("com.apple.eawt.Application"); com.apple.eawt.Application.getApplication().requestForeground(true);
Object instance = application.getMethod("getApplication").invoke(null);
Method requestForeground = application.getMethod("requestForeground", new Class<?>[] { boolean.class });
requestForeground.invoke(instance, true);
} catch (Throwable t) { } catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "requestForeground not supported: " + t); Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "requestForeground not supported: " + t);
} }
@ -56,16 +56,32 @@ public class MacAppUtilities {
public static void revealInFinder(File file) { public static void revealInFinder(File file) {
try { try {
Class<?> fileManager = Class.forName("com.apple.eio.FileManager"); com.apple.eio.FileManager.revealInFinder(file);
Method revealInFinder = fileManager.getMethod("revealInFinder", new Class<?>[] { File.class });
revealInFinder.invoke(null, file);
} catch (Throwable t) { } catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "revealInFinder not supported: " + t); Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "revealInFinder not supported: " + t);
} }
} }
public static void setUIDefaults() { public static void initializeApplication() {
// improved UI defaults
UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant")); UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant"));
// make sure Application Quit Events get forwarded to normal Window Listeners
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
@Override
public void handleQuit(ApplicationEvent evt) {
for (Window window : Window.getOwnerlessWindows()) {
// close all windows
window.setVisible(false);
// call window listeners
EventQueue.invokeLater(() -> {
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
});
}
}
});
} }
public static boolean isLockedFolder(File folder) { public static boolean isLockedFolder(File folder) {