Wizard: add ability to open project wizard via hyperlink

This commit is contained in:
Ilya Kirillov
2020-04-02 22:34:11 +03:00
parent 91af859cb5
commit 588034e124
7 changed files with 106 additions and 6 deletions
@@ -33,4 +33,6 @@ module.settings.template.none=None
version.provider.downloading.kotlin.version=Downloading Kotlin version
module.settings.dependencies.empty=No module dependencies added.
module.settings.dependencies.empty.suggest.add=Add module dependency
module.settings.dependencies.empty.suggest.add=Add module dependency
project.opener.initialisation=Initialization ...
@@ -50,7 +50,7 @@ class IdeWizard(
var artifactId by setting(StructurePlugin::artifactId.reference)
var buildSystemType by setting(BuildSystemPlugin::type.reference)
val projectTemplate by setting(ProjectTemplatesPlugin::template.reference)
var projectTemplate by setting(ProjectTemplatesPlugin::template.reference)
private fun <V : Any, T : SettingType<V>> setting(reference: SettingReference<V, T>) =
object : ReadWriteProperty<Any?, V?> {
@@ -2,6 +2,8 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard
import com.intellij.ide.RecentProjectsManager
import com.intellij.ide.actions.NewProjectAction
import com.intellij.ide.impl.NewProjectUtil
import com.intellij.ide.projectWizard.NewProjectWizard
import com.intellij.ide.util.projectWizard.*
import com.intellij.ide.wizard.AbstractWizard
import com.intellij.openapi.Disposable
@@ -22,21 +24,24 @@ import org.jetbrains.kotlin.idea.projectWizard.ProjectCreationStats
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
import org.jetbrains.kotlin.idea.projectWizard.WizardStatsService
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
import org.jetbrains.kotlin.tools.projectWizard.core.div
import org.jetbrains.kotlin.tools.projectWizard.core.entity.StringValidators
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
import org.jetbrains.kotlin.tools.projectWizard.core.isSuccess
import org.jetbrains.kotlin.tools.projectWizard.core.onFailure
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.Plugins
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
import org.jetbrains.kotlin.tools.projectWizard.wizard.service.IdeaJpsWizardService
import org.jetbrains.kotlin.tools.projectWizard.wizard.service.IdeaServices
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.asHtml
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep.FirstWizardStepComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.runWithProgressBar
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.SecondStepWizardComponent
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.io.File
import javax.swing.JButton
import javax.swing.JComponent
@@ -143,8 +148,15 @@ class NewProjectWizardModuleBuilder : EmptyModuleBuilder() {
}
}
internal fun selectProjectTemplate(template: ProjectTemplate) {
wizard.buildSystemType = BuildSystemType.GradleKotlinDsl
wizard.projectTemplate = template
}
private val firstStep = ModuleNewWizardFirstStep(wizard)
override fun getCustomOptionsStep(context: WizardContext?, parentDisposable: Disposable?) =
ModuleNewWizardFirstStep(wizard)
firstStep
}
abstract class WizardStep(protected val wizard: IdeWizard, private val phase: GenerationPhase) : ModuleWizardStep() {
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.tools.projectWizard.wizard
import com.intellij.ide.impl.NewProjectUtil
import com.intellij.ide.projectWizard.NewProjectWizard
import com.intellij.ide.projectWizard.ProjectTypeStep
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
object NewWizardOpener {
fun open(template: ProjectTemplate?) {
val task = object : Task.Backgroundable(
null,
KotlinNewProjectWizardUIBundle.message("project.opener.initialisation")
) {
val wizard = NewProjectWizard(null, ModulesProvider.EMPTY_MODULES_PROVIDER, null)
override fun run(indicator: ProgressIndicator) {
// warm-up components, stolen from com.intellij.ide.impl.NewProjectUtil.createNewProject
ProjectManager.getInstance().defaultProject
}
override fun onFinished() = ApplicationManager.getApplication().invokeLater {
val step = wizard.currentStepObject as ProjectTypeStep
step.setSelectedTemplate(KotlinNewProjectWizardUIBundle.message("generator.title"), null)
if (template != null) {
wizard.projectBuilder
.safeAs<NewProjectWizardModuleBuilder>()
?.selectProjectTemplate(template)
}
if (wizard.showAndGet()) {
NewProjectUtil.createFromWizard(wizard, null)
}
}
}
ProgressManager.getInstance().runProcessWithProgressAsynchronously(
task,
BackgroundableProcessIndicator(task)
)
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.tools.projectWizard.wizard
import com.intellij.openapi.application.JBProtocolCommand
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
class OpenNewProjectWizardProtocolCommand : JBProtocolCommand(COMMAND_NAME) {
override fun perform(target: String?, parameters: Map<String, String?>) {
when (target) {
NEW_PROJECT_TARGET -> showCreateNewProjectWizard(parameters)
}
}
private fun showCreateNewProjectWizard(parameters: Map<String, String?>) {
val template = parameters[NEW_PROJECT_TARGET_TEMPLATE_PARAMETER]
?.let(ProjectTemplate.Companion::byId)
NewWizardOpener.open(template)
}
companion object {
private const val COMMAND_NAME = "kotlin-wizard"
private const val NEW_PROJECT_TARGET = "create-project"
private const val NEW_PROJECT_TARGET_TEMPLATE_PARAMETER = "template"
}
}
@@ -55,7 +55,10 @@ class ProjectTemplateSettingComponent(
super.onValueUpdated(reference)
if (reference == ProjectTemplatesPlugin::template.reference) {
applySelectedTemplate()
value?.let(templateDescriptionComponent::setTemplate)
value?.let { template ->
list.setSelectedValue(template, true)
templateDescriptionComponent.setTemplate(template)
}
}
}
@@ -150,5 +150,6 @@
<fileEditorProvider implementation="org.jetbrains.kotlin.idea.scratch.ui.KtScratchFileEditorProvider"/>
<moduleBuilder builderClass="org.jetbrains.kotlin.tools.projectWizard.wizard.NewProjectWizardModuleBuilder"/>
<jbProtocolCommand implementation="org.jetbrains.kotlin.tools.projectWizard.wizard.OpenNewProjectWizardProtocolCommand"/>
</extensions>
</idea-plugin>