From a5943c127935fe9ff4a72775dd8230739dde5b99 Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 13 Mar 2020 17:17:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/DesignerFrame.java | 5 +-- .../com/fr/design/os/impl/MacOsAction.java | 44 ------------------- .../os/impl/MacOsAddListenerAction.java | 41 +++++++++++++++++ .../com/fr/design/os/impl/SupportOSImpl.java | 10 +++++ 4 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java create mode 100644 designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 4a9fbac8a..237f2f975 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -40,7 +40,7 @@ import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.menu.MenuManager; import com.fr.design.menu.ShortCut; -import com.fr.design.os.impl.MacOsAction; +import com.fr.design.os.impl.MacOsAddListenerAction; import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.event.EventDispatcher; @@ -527,8 +527,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta } private void addMacOsListener() { - MacOsAction macOsAction = OSSupportCenter.getAction(MacOsAction.class); - macOsAction.execute(this); + OSSupportCenter.buildAction(new MacOsAddListenerAction(), SupportOSImpl.DOCK_QUIT); } protected ArrayList getFrameListeners() { diff --git a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java deleted file mode 100644 index 7f5c7be08..000000000 --- a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.fr.design.os.impl; - -import com.fr.design.mainframe.DesignerFrame; -import com.fr.invoke.Reflect; -import com.fr.log.FineLoggerFactory; -import com.fr.stable.os.OperatingSystem; -import com.fr.stable.os.support.OSBasedAction; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * @author hades - * @version 10.0 - * Created by hades on 2020/3/13 - */ -public class MacOsAction implements OSBasedAction { - - @Override - public void execute(final Object... objects) { - if (OperatingSystem.isMacos()) { - try { - Class app = Class.forName("com.apple.eawt.Application"); - Class handler = Class.forName("com.apple.eawt.QuitHandler"); - Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler}, - new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, - Object[] args) throws Throwable { - if ("handleQuitRequestWith".equals(method.getName())) { - DesignerFrame designerFrame = (DesignerFrame) objects[0]; - designerFrame.exit(); - } - return null; - } - }); - Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance); - } catch (ClassNotFoundException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - } -} diff --git a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java new file mode 100644 index 000000000..4d8c892b9 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java @@ -0,0 +1,41 @@ +package com.fr.design.os.impl; + +import com.fr.design.mainframe.DesignerFrame; +import com.fr.invoke.Reflect; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.os.support.OSBasedAction; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/3/13 + */ +public class MacOsAddListenerAction implements OSBasedAction { + + @Override + public void execute(final Object... objects) { + try { + Class app = Class.forName("com.apple.eawt.Application"); + Class handler = Class.forName("com.apple.eawt.QuitHandler"); + Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler}, + new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, + Object[] args) throws Throwable { + if ("handleQuitRequestWith".equals(method.getName())) { + DesignerFrame designerFrame = (DesignerFrame) objects[0]; + designerFrame.exit(); + } + return null; + } + }); + Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance); + } catch (ClassNotFoundException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java index 9bc29b829..2518ef57c 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java @@ -73,6 +73,16 @@ public enum SupportOSImpl implements SupportOS { public boolean support() { return FRContext.isChineseEnv() && !OperatingSystem.isMacos() && Arch.getArch() != Arch.ARM; } + }, + + /** + * mac下dock栏右键退出 + */ + DOCK_QUIT { + @Override + public boolean support() { + return OperatingSystem.isMacos(); + } } }