mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExecutorAction.getActions — do not show run configurations if no programm runner
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,8 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.PsiMethodUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class ApplicationRunLineMarkerProvider extends RunLineMarkerContributor {
|
||||
@Nullable
|
||||
@Override
|
||||
public Info getInfo(final PsiElement e) {
|
||||
public Info getInfo(@NotNull final PsiElement e) {
|
||||
if (isIdentifier(e)) {
|
||||
PsiElement element = e.getParent();
|
||||
if (element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass)element) != null ||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public class TestRunLineMarkerProvider extends RunLineMarkerContributor {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Info getInfo(PsiElement e) {
|
||||
public Info getInfo(@NotNull PsiElement e) {
|
||||
if (isIdentifier(e)) {
|
||||
PsiElement element = e.getParent();
|
||||
if (element instanceof PsiClass) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,10 +26,6 @@ public abstract class RunnerRegistry {
|
||||
return ServiceManager.getService(RunnerRegistry.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
public abstract boolean hasRunner(@NotNull String executorId, @NotNull RunProfile settings);
|
||||
|
||||
@Nullable
|
||||
public abstract ProgramRunner getRunner(@NotNull String executorId, @Nullable RunProfile settings);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,11 +24,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// TODO[spLeaner]: eliminate
|
||||
public class RunnerRegistryImpl extends RunnerRegistry {
|
||||
@Override
|
||||
public boolean hasRunner(@NotNull String executorId, @NotNull RunProfile settings) {
|
||||
return getRunner(executorId, settings) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgramRunner getRunner(@NotNull String executorId, @Nullable RunProfile settings) {
|
||||
if (settings == null) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.execution.lineMarker
|
||||
|
||||
import com.intellij.execution.Executor
|
||||
import com.intellij.execution.ExecutorRegistry
|
||||
import com.intellij.execution.RunnerRegistry
|
||||
import com.intellij.execution.actions.*
|
||||
import com.intellij.execution.configurations.LocatableConfiguration
|
||||
import com.intellij.execution.impl.RunManagerImpl
|
||||
@@ -29,46 +30,52 @@ import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.diagnostic.catchAndLog
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.util.containers.mapSmart
|
||||
import com.intellij.util.containers.mapSmartNotNull
|
||||
|
||||
private val LOG = logger<ExecutorAction>()
|
||||
private val CONFIGURATION_CACHE = Key.create<List<ConfigurationFromContext>>("ConfigurationFromContext")
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
class ExecutorAction private constructor(private val myOrigin: AnAction,
|
||||
private val myExecutor: Executor,
|
||||
private val myOrder: Int) : AnAction() {
|
||||
|
||||
class ExecutorAction private constructor(private val origin: AnAction, private val executor: Executor, private val order: Int) : AnAction() {
|
||||
init {
|
||||
copyFrom(myOrigin)
|
||||
copyFrom(origin)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG = logger<ExecutorAction>()
|
||||
private val CONFIGURATION_CACHE = Key.create<List<ConfigurationFromContext>>("ConfigurationFromContext")
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getActions(order: Int = 0) = getActionList(order).toTypedArray()
|
||||
|
||||
@JvmStatic
|
||||
fun getActions(order: Int): Array<AnAction> {
|
||||
return ExecutorRegistry.getInstance().registeredExecutors.map {
|
||||
ExecutorAction(ActionManager.getInstance().getAction(it.contextActionId), it, order)
|
||||
}.toTypedArray()
|
||||
@JvmOverloads
|
||||
fun getActionList(order: Int = 0): List<AnAction> {
|
||||
val actionManager = ActionManager.getInstance()
|
||||
return ExecutorRegistry.getInstance().registeredExecutors.mapSmart {
|
||||
ExecutorAction(actionManager.getAction(it.contextActionId), it, order)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfigurations(dataContext: DataContext): List<ConfigurationFromContext> {
|
||||
var result = DataManager.getInstance().loadFromDataContext(dataContext, CONFIGURATION_CACHE)
|
||||
if (result == null) {
|
||||
result = calcConfigurations(dataContext)
|
||||
result = computeConfigurations(dataContext)
|
||||
DataManager.getInstance().saveInDataContext(dataContext, CONFIGURATION_CACHE, result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun calcConfigurations(dataContext: DataContext): List<ConfigurationFromContext> {
|
||||
private fun computeConfigurations(dataContext: DataContext): List<ConfigurationFromContext> {
|
||||
val context = ConfigurationContext.getFromContext(dataContext)
|
||||
if (context.location == null) {
|
||||
return emptyList()
|
||||
}
|
||||
return RunConfigurationProducer.getProducers(context.project).mapNotNull {
|
||||
|
||||
return RunConfigurationProducer.getProducers(context.project).mapSmartNotNull {
|
||||
LOG.catchAndLog {
|
||||
val configuration = it.createLightConfiguration(context) ?: return@mapNotNull null
|
||||
val configuration = it.createLightConfiguration(context) ?: return@mapSmartNotNull null
|
||||
val settings = RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(context.project), configuration, false)
|
||||
ConfigurationFromContextImpl(it, settings, context.psiLocation)
|
||||
}
|
||||
@@ -77,13 +84,13 @@ class ExecutorAction private constructor(private val myOrigin: AnAction,
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val name = getActionName(e.dataContext, myExecutor)
|
||||
e.presentation.isVisible = name != null
|
||||
val name = getActionName(e.dataContext, executor)
|
||||
e.presentation.isEnabledAndVisible = name != null
|
||||
e.presentation.text = name
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
myOrigin.actionPerformed(e)
|
||||
origin.actionPerformed(e)
|
||||
}
|
||||
|
||||
private fun getActionName(dataContext: DataContext, executor: Executor): String? {
|
||||
@@ -91,8 +98,12 @@ class ExecutorAction private constructor(private val myOrigin: AnAction,
|
||||
if (list.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
val configuration = list[if (myOrder < list.size) myOrder else 0]
|
||||
val actionName = BaseRunConfigurationAction.suggestRunActionName(configuration.configuration as LocatableConfiguration)
|
||||
return executor.getStartActionText(actionName)
|
||||
|
||||
val configuration = list.getOrNull(if (order < list.size) order else 0)?.configuration as LocatableConfiguration
|
||||
if (RunnerRegistry.getInstance().getRunner(executor.id, configuration) == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return executor.getStartActionText(BaseRunConfigurationAction.suggestRunActionName(configuration))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,3 +149,12 @@ inline fun <T, R> Collection<T>.mapSmart(transform: (T) -> R): List<R> {
|
||||
mapTo(ArrayList<R>(size), transform)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R : Any> Collection<T>.mapSmartNotNull(transform: (T) -> R?): List<R> {
|
||||
return if (size == 1) {
|
||||
transform(first())?.let { SmartList<R>(it) } ?: SmartList<R>()
|
||||
}
|
||||
else {
|
||||
mapNotNullTo(ArrayList<R>(size), transform)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ open class OutMessage() {
|
||||
|
||||
fun writeNullableString(name: String, value: CharSequence?) {
|
||||
beginArguments()
|
||||
writer.name(name).value(value?.toString() ?: null)
|
||||
writer.name(name).value(value?.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user