Intellij IDEA 插件开发:无法获取 IntentionAction 的进度指示器
Intellij IDEA plugin development: Cannot get progress indicator for IntentionAction
我想在我的自定义 IntellIJ IDEA 插件中 运行 自定义 IntentionAction
时显示进度条。
可是怎么弄都不显示。为了测试问题是否出在IntentionAction
,我将代码复制粘贴到一个AnAction
的简单实现中。整个 class 看起来像这样:
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
- 但无济于事。除了 IntentionAction
中的 ProgressIndicator
始终是 EmptyProgressIndicator
之外,我不知道有什么问题
如果您的意图操作是在 WriteAction
内部调用的,您将无法从那里显示模态 UI。覆盖 startInWriteAction
并返回 false
可能会有所帮助。
我想在我的自定义 IntellIJ IDEA 插件中 运行 自定义 IntentionAction
时显示进度条。
可是怎么弄都不显示。为了测试问题是否出在IntentionAction
,我将代码复制粘贴到一个AnAction
的简单实现中。整个 class 看起来像这样:
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
- 但无济于事。除了 IntentionAction
中的 ProgressIndicator
始终是 EmptyProgressIndicator
如果您的意图操作是在 WriteAction
内部调用的,您将无法从那里显示模态 UI。覆盖 startInWriteAction
并返回 false
可能会有所帮助。