Wizard: add project preview
This commit is contained in:
+46
-3
@@ -1,15 +1,31 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep
|
||||
|
||||
import com.intellij.ui.JBColor
|
||||
import com.intellij.util.ui.JBUI
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectTemplates.ProjectTemplatesPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.WizardStepComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor.ModulesEditorComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingsList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent
|
||||
import javax.swing.JComponent
|
||||
|
||||
class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.context) {
|
||||
private val context = wizard.context
|
||||
private val projectSettingsComponent = ProjectSettingsComponent(context).asSubComponent()
|
||||
private val projectPreviewComponent = ProjectPreviewComponent(context).asSubComponent()
|
||||
|
||||
override val component: JComponent = borderPanel {
|
||||
addToCenter(projectSettingsComponent.component)
|
||||
addToRight(projectPreviewComponent.component)
|
||||
}
|
||||
}
|
||||
|
||||
class ProjectSettingsComponent(context: Context) : DynamicComponent(context) {
|
||||
private val projectTemplateComponent = ProjectTemplateSettingComponent(context).asSubComponent()
|
||||
private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent()
|
||||
|
||||
@@ -20,8 +36,35 @@ class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.c
|
||||
projectTemplateComponent,
|
||||
buildSystemSetting
|
||||
),
|
||||
wizard.context
|
||||
context
|
||||
).asSubComponent()
|
||||
|
||||
override val component: JComponent = nameAndLocationComponent.component
|
||||
override val component: JComponent = nameAndLocationComponent.component.apply {
|
||||
border = JBUI.Borders.empty(10)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ProjectPreviewComponent(context: Context) : DynamicComponent(context) {
|
||||
private val modulesEditorComponent = ModulesEditorComponent(
|
||||
context,
|
||||
null,
|
||||
needBorder = false,
|
||||
editable = false,
|
||||
oneEntrySelected = {},
|
||||
selectSettingWithError = {}
|
||||
).asSubComponent()
|
||||
|
||||
override val component: JComponent = borderPanel {
|
||||
border = JBUI.Borders.empty(10)
|
||||
addToTop(label("Preview", bold = true).addBorder(JBUI.Borders.emptyBottom(5)))
|
||||
addToCenter(modulesEditorComponent.component)
|
||||
}.addBorder(JBUI.Borders.customLine(JBColor.border(), 0, /*left*/1, 0, 0))
|
||||
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
super.onValueUpdated(reference)
|
||||
if (reference == ProjectTemplatesPlugin::template.reference) {
|
||||
modulesEditorComponent.updateModel()
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ class ProjectTemplateSettingComponent(
|
||||
override val component: JComponent = panel {
|
||||
add(list, BorderLayout.CENTER)
|
||||
add(
|
||||
templateDescriptionComponent.component.withBorder(JBUI.Borders.emptyTop(5)),
|
||||
templateDescriptionComponent.component.addBorder(JBUI.Borders.emptyTop(5)),
|
||||
BorderLayout.SOUTH
|
||||
)
|
||||
}
|
||||
|
||||
+4
-2
@@ -43,8 +43,10 @@ class ModulesEditorSubStep(
|
||||
private val moduleSettingComponent = ModulesEditorComponent(
|
||||
context,
|
||||
uiEditorUsagesStats,
|
||||
onNodeSelected,
|
||||
selectSettingWithError
|
||||
needBorder = true,
|
||||
editable = true,
|
||||
oneEntrySelected = onNodeSelected,
|
||||
selectSettingWithError = selectSettingWithError
|
||||
).asSubComponent()
|
||||
|
||||
override fun buildContent(): JComponent = panel {
|
||||
|
||||
+13
-6
@@ -17,10 +17,11 @@ import java.awt.BorderLayout
|
||||
import javax.swing.BorderFactory
|
||||
import javax.swing.JComponent
|
||||
|
||||
|
||||
class ModulesEditorComponent(
|
||||
context: Context,
|
||||
uiEditorUsagesStats: UiEditorUsageStats,
|
||||
uiEditorUsagesStats: UiEditorUsageStats?,
|
||||
needBorder: Boolean,
|
||||
editable: Boolean,
|
||||
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit,
|
||||
selectSettingWithError: (ValidationResult.ValidationError) -> Unit
|
||||
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, context) {
|
||||
@@ -45,23 +46,29 @@ class ModulesEditorComponent(
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
updateModel()
|
||||
}
|
||||
|
||||
fun updateModel() {
|
||||
model.update()
|
||||
}
|
||||
|
||||
private val moduleCreator = NewModuleCreator()
|
||||
|
||||
private val toolbarDecorator = ModulesEditorToolbarDecorator(
|
||||
private val toolbarDecorator = if (editable) ModulesEditorToolbarDecorator(
|
||||
tree = tree,
|
||||
moduleCreator = moduleCreator,
|
||||
model = model,
|
||||
getModules = { value ?: emptyList() },
|
||||
isMultiplatformProject = { KotlinPlugin::projectKind.value != ProjectKind.Singleplatform }
|
||||
)
|
||||
) else null
|
||||
|
||||
override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) {
|
||||
panel {
|
||||
border = BorderFactory.createLineBorder(JBColor.border())
|
||||
add(toolbarDecorator.createToolPanel(), BorderLayout.CENTER)
|
||||
if (needBorder) {
|
||||
border = BorderFactory.createLineBorder(JBColor.border())
|
||||
}
|
||||
add(if (editable) toolbarDecorator!!.createToolPanel() else tree, BorderLayout.CENTER)
|
||||
add(validationIndicator, BorderLayout.SOUTH)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ class TargetsModel(
|
||||
private val tree: ModulesEditorTree,
|
||||
private val value: KMutableProperty0<List<Module>?>,
|
||||
private val context: Context,
|
||||
private val uiEditorUsagesStats: UiEditorUsageStats
|
||||
private val uiEditorUsagesStats: UiEditorUsageStats?
|
||||
) {
|
||||
private val root get() = tree.model.root as DefaultMutableTreeNode
|
||||
|
||||
@@ -63,7 +63,7 @@ class TargetsModel(
|
||||
}
|
||||
|
||||
fun add(module: Module) {
|
||||
uiEditorUsagesStats.modulesCreated++
|
||||
uiEditorUsagesStats?.modulesCreated?.inc()
|
||||
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
||||
context.writeSettings {
|
||||
module.apply { initDefaultValuesForSettings() }
|
||||
@@ -80,7 +80,7 @@ class TargetsModel(
|
||||
|
||||
fun removeSelected() {
|
||||
val selectedNode = tree.selectedNode?.takeIf { it.userObject is Module } ?: return
|
||||
uiEditorUsagesStats.modulesRemoved++
|
||||
uiEditorUsagesStats?.modulesRemoved?.inc()
|
||||
when (val parent = selectedNode.parent.safeAs<DefaultMutableTreeNode>()?.userObject) {
|
||||
ModulesEditorTree.PROJECT_USER_OBJECT -> {
|
||||
val index = selectedNode.parent.getIndex(selectedNode)
|
||||
|
||||
+5
-1
@@ -12,6 +12,7 @@ import com.intellij.ui.*
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.ui.components.JBTextField
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Failure
|
||||
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.ModuleConfigurator
|
||||
@@ -40,6 +41,9 @@ internal inline fun label(text: String, bold: Boolean = false, init: JBLabel.()
|
||||
|
||||
inline fun panel(layout: LayoutManager = BorderLayout(), init: JPanel.() -> Unit = {}) = JPanel(layout).apply(init)
|
||||
|
||||
inline fun borderPanel(init: BorderLayoutPanel.() -> Unit = {}) = BorderLayoutPanel().apply(init)
|
||||
|
||||
|
||||
fun textField(defaultValue: String?, onUpdated: (value: String) -> Unit) =
|
||||
JBTextField(defaultValue)
|
||||
.withOnUpdatedListener(onUpdated)
|
||||
@@ -172,7 +176,7 @@ fun <C : JComponent> C.bordered(
|
||||
)
|
||||
}
|
||||
|
||||
fun <C : JComponent> C.withBorder(border: Border): C = apply {
|
||||
fun <C : JComponent> C.addBorder(border: Border): C = apply {
|
||||
this.border = BorderFactory.createCompoundBorder(border, this.border)
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
|
||||
|
||||
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
@@ -111,9 +110,9 @@ data class BuildFileData(
|
||||
)
|
||||
|
||||
enum class BuildSystemType(override val text: String) : DisplayableSettingItem {
|
||||
GradleKotlinDsl("Gradle (Kotlin DSL)"),
|
||||
GradleGroovyDsl("Gradle (Groovy DSL)"),
|
||||
Jps("IDEA Build System"),
|
||||
GradleKotlinDsl("Gradle Kotlin"),
|
||||
GradleGroovyDsl("Gradle Groovy"),
|
||||
Jps("IntelliJ"),
|
||||
Maven("Maven")
|
||||
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user