Skip to content

Commit

Permalink
2023.3 creator fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 14, 2024
1 parent ccc0c77 commit 9a4867a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
14 changes: 8 additions & 6 deletions src/main/kotlin/creator/custom/CustomPlatformStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CustomPlatformStep(
lateinit var templatePropertyPlaceholder: Placeholder

builder.row(MCDevBundle("creator.ui.custom.repos.label")) {
segmentedButton(templateRepos) { it.name }
segmentedButton(templateRepos) { text = it.name }
.bind(templateRepoProperty)
}.visible(templateRepos.size > 1)

Expand Down Expand Up @@ -153,16 +153,18 @@ class CustomPlatformStep(

builder.row(MCDevBundle("creator.ui.custom.groups.label")) {
availableGroupsSegmentedButton =
segmentedButton(emptyList<String>(), String::toString)
segmentedButton(emptyList<String>()) { text = it }
.bind(selectedGroupProperty)
}.visibleIf(
availableGroupsProperty.transform { it.size > 1 }
)

builder.row(MCDevBundle("creator.ui.custom.templates.label")) {
availableTemplatesSegmentedButton =
segmentedButton(emptyList(), LoadedTemplate::label, LoadedTemplate::tooltip)
.bind(selectedTemplateProperty)
segmentedButton(emptyList()) { template: LoadedTemplate ->
text = template.label
toolTipText = template.tooltip
}.bind(selectedTemplateProperty)
.validation {
addApplyRule("", condition = ::hasTemplateErrors)
}
Expand All @@ -172,15 +174,15 @@ class CustomPlatformStep(

availableTemplatesProperty.afterChange { newTemplates ->
val groups = newTemplates.mapTo(linkedSetOf()) { it.descriptor.translatedGroup }
availableGroupsSegmentedButton.items(groups)
availableGroupsSegmentedButton.items = groups
// availableGroupsSegmentedButton.visible(groups.size > 1)
availableGroups = groups
selectedGroup = groups.firstOrNull() ?: "empty"
}

selectedGroupProperty.afterChange { group ->
val templates = availableTemplates.filter { it.descriptor.translatedGroup == group }
availableTemplatesSegmentedButton.items(templates)
availableTemplatesSegmentedButton.items = templates
// Force visiblity because the component might become hidden and not show up again
// when the segmented button switches between dropdown and buttons
availableTemplatesSegmentedButton.visible(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

package com.demonwav.mcdev.creator.custom.finalizers

import com.demonwav.mcdev.util.invokeAndWait
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import org.jetbrains.idea.maven.project.importing.MavenImportingManager
import kotlinx.coroutines.runBlocking
import org.jetbrains.idea.maven.buildtool.MavenImportSpec
import org.jetbrains.idea.maven.project.MavenProjectsManager

class ImportMavenProjectFinalizer : CreatorFinalizer {

Expand All @@ -38,25 +38,16 @@ class ImportMavenProjectFinalizer : CreatorFinalizer {
templateProperties: Map<String, Any?>
) {
val projectDir = context.projectFileDirectory

val pomFile = VfsUtil.findFile(Path.of(projectDir).resolve("pom.xml"), true)
?: return
thisLogger().info("Invoking import on EDT pomFile = ${pomFile.path}")
val promise = invokeAndWait {
if (project.isDisposed || !project.isInitialized) {
return@invokeAndWait null
}

MavenImportingManager.getInstance(project).linkAndImportFile(pomFile)
}

if (promise == null) {
thisLogger().info("Could not start import")
return
thisLogger().info("Invoking import on EDT pomFile = ${pomFile.path}")
val projectsManager = MavenProjectsManager.getInstance(project)
projectsManager.addManagedFiles(listOf(pomFile))
runBlocking {
projectsManager.updateAllMavenProjects(MavenImportSpec(true, true, false))
}

thisLogger().info("Waiting for import to finish")
promise.finishPromise.blockingGet(Int.MAX_VALUE, TimeUnit.SECONDS)
thisLogger().info("Import finished")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class SimpleCreatorProperty<T>(
it.validationOnApply(validation)
}
} else {
segmentedButton(options.keys) { options[it] ?: it.toString() }
segmentedButton(options.keys) { text = options[it] ?: it.toString() }
.bind(graphProperty)
.enabled(descriptor.editable != false)
.maxButtonsCount(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.demonwav.mcdev.platform.mixin.expression

import com.intellij.codeInsight.TailType
import com.intellij.codeInsight.TailTypes
import com.intellij.codeInsight.completion.BasicExpressionCompletionContributor
import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionParameters
Expand All @@ -38,8 +39,8 @@ class MEExpressionCompletionContributor : CompletionContributor() {
CompletionType.BASIC,
MEExpressionCompletionUtil.STATEMENT_KEYWORD_PLACE,
KeywordCompletionProvider(
Keyword("return", TailType.INSERT_SPACE),
Keyword("throw", TailType.INSERT_SPACE),
Keyword("return", TailTypes.insertSpaceType()),
Keyword("throw", TailTypes.insertSpaceType()),
)
)
extend(
Expand All @@ -51,7 +52,7 @@ class MEExpressionCompletionContributor : CompletionContributor() {
Keyword("true"),
Keyword("false"),
Keyword("null"),
Keyword("new", TailType.INSERT_SPACE),
Keyword("new", TailTypes.insertSpaceType()),
)
)
extend(
Expand All @@ -65,7 +66,7 @@ class MEExpressionCompletionContributor : CompletionContributor() {
CompletionType.BASIC,
MEExpressionCompletionUtil.INSTANCEOF_PLACE,
KeywordCompletionProvider(
Keyword("instanceof", TailType.INSERT_SPACE)
Keyword("instanceof", TailTypes.insertSpaceType())
)
)
extend(
Expand Down Expand Up @@ -123,7 +124,7 @@ class MEExpressionCompletionContributor : CompletionContributor() {
keywords.map { keyword ->
var lookupItem =
BasicExpressionCompletionContributor.createKeywordLookupItem(parameters.position, keyword.name)
if (keyword.tailType != TailType.NONE) {
if (keyword.tailType != TailTypes.noneType()) {
lookupItem = object : TailTypeDecorator<LookupElement>(lookupItem) {
override fun computeTailType(context: InsertionContext?) = keyword.tailType
}
Expand All @@ -134,5 +135,5 @@ class MEExpressionCompletionContributor : CompletionContributor() {
}
}

private class Keyword(val name: String, val tailType: TailType = TailType.NONE)
private class Keyword(val name: String, val tailType: TailType = TailTypes.noneType())
}

0 comments on commit 9a4867a

Please sign in to comment.