From ecb0b88f4126a76dca73e72127c7b7b957807c06 Mon Sep 17 00:00:00 2001 From: lkqm Date: Fri, 7 Jan 2022 21:12:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=87=8D=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=E7=9A=84=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不显示右键菜单:非Java文件 || 跨多个模块目录选择 --- .../plugin/actions/EasyCodeEntityAction.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/sjhy/plugin/actions/EasyCodeEntityAction.java b/src/main/java/com/sjhy/plugin/actions/EasyCodeEntityAction.java index e8068c5..4ed3049 100644 --- a/src/main/java/com/sjhy/plugin/actions/EasyCodeEntityAction.java +++ b/src/main/java/com/sjhy/plugin/actions/EasyCodeEntityAction.java @@ -4,6 +4,8 @@ import com.google.common.collect.Lists; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; @@ -74,5 +76,23 @@ public class EasyCodeEntityAction extends AnAction { return psiClassList; } + @Override + public void update(@NotNull AnActionEvent event) { + // 不存在模块不展示:选择多个模块 + Project project = event.getData(CommonDataKeys.PROJECT); + Module module = event.getData(LangDataKeys.MODULE); + if (project == null || module == null) { + event.getPresentation().setVisible(false); + return; + } + + // 非java的文件不显示 + VirtualFile file = event.getDataContext().getData(CommonDataKeys.VIRTUAL_FILE); + if (file != null && !file.isDirectory() && !"java".equals(file.getExtension())) { + event.getPresentation().setVisible(false); + return; + } + } + }