|
| 1 | +package com.coder.gateway |
| 2 | + |
| 3 | +import com.coder.gateway.sdk.CoderCLIManager |
| 4 | +import com.coder.gateway.sdk.canWrite |
| 5 | +import com.coder.gateway.services.CoderSettingsState |
| 6 | +import com.intellij.openapi.components.service |
| 7 | +import com.intellij.openapi.options.BoundConfigurable |
| 8 | +import com.intellij.openapi.ui.DialogPanel |
| 9 | +import com.intellij.openapi.ui.ValidationInfo |
| 10 | +import com.intellij.ui.components.JBTextField |
| 11 | +import com.intellij.ui.dsl.builder.AlignX |
| 12 | +import com.intellij.ui.dsl.builder.bindText |
| 13 | +import com.intellij.ui.dsl.builder.panel |
| 14 | +import com.intellij.ui.layout.ValidationInfoBuilder |
| 15 | +import java.net.URL |
| 16 | +import java.nio.file.Path |
| 17 | + |
| 18 | +class CoderSettingsConfigurable : BoundConfigurable("Coder") { |
| 19 | + override fun createPanel(): DialogPanel { |
| 20 | + val state: CoderSettingsState = service() |
| 21 | + return panel { |
| 22 | + row(CoderGatewayBundle.message("gateway.connector.settings.binary-source.title")) { |
| 23 | + textField().resizableColumn().align(AlignX.FILL) |
| 24 | + .bindText(state::binarySource) |
| 25 | + .comment( |
| 26 | + CoderGatewayBundle.message( |
| 27 | + "gateway.connector.settings.binary-source.comment", |
| 28 | + CoderCLIManager(URL("http://localhost")).remoteBinaryURL.path, |
| 29 | + ) |
| 30 | + ) |
| 31 | + } |
| 32 | + row(CoderGatewayBundle.message("gateway.connector.settings.binary-destination.title")) { |
| 33 | + textField().resizableColumn().align(AlignX.FILL) |
| 34 | + .bindText(state::binaryDestination) |
| 35 | + .validationOnApply(validateBinaryDestination()) |
| 36 | + .validationOnInput(validateBinaryDestination()) |
| 37 | + .comment( |
| 38 | + CoderGatewayBundle.message( |
| 39 | + "gateway.connector.settings.binary-destination.comment", |
| 40 | + CoderCLIManager.getDataDir(), |
| 41 | + ) |
| 42 | + ) |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + private fun validateBinaryDestination(): ValidationInfoBuilder.(JBTextField) -> ValidationInfo? = { |
| 48 | + if (it.text.isNotBlank() && !Path.of(it.text).canWrite()) { |
| 49 | + error("Cannot write to this path") |
| 50 | + } else { |
| 51 | + null |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments