How to run or restart the currently selected run profile from within plugin code?

Answered

How to run or restart the currently selected run profile from within plugin code?

Currently running or restarting through Shift F10, I want to integrate these APIs through plug-ins.

 
0
6 comments

Hi,

Please use UI Inspector to track down the action and see its implementation:

https://plugins.jetbrains.com/docs/intellij/internal-ui-inspector.html#action

The underlying action is com.intellij.execution.ExecutorRegistryImpl.ExecutorAction.

0

Hi, I implemented RunAction and registered the shortcut key, but I can't use the shortcut key to start the program in the idea.

But the default shortcut key (Shift F10) of idea can be run.

The following is the configuration and code implementation of plugin.xml.

    <actions>
<action id="MyRun" class="com.aiwan.request.action.MyRunAction" icon="AllIcons.Actions.Execute">
<!-- <add-to-group group-id="RunDashboardContentToolbar"/>-->
<keyboard-shortcut first-keystroke="alt d" keymap="$default"/>
</action>
</actions>
public class MyRunAction extends RunAction {

@Override
protected void update(@NotNull AnActionEvent e, boolean running) {
System.out.println("Update: "+running);
Presentation presentation = e.getPresentation();
if (running) {
presentation.setText(ExecutionBundle.messagePointer("run.dashboard.rerun.action.name"));
presentation.setDescription(ExecutionBundle.messagePointer("run.dashboard.rerun.action.description"));
presentation.setIcon(AllIcons.Actions.Restart);
}
else {
presentation.setText(ExecutionBundle.messagePointer("run.dashboard.run.action.name"));
presentation.setDescription(ExecutionBundle.messagePointer("run.dashboard.run.action.description"));
presentation.setIcon(AllIcons.Actions.Execute);
}
}
}
0

Hi,

I don't see what the issue is. Please provide a reproducible example.

0

Your shortcut conflicts with a letter in my IDE. I changed it to Ctrl+Shift+L, and it works correctly.
Action is not run, because it is disabled. According to com.intellij.openapi.actionSystem.Presentation.setEnabled() Javadoc, AnAction.actionPerformed() is not executed in such a case.
Set a breakpoint in com.intellij.execution.dashboard.actions.ExecutorAction.update() and see why it is disabled.

0

Hi I found a way to do shift + F10 in the plugin。Thanks for your help.

@Override
protected void update(@NotNull AnActionEvent e, boolean running) {
AnAction run = ActionManager.getInstance().getAction("Run");
run.actionPerformed(e);
}
0

Please sign in to leave a comment.