Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import com.fwdekker.randomness.array.ArrayDecorator.Companion.MIN_MIN_COUNT
import com.fwdekker.randomness.array.ArrayDecorator.Companion.PRESET_AFFIX_DECORATOR_DESCRIPTORS
import com.fwdekker.randomness.array.ArrayDecorator.Companion.PRESET_SEPARATORS
import com.fwdekker.randomness.ui.JIntSpinner
import com.fwdekker.randomness.ui.LiteralPredicate
import com.fwdekker.randomness.ui.UIConstants
import com.fwdekker.randomness.ui.bindCurrentText
import com.fwdekker.randomness.ui.bindIntValue
import com.fwdekker.randomness.ui.bindSpinners
import com.fwdekker.randomness.ui.decoratedRowRange
import com.fwdekker.randomness.ui.isEditable
import com.fwdekker.randomness.ui.loadMnemonic
import com.fwdekker.randomness.ui.ofConstant
import com.fwdekker.randomness.ui.withFixedWidth
import com.fwdekker.randomness.ui.withName
import com.intellij.ui.dsl.builder.BottomGap
Expand Down Expand Up @@ -52,7 +52,7 @@ class ArrayDecoratorEditor(
.withName("arrayEnabled")
.bindSelected(scheme::enabled)
.also { enabledCheckBox = it }
.also { isEnabled = enabledCheckBox.selected.or(LiteralPredicate(embedded)) }
.also { isEnabled = enabledCheckBox.selected.or(ComponentPredicate.ofConstant(embedded)) }
}.visible(!embedded)

decoratedRowRange(indent = !embedded) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.fwdekker.randomness.template

import com.fwdekker.randomness.Bundle
import com.fwdekker.randomness.Scheme
import com.intellij.ide.DataManager
import com.intellij.openapi.Disposable
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.options.ex.Settings
import com.intellij.openapi.util.Disposer
import java.awt.Component
import javax.swing.JComponent


Expand Down Expand Up @@ -76,6 +80,12 @@ class TemplateListConfigurable : Configurable, Disposable {
override fun reset() = editor.reset()


/**
* Explicitly selects the given scheme (based on its UUID).
*/
fun selectScheme(scheme: Scheme) = editor.selectScheme(scheme)


/**
* Recursively disposes this configurable's resources.
*/
Expand All @@ -86,3 +96,18 @@ class TemplateListConfigurable : Configurable, Disposable {
*/
override fun dispose() = Unit
}


/**
* Selects [scheme] in the currently open [TemplateListConfigurable], or does nothing if this is not possible for some
* reason.
*/
fun selectSchemeInSettings(context: Component, scheme: Scheme?) {
scheme ?: return

val id = "com.fwdekker.randomness.template.TemplateListConfigurable"
val settings = Settings.KEY.getData(DataManager.getInstance().getDataContext(context)) ?: return
val configurable = settings.find(id) as TemplateListConfigurable

configurable.selectScheme(scheme)
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class TemplateListEditor(
override fun dispose() = Unit


/**
* Explicitly selects the given scheme (based on its UUID).
*/
fun selectScheme(scheme: Scheme) {
templateTree.selectedScheme = scheme
}


/**
* Scrolls to the focused element within the [editor], registering this listener with the [focusManager], and
* automatically disposing itself when the [editor] is disposed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import com.fwdekker.randomness.template.TemplateReference.Companion.PRESET_AFFIX
import com.fwdekker.randomness.template.TemplateReference.Companion.PRESET_CAPITALIZATION
import com.fwdekker.randomness.ui.onResetThis
import com.fwdekker.randomness.ui.withName
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.ColoredListCellRenderer
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.listCellRenderer
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.builder.toNullableProperty
import com.intellij.ui.layout.ComboBoxPredicate
import javax.swing.JList


Expand All @@ -26,6 +28,8 @@ class TemplateReferenceEditor(scheme: TemplateReference) : SchemeEditor<Template
override val rootComponent = panel {
group(Bundle("reference.ui.value.header")) {
row(Bundle("reference.ui.value.template_option")) {
lateinit var templates: ComboBox<Template>

comboBox(emptyList(), TemplateCellRenderer())
.onResetThis { cell ->
cell.component.removeAllItems()
Expand All @@ -36,6 +40,10 @@ class TemplateReferenceEditor(scheme: TemplateReference) : SchemeEditor<Template
}
.withName("template")
.bindItem(scheme::template.toNullableProperty())
.also { templates = it.component }

link(Bundle("reference.ui.value.visit")) { selectSchemeInSettings(templates, scheme.template) }
.visibleIf(ComboBoxPredicate<Template>(templates) { it != null })
}

row(Bundle("reference.ui.value.capitalization_option")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,9 @@ fun <E> Cell<ComboBox<E>>.withFilter(filter: DocumentFilter): Cell<ComboBox<E>>


/**
* A predicate that always returns [output].
*/
class LiteralPredicate(private val output: Boolean) : ComponentPredicate() {
/**
* Does nothing, because there's no need to respond to any events to determine the output of [invoke].
*/
override fun addListener(listener: (Boolean) -> Unit) = Unit

/**
* Returns [output].
*/
override fun invoke() = output
}
* Returns a predicate that always returns [constant].
*/
fun ComponentPredicate.Companion.ofConstant(constant: Boolean) = if (constant) TRUE else FALSE

/**
* Returns a [ComponentPredicate] that evaluates [lambda] on the value of this [JIntSpinner].
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/randomness.properties
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ reference.error.recursion=Found recursion: %1$s
reference.ui.value.capitalization_option=&Capitalization:
reference.ui.value.header=Value
reference.ui.value.template_option=&Template:
reference.ui.value.visit=Go to target
reference.title=Reference
reporter.issue=Issue on GitHub
reporter.opening=Opening GitHub in browser
Expand Down