fix: 优化重实体生成代码的右键菜单显示

不显示右键菜单:非Java文件 || 跨多个模块目录选择
This commit is contained in:
lkqm 2022-01-07 21:12:39 +08:00
parent 7e65744ef2
commit ecb0b88f41
1 changed files with 20 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import com.google.common.collect.Lists;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys; 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.project.Project;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClass;
@ -74,5 +76,23 @@ public class EasyCodeEntityAction extends AnAction {
return psiClassList; 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;
}
}
} }