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; + } + } + }