Skip to content

Commit

Permalink
feat: use single binding
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2023
1 parent 56ab3ec commit 9092752
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -12,7 +12,7 @@ pluginUntilBuild = 231.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2022.1.4
platformVersion = 2022.3.2

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
25 changes: 12 additions & 13 deletions src/main/kotlin/cc/unitmesh/devti/runconfig/DtRunConfiguration.kt
Expand Up @@ -20,7 +20,6 @@ import org.jdom.Element
class DtRunConfiguration(project: Project, name: String, factory: ConfigurationFactory) :
RunConfigurationBase<DtRunConfigurationOptions>(project, factory, name) {


public override fun getOptions(): DtRunConfigurationOptions {
return super.getOptions() as DtRunConfigurationOptions
}
Expand Down Expand Up @@ -56,18 +55,18 @@ class DtRunConfiguration(project: Project, name: String, factory: ConfigurationF
element.writeString("openAiMaxTokens", runConfigure.openAiMaxTokens.toString())
}

// override fun readExternal(element: Element) {
// super.readExternal(element)
//
// val runConfigure = DevtiConfigure("", "", "", 4096, 0.0f)
//
// element.readString("githubToken")?.let { runConfigure.githubToken = it }
// element.readString("openAiApiKey")?.let { runConfigure.openAiApiKey = it }
// element.readString("openAiEngine")?.let { runConfigure.openAiEngine = it }
// element.readString("openAiMaxTokens")?.let { runConfigure.openAiMaxTokens = it.toInt() }
//
// this.options.fromConfigure(runConfigure)
// }
override fun readExternal(element: Element) {
super.readExternal(element)

val runConfigure = DevtiConfigure("", "", "", 4096, 0.0f)

element.readString("githubToken")?.let { runConfigure.githubToken = it }
element.readString("openAiApiKey")?.let { runConfigure.openAiApiKey = it }
element.readString("openAiEngine")?.let { runConfigure.openAiEngine = it }
element.readString("openAiMaxTokens")?.let { runConfigure.openAiMaxTokens = it.toInt() }

this.options.setFrom(runConfigure)
}
}

fun Element.writeString(name: String, value: String) {
Expand Down
58 changes: 32 additions & 26 deletions src/main/kotlin/cc/unitmesh/devti/runconfig/ui/DtSettingsEditor.kt
Expand Up @@ -2,10 +2,11 @@ package cc.unitmesh.devti.runconfig.ui

import cc.unitmesh.devti.runconfig.DevtiConfigure
import cc.unitmesh.devti.runconfig.DtRunConfiguration
import cc.unitmesh.devti.runconfig.DtRunConfigurationOptions
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Row
import com.intellij.ui.dsl.builder.bindIntText
import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.bindText
Expand All @@ -14,37 +15,24 @@ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import javax.swing.JComponent

class DtSettingsEditor(project: Project) : SettingsEditor<DtRunConfiguration>() {
private var githubToken: String = ""
private var completionProvider = DtCommandCompletionProvider()
private var openAiApiKey: String = ""
private var openAiEngine: String = "gpt-3.5-turbo"
private var openAiMaxTokens: Int = 4096

private lateinit var myPanel: JComponent

override fun applyEditorTo(configuration: DtRunConfiguration) {
logger.warn("github:$githubToken")
configuration.setOptions(
DevtiConfigure(
githubToken,
openAiApiKey,
openAiEngine,
openAiMaxTokens,
0.0f
)
)
}
private var panel: JComponent? = null

private val githubInput = DtCommandLineEditor(project, completionProvider)
override fun createEditor(): JComponent = panel {
row("Github Token:") {
textField()
.bindText(::githubToken)
.horizontalAlign(HorizontalAlign.FILL).resizableColumn()
row {
label("Github Token:")
fullWidthCell(githubInput)
}

row("OpenAI API Key:") {
textField()
.bindText(::openAiApiKey)
.horizontalAlign(HorizontalAlign.FILL).resizableColumn()
.bindText(::openAiApiKey)
}

row("API Engine:") {
Expand All @@ -54,19 +42,37 @@ class DtSettingsEditor(project: Project) : SettingsEditor<DtRunConfiguration>()
row("Max Token") {
intTextField(0..32768).bindIntText(::openAiMaxTokens)
}
}.apply {
myPanel = this
}.also {
panel = it
}

override fun resetEditorFrom(configuration: DtRunConfiguration) {
val configure = configuration.options.toConfigure()
githubToken = configure.githubToken
githubInput.text = configure.githubToken
openAiApiKey = configure.openAiApiKey
openAiEngine = configure.openAiEngine
openAiMaxTokens = configure.openAiMaxTokens
};
}

override fun applyEditorTo(configuration: DtRunConfiguration) {
logger.warn("github text:${githubInput.text}")
configuration.setOptions(
DevtiConfigure(
githubInput.text,
openAiApiKey,
openAiEngine,
openAiMaxTokens,
0.0f
)
)
}

companion object {
val logger = Logger.getInstance(DtRunConfigurationOptions::class.java)
val logger = Logger.getInstance(DtSettingsEditor::class.java)
}
}

fun <T : JComponent> Row.fullWidthCell(component: T): Cell<T> {
return cell(component)
.horizontalAlign(HorizontalAlign.FILL)
}

0 comments on commit 9092752

Please sign in to comment.