Skip to content

Commit eb5f5f5

Browse files
committed
fix after dropping legacy action usage
1 parent e360f74 commit eb5f5f5

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

‎plugin/src/main/java/com/intellij/java/impl/ide/actions/CreateModuleInfoAction.java‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
import consulo.module.content.ProjectRootManager;
3838
import consulo.project.Project;
3939
import consulo.ui.ex.action.AnActionEvent;
40+
import consulo.ui.ex.action.AnActionWithAsyncUpdate;
41+
import consulo.ui.ex.action.coroutine.ActionSafeReadLock;
42+
import consulo.util.concurrent.coroutine.Coroutine;
4043
import consulo.virtualFileSystem.VirtualFile;
4144
import org.jspecify.annotations.Nullable;
4245

@@ -49,7 +52,7 @@
4952
import static com.intellij.java.language.psi.PsiJavaModule.MODULE_INFO_FILE;
5053

5154
@ActionImpl(id = "NewModuleInfo")
52-
public class CreateModuleInfoAction extends CreateFromTemplateActionBase {
55+
public class CreateModuleInfoAction extends CreateFromTemplateActionBase implements AnActionWithAsyncUpdate {
5356
public CreateModuleInfoAction() {
5457
super(
5558
JavaLocalize.actionCreateNewModuleInfoTitle(),
@@ -59,24 +62,26 @@ public CreateModuleInfoAction() {
5962
}
6063

6164
@Override
62-
public void update(AnActionEvent e) {
63-
if (!e.getPresentation().isVisible()) {
64-
return;
65-
}
66-
DataContext ctx = e.getDataContext();
67-
boolean available = Optional.ofNullable(ctx.getData(IdeView.KEY))
68-
.map(view -> getTargetDirectory(ctx, view))
69-
.filter(PsiUtil::isLanguageLevel9OrHigher)
70-
.map(PsiElement::getModule)
71-
.map(
72-
module -> FilenameIndex.getVirtualFilesByName(
73-
module.getProject(),
74-
MODULE_INFO_FILE,
75-
GlobalSearchScope.moduleScope(module)
76-
).isEmpty()
77-
)
78-
.orElse(false);
79-
e.getPresentation().setEnabledAndVisible(available);
65+
public Coroutine<?, ?> updateAsync(AnActionEvent e) {
66+
return ActionSafeReadLock.run(e, presentation -> {
67+
if (!e.getPresentation().isVisible()) {
68+
return;
69+
}
70+
DataContext ctx = e.getDataContext();
71+
boolean available = Optional.ofNullable(ctx.getData(IdeView.KEY))
72+
.map(view -> getTargetDirectory(ctx, view))
73+
.filter(PsiUtil::isLanguageLevel9OrHigher)
74+
.map(PsiElement::getModule)
75+
.map(
76+
module -> FilenameIndex.getVirtualFilesByName(
77+
module.getProject(),
78+
MODULE_INFO_FILE,
79+
GlobalSearchScope.moduleScope(module)
80+
).isEmpty()
81+
)
82+
.orElse(false);
83+
e.getPresentation().setEnabledAndVisible(available);
84+
}).toCoroutine();
8085
}
8186

8287
@Nullable

‎plugin/src/main/java/com/intellij/java/impl/ide/actions/CreatePackageInfoAction.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
import consulo.project.Project;
4040
import consulo.ui.annotation.RequiredUIAccess;
4141
import consulo.ui.ex.action.AnActionEvent;
42+
import consulo.ui.ex.action.AnActionWithAsyncUpdate;
43+
import consulo.ui.ex.action.coroutine.ActionSafeReadLock;
4244
import consulo.ui.ex.awt.Messages;
4345
import consulo.ui.ex.awt.UIUtil;
46+
import consulo.util.concurrent.coroutine.Coroutine;
4447
import consulo.util.lang.StringUtil;
4548
import org.jspecify.annotations.Nullable;
4649

@@ -50,7 +53,7 @@
5053
* @author Bas Leijdekkers
5154
*/
5255
@ActionImpl(id = "NewPackageInfo")
53-
public class CreatePackageInfoAction extends CreateFromTemplateActionBase implements DumbAware {
56+
public class CreatePackageInfoAction extends CreateFromTemplateActionBase implements DumbAware, AnActionWithAsyncUpdate {
5457
public CreatePackageInfoAction() {
5558
super(
5659
JavaLocalize.actionCreateNewPackageInfoTitle(),
@@ -95,13 +98,14 @@ else if (directory.findFile("package.html") != null) {
9598
}
9699

97100
@Override
98-
@RequiredReadAction
99-
public void update(AnActionEvent e) {
100-
if (!e.getPresentation().isVisible()) {
101-
return;
102-
}
101+
public Coroutine<?, ?> updateAsync(AnActionEvent e) {
102+
return ActionSafeReadLock.run(e, presentation -> {
103+
if (!e.getPresentation().isVisible()) {
104+
return;
105+
}
103106

104-
e.getPresentation().setEnabledAndVisible(isAvailable(e.getDataContext()));
107+
e.getPresentation().setEnabledAndVisible(isAvailable(e.getDataContext()));
108+
}).toCoroutine();
105109
}
106110

107111
@RequiredReadAction

0 commit comments

Comments
 (0)