我想在我的自定义IntellIJ IDEA插件中运行自定义IntentionAction
时显示进度条。
然而,无论我做什么,都不会显示。为了测试问题是否在IntentionAction
中,我将代码复制粘贴到AnAction
的简单实现中。全班看起来像这样:
public class HelloAction extends AnAction {
public HelloAction() {
super("Hello");
}
public void actionPerformed(AnActionEvent event) {
Project project = event.getData(CommonDataKeys.PROJECT);
ProgressManager.getInstance().run(new Task.Modal(project, "daf", false) {
public void run(ProgressIndicator indicator) {
indicator.setText("This is how you update the indicator");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
indicator.setFraction(0.5); // halfway done
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
}
});
Messages.showMessageDialog(project, "Hello world!", "Greeting", Messages.getInformationIcon());
}
}
它完美无缺。当我在IntentionAction
中使用相同的代码时,不会显示任何内容。
public class GenerateIntentionAction extends PsiElementBaseIntentionAction implements IntentionAction {
...
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
ProgressManager.getInstance().run(new Task.Modal(project, "daf", false) {
public void run(ProgressIndicator indicator) {
indicator.setText("This is how you update the indicator");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
indicator.setFraction(0.5); // halfway done
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
}
});
我尝试拨打runWithProgressSynchronously
而不是run
,尝试制作Task
Modal
和Backgroundable
- 无济于事。除了ProgressIndicator
内的IntentionAction
总是EmptyProgressIndicator
答案 0 :(得分:0)
如果在WriteAction
内调用了您的意图操作,则无法从那里显示模态UI。覆盖startInWriteAction
并返回false
可能会有所帮助。