diff --git a/platform/execution-impl/src/com/intellij/execution/RunOnTargetComboBox.java b/platform/execution-impl/src/com/intellij/execution/RunOnTargetComboBox.java index 4e08fe6ca781..0708f40bfaeb 100644 --- a/platform/execution-impl/src/com/intellij/execution/RunOnTargetComboBox.java +++ b/platform/execution-impl/src/com/intellij/execution/RunOnTargetComboBox.java @@ -3,12 +3,10 @@ package com.intellij.execution; import com.intellij.execution.target.*; import com.intellij.icons.AllIcons; -import com.intellij.ide.wizard.AbstractWizardStepEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.NlsContexts; -import com.intellij.openapi.util.Pair; import com.intellij.ui.ColoredListCellRenderer; import com.intellij.ui.SeparatorWithText; import com.intellij.util.ObjectUtils; @@ -135,14 +133,8 @@ public class RunOnTargetComboBox extends ComboBox { } @Nullable - private Pair> createStepsForNewWizard(Project project, LanguageRuntimeType defaultRuntimeType) { - T config = type.createDefaultConfig(); - List steps = type.createStepsForNewWizard(project, config, defaultRuntimeType); - if (steps == null) { - LOGGER.error("Cannot instantiate remote target wizard"); - return null; - } - return Pair.create(config, steps); + TargetEnvironmentWizard createWizard(@NotNull Project project, @Nullable LanguageRuntimeType languageRuntime) { + return TargetEnvironmentWizard.createWizard(project, type, languageRuntime); } } @@ -154,17 +146,12 @@ public class RunOnTargetComboBox extends ComboBox { } if (anObject instanceof Type) { //noinspection unchecked,rawtypes - Pair> wizardData = - ((Type)anObject).createStepsForNewWizard(myProject, myDefaultRuntimeType); - if (wizardData != null) { - TargetEnvironmentConfiguration newTarget = wizardData.first; - TargetEnvironmentWizard wizard = new TargetEnvironmentWizard( - myProject, ExecutionBundle.message("run.on.targets.wizard.title.new.target"), newTarget, wizardData.second); - if (wizard.showAndGet()) { - TargetEnvironmentsManager.getInstance().addTarget(newTarget); - addTarget(newTarget, 2); - setSelectedIndex(2); - } + TargetEnvironmentWizard wizard = ((Type)anObject).createWizard(myProject, myDefaultRuntimeType); + if (wizard != null && wizard.showAndGet()) { + TargetEnvironmentConfiguration newTarget = wizard.getSubject(); + TargetEnvironmentsManager.getInstance().addTarget(newTarget); + addTarget(newTarget, 2); + setSelectedIndex(2); } return; } diff --git a/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentWizard.kt b/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentWizard.kt index 86f85630775c..56c34b7e1722 100644 --- a/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentWizard.kt +++ b/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentWizard.kt @@ -1,6 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.target +import com.intellij.execution.ExecutionBundle import com.intellij.ide.wizard.AbstractWizardEx import com.intellij.ide.wizard.AbstractWizardStepEx import com.intellij.openapi.project.Project @@ -11,5 +12,24 @@ class TargetEnvironmentWizard(project: Project, val subject: TargetEnvironmentConfiguration, steps: List) : AbstractWizardEx(title, project, steps) { + override fun getHelpId(): String = "reference.remote.target.wizard.${subject.typeId}" + + companion object { + @JvmStatic + fun createWizard( + project: Project, targetType: TargetEnvironmentType, runtimeType: LanguageRuntimeType<*>? + ): TargetEnvironmentWizard? { + + if (!targetType.providesNewWizard(project, runtimeType)) { + return null + } + + val config = targetType.createDefaultConfig() + val steps = targetType.createStepsForNewWizard(project, config, runtimeType) ?: return null + + return TargetEnvironmentWizard( + project, ExecutionBundle.message("run.on.targets.wizard.title.new.target"), config, steps) + } + } } \ No newline at end of file diff --git a/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentsMasterDetails.kt b/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentsMasterDetails.kt index 2820e37415a9..82ae08e807ef 100644 --- a/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentsMasterDetails.kt +++ b/platform/execution-impl/src/com/intellij/execution/target/TargetEnvironmentsMasterDetails.kt @@ -15,7 +15,8 @@ import com.intellij.util.containers.toArray import com.intellij.util.text.UniqueNameGenerator import com.intellij.util.ui.StatusText -class TargetEnvironmentsMasterDetails @JvmOverloads constructor(private val project: Project, private val initialSelectedName: String? = null) +class TargetEnvironmentsMasterDetails @JvmOverloads constructor(private val project: Project, + private val initialSelectedName: String? = null) : MasterDetailsComponent() { init { @@ -94,16 +95,30 @@ class TargetEnvironmentsMasterDetails @JvmOverloads constructor(private val proj .filterNotNull() .toList() - private inner class CreateNewTargetAction(private val type: TargetEnvironmentType) + private inner class CreateNewTargetAction(private val project: Project, + private val type: TargetEnvironmentType) : DumbAwareAction(type.displayName, null, type.icon) { override fun actionPerformed(e: AnActionEvent) { - val newConfig = type.createDefaultConfig() - type.initializeNewlyCreated(newConfig) - // there may be not yet stored names - newConfig.displayName = UniqueNameGenerator.generateUniqueName(type.displayName) { curName -> - getConfiguredTargets().none { it.displayName == curName } + val newConfig: TargetEnvironmentConfiguration + + val wizard = TargetEnvironmentWizard.createWizard(project, type, null) + if (wizard != null) { + if (!wizard.showAndGet()) return + + newConfig = wizard.subject } + else { + newConfig = type.createDefaultConfig() + type.initializeNewlyCreated(newConfig) + } + + if (newConfig.displayName.isBlank()) { + newConfig.displayName = UniqueNameGenerator.generateUniqueName(type.displayName) { curName -> + getConfiguredTargets().none { it.displayName == curName } + } + } + // there may be not yet stored names TargetEnvironmentsManager.instance.ensureUniqueName(newConfig) val newNode = addTargetNode(newConfig) selectNodeInTree(newNode, true, true) @@ -118,7 +133,7 @@ class TargetEnvironmentsMasterDetails @JvmOverloads constructor(private val proj override fun getChildren(e: AnActionEvent?): Array { return TargetEnvironmentType.EXTENSION_NAME.extensionList - .map { CreateNewTargetAction(it) } + .map { CreateNewTargetAction(project, it) } .toArray(AnAction.EMPTY_ARRAY) }