* 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/xz.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="output" path="bin"/>
</classpath>

View File

@ -642,8 +642,7 @@
<!-- 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">
<classpath>
<fileset dir="${dir.lib}" includes="*.jar" />
<pathelement location="${dir.lib}/build/junit.jar" />
<fileset dir="${dir.lib}" includes="**/*.jar" />
</classpath>
</javac>

View File

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

View File

@ -1,8 +1,9 @@
package net.filebot.mac;
import java.awt.EventQueue;
import java.awt.Window;
import java.awt.event.WindowEvent;
import java.io.File;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -10,6 +11,10 @@ import javax.swing.UIManager;
import ca.weblite.objc.Client;
import com.apple.eawt.Application;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;
public class MacAppUtilities {
private static Client _objc;
@ -35,9 +40,7 @@ public class MacAppUtilities {
public static void setWindowCanFullScreen(Window window) {
try {
Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");
Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, boolean.class });
setWindowCanFullScreen.invoke(null, window, true);
com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true);
} catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
}
@ -45,10 +48,7 @@ public class MacAppUtilities {
public static void requestForeground() {
try {
Class<?> application = Class.forName("com.apple.eawt.Application");
Object instance = application.getMethod("getApplication").invoke(null);
Method requestForeground = application.getMethod("requestForeground", new Class<?>[] { boolean.class });
requestForeground.invoke(instance, true);
com.apple.eawt.Application.getApplication().requestForeground(true);
} catch (Throwable 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) {
try {
Class<?> fileManager = Class.forName("com.apple.eio.FileManager");
Method revealInFinder = fileManager.getMethod("revealInFinder", new Class<?>[] { File.class });
revealInFinder.invoke(null, file);
com.apple.eio.FileManager.revealInFinder(file);
} catch (Throwable 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"));
// 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) {