mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-248360 - Adding new target in Manage targets dialog should launch wizard
GitOrigin-RevId: c73c9db07e66564f05464fc1cd4f1b0416bfc841
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7591c6fb71
commit
786fff96ce
@@ -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<RunOnTargetComboBox.Item> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pair<T, List<AbstractWizardStepEx>> createStepsForNewWizard(Project project, LanguageRuntimeType<?> defaultRuntimeType) {
|
||||
T config = type.createDefaultConfig();
|
||||
List<AbstractWizardStepEx> 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<RunOnTargetComboBox.Item> {
|
||||
}
|
||||
if (anObject instanceof Type) {
|
||||
//noinspection unchecked,rawtypes
|
||||
Pair<TargetEnvironmentConfiguration, List<AbstractWizardStepEx>> 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;
|
||||
}
|
||||
|
||||
@@ -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<AbstractWizardStepEx>)
|
||||
: AbstractWizardEx(title, project, steps) {
|
||||
|
||||
override fun getHelpId(): String = "reference.remote.target.wizard.${subject.typeId}"
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun <C : TargetEnvironmentConfiguration> createWizard(
|
||||
project: Project, targetType: TargetEnvironmentType<C>, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
-8
@@ -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<T : TargetEnvironmentConfiguration>(private val type: TargetEnvironmentType<T>)
|
||||
private inner class CreateNewTargetAction<T : TargetEnvironmentConfiguration>(private val project: Project,
|
||||
private val type: TargetEnvironmentType<T>)
|
||||
: 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<AnAction> {
|
||||
return TargetEnvironmentType.EXTENSION_NAME.extensionList
|
||||
.map { CreateNewTargetAction(it) }
|
||||
.map { CreateNewTargetAction(project, it) }
|
||||
.toArray(AnAction.EMPTY_ARRAY)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user