From c526aec25e5d613cf302c65d10d2e8b505f5d62a Mon Sep 17 00:00:00 2001 From: makejava <1353036300@qq.com> Date: Thu, 15 Jul 2021 17:03:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmac=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E5=85=BC=E5=AE=B9BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sjhy/plugin/tool/MessageDialogUtils.java | 59 +++++-------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/sjhy/plugin/tool/MessageDialogUtils.java b/src/main/java/com/sjhy/plugin/tool/MessageDialogUtils.java index 2bebbaf..3ec1cf5 100644 --- a/src/main/java/com/sjhy/plugin/tool/MessageDialogUtils.java +++ b/src/main/java/com/sjhy/plugin/tool/MessageDialogUtils.java @@ -1,13 +1,10 @@ package com.sjhy.plugin.tool; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.MessageDialogBuilder; -import com.intellij.openapi.ui.Messages; -import com.intellij.util.ExceptionUtil; +import com.intellij.util.ui.UIUtil; import com.sjhy.plugin.constants.MsgValue; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import javax.swing.*; /** * 消息弹框工具类 @@ -37,24 +34,12 @@ public class MessageDialogUtils { * @return 是否确认 */ public static boolean yesNo(Project project, String msg) { - MessageDialogBuilder builder = MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, msg); - Method method; - // 新版本兼容 - try { - method = builder.getClass().getMethod("ask", Project.class); - return (boolean) method.invoke(builder, project); - } catch (NoSuchMethodException e) { - // 旧版本兼容 - try { - method = builder.getClass().getMethod("isYes"); - return (boolean) method.invoke(builder); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e1) { - ExceptionUtil.rethrow(e1); - } - } catch (IllegalAccessException | InvocationTargetException e) { - ExceptionUtil.rethrow(e); - } - return false; + Object[] options = new Object[]{"Yes", "No"}; + return JOptionPane.showOptionDialog(null, + msg, MsgValue.TITLE_INFO, + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, + UIUtil.getQuestionIcon(), + options, options[0]) == 0; } /** @@ -65,28 +50,12 @@ public class MessageDialogUtils { * @return 点击按钮 */ public static int yesNoCancel(Project project, String msg, String yesText, String noText, String cancelText) { - MessageDialogBuilder builder = MessageDialogBuilder - .yesNoCancel(MsgValue.TITLE_INFO, msg) - .yesText(yesText) - .noText(noText) - .cancelText(cancelText); - Method method; - // 新版本兼容 - try { - method = builder.getClass().getMethod("show", Project.class); - return (int) method.invoke(builder, project); - } catch (NoSuchMethodException e) { - // 旧版本兼容 - try { - method = builder.getClass().getMethod("show"); - return (int) method.invoke(builder); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e1) { - ExceptionUtil.rethrow(e1); - } - } catch (IllegalAccessException | InvocationTargetException e) { - ExceptionUtil.rethrow(e); - } - return Messages.NO; + Object[] options = new Object[]{"Yes", "No", "Cancel"}; + return JOptionPane.showOptionDialog(null, + msg, MsgValue.TITLE_INFO, + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, + UIUtil.getQuestionIcon(), + options, options[0]); } }