Skip to content

Commit

Permalink
properly support DefaultExecutionTarget. Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
turbanoff committed Nov 21, 2018
1 parent e69b9b6 commit eb0d703
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Plugins for Jetbrains IDEs. It's provides a way to use run configurations as buttons on toolbar. Or assign shortcuts to execute specific run configuration.

Plugin is compatible with all major IDEs based on IntelliJ Platform starting from version 2016.x:
Plugin is compatible with all major IDEs based on IntelliJ Platform starting from version 2018.1:
* IntelliJ IDEA
* Android Studio
* PhpStorm
Expand Down
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Also it allows to create button in toolbar to run specific configuration.<br>
<h3>1.3</h3>
<ul>
<li>Properly support execution targets (It includes support of CMake profiles.).
Now plugin register action not only per-Executor (Run/Debug/Coverage/...) but per-Executor-per-ExecutionTarget
Now plugin register action not only per-Executor (Run/Debug/Coverage/...) but per-Executor-per-ExecutionTarget.
Dropped support of old IDE. Now only 2018.1+ are supported.
</li>
</ul>
<h3>1.2</h3>
Expand All @@ -28,7 +29,7 @@ Also it allows to create button in toolbar to run specific configuration.<br>
]]>
</change-notes>

<idea-version since-build="143.0"/>
<idea-version since-build="181"/>

<depends>com.intellij.modules.platform</depends>

Expand Down
15 changes: 12 additions & 3 deletions src/org/turbanov/actions/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.function.Function;

import com.intellij.execution.DefaultExecutionTarget;
import com.intellij.execution.ExecutionTarget;
import com.intellij.execution.ExecutionTargetManager;
import com.intellij.execution.Executor;
Expand Down Expand Up @@ -54,8 +55,13 @@ private void registerAction(@NotNull RunnerAndConfigurationSettings runConfig,
AnAction action = actionManager.getAction(actionId);
if (action == null) {
Icon icon = makeIcon(runConfig, executor);
String text = executor.getActionName() + " '" + runConfig.getName() + "'" +
(target == null ? "" : " " + target.getDisplayName());
String targetAdd;
if (target == null || DefaultExecutionTarget.INSTANCE.equals(target)) {
targetAdd = "";
} else {
targetAdd = " " + target.getDisplayName();
}
String text = executor.getActionName() + " '" + runConfig.getName() + "'" + targetAdd;
String executionTargetId = target == null ? null : target.getId();
action = new RunConfigurationAsAction(runConfig.getName(), executor.getId(), icon, text, executionTargetId);
actionManager.registerAction(actionId, action, PLUGIN_ID);
Expand Down Expand Up @@ -113,7 +119,10 @@ private void registerForAllExecutors(@NotNull RunnerAndConfigurationSettings set

@NotNull
private List<ExecutionTarget> getTargets(@NotNull RunnerAndConfigurationSettings runConfig) {
List<ExecutionTarget> targets = ExecutionTargetManager.getTargetsToChooseFor(myProject, runConfig);
List<ExecutionTarget> targets = ExecutionTargetManager.getInstance(myProject).getTargetsFor(runConfig);
if (targets.size() == 1 && DefaultExecutionTarget.INSTANCE.equals(targets.get(0))) {
return targets;
}
targets = new ArrayList<>(targets);
targets.add(null);
return targets;
Expand Down
23 changes: 11 additions & 12 deletions src/org/turbanov/actions/RunConfigurationAsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import com.intellij.execution.ExecutionTargetManager;
import com.intellij.execution.Executor;
import com.intellij.execution.ExecutorRegistry;
import com.intellij.execution.ProgramRunnerUtil;
import com.intellij.execution.RunManagerEx;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.runners.ExecutionUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.diagnostic.Logger;
Expand Down Expand Up @@ -59,27 +59,26 @@ public void actionPerformed(@NotNull AnActionEvent e) {
return;
}

selectRequiredExecutionTarget(project, runConfig);
ExecutionTarget target = getExecutionTarget(project, runConfig);

ProgramRunnerUtil.executeConfiguration(project, runConfig, executor);
ExecutionUtil.runConfiguration(runConfig, executor, target);
}

private void selectRequiredExecutionTarget(@NotNull Project project, @NotNull RunnerAndConfigurationSettings runConfig) {
if (executionTargetId == null) {
return; //use selected as is
}
@NotNull
private ExecutionTarget getExecutionTarget(@NotNull Project project, @NotNull RunnerAndConfigurationSettings runConfig) {
ExecutionTargetManager targetManager = ExecutionTargetManager.getInstance(project);
ExecutionTarget executionTarget = targetManager.getActiveTarget();
if (executionTargetId.equals(executionTarget.getId())) {
return; //already selected ours
ExecutionTarget active = targetManager.getActiveTarget();
if (executionTargetId == null || executionTargetId.equals(active.getId())) {
return active; //use selected as is
}

List<ExecutionTarget> targets = targetManager.getTargetsFor(runConfig);
for (ExecutionTarget target : targets) {
if (target.getId().equals(executionTargetId)) {
targetManager.setActiveTarget(target);
return;
return target;
}
}
return active; //fallback to active
}

public void register() {
Expand Down

0 comments on commit eb0d703

Please sign in to comment.