Skip to content

Commit

Permalink
feat(counit): init for tool panel
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 24, 2023
1 parent 4eadf8e commit b2215ba
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
@@ -0,0 +1,49 @@
package cc.unitmesh.devti.settings.configurable

import cc.unitmesh.devti.AutoDevBundle
import com.intellij.openapi.Disposable
import com.intellij.openapi.options.BoundConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.util.Disposer
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Row
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import javax.swing.JComponent
import javax.swing.JTextField

class CoUnitToolConfigurable(project: Project) :
BoundConfigurable(AutoDevBundle.message("settings.external.counit.name")), Disposable {
private val pathToToolchainComboBox = CoUnitToolchainPathChoosingComboBox()
private val serverAddress = JTextField()
override fun createPanel(): DialogPanel = panel {
row {
checkBox(AutoDevBundle.message("settings.external.counit.enable.label"))
.comment(AutoDevBundle.message("settings.external.counit.enable.label.comment"))
// .bindSelected(project::enableCoUnit)
}

row(AutoDevBundle.message("settings.external.counit.server.address.label")) {
fullWidthCell(serverAddress)
// .bind(
// componentGet = { it.text },
// componentSet = { component, value -> component.text = value },
// prop = state::additionalArguments.toMutableProperty()
// )
}

row(AutoDevBundle.message("settings.external.counit.location.label")) {
fullWidthCell(pathToToolchainComboBox)
}
}

override fun dispose() {
Disposer.dispose(pathToToolchainComboBox)
}
}

fun <T : JComponent> Row.fullWidthCell(component: T): Cell<T> {
return cell(component)
.horizontalAlign(HorizontalAlign.FILL)
}
@@ -0,0 +1,11 @@
package cc.unitmesh.devti.settings.configurable

import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurableProvider
import com.intellij.openapi.project.Project

class CoUnitToolConfigurableProvider (private val project: Project) : ConfigurableProvider() {
override fun createConfigurable(): Configurable {
return CoUnitToolConfigurable(project)
}
}
@@ -0,0 +1,48 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package cc.unitmesh.devti.settings.configurable

import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.ui.ComboBoxWithWidePopup
import com.intellij.openapi.ui.ComponentWithBrowseButton
import com.intellij.ui.ComboboxSpeedSearch
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.components.fields.ExtendableTextField
import java.nio.file.Path
import java.nio.file.Paths
import javax.swing.event.DocumentEvent
import javax.swing.plaf.basic.BasicComboBoxEditor

class CoUnitToolchainPathChoosingComboBox(onTextChanged: () -> Unit = {}) :
ComponentWithBrowseButton<ComboBoxWithWidePopup<Path>>(ComboBoxWithWidePopup(), null) {
private val editor: BasicComboBoxEditor = object : BasicComboBoxEditor() {
override fun createEditorComponent(): ExtendableTextField = ExtendableTextField()
}

private val pathTextField: ExtendableTextField
get() = childComponent.editor.editorComponent as ExtendableTextField

init {
ComboboxSpeedSearch(childComponent)
childComponent.editor = editor
childComponent.isEditable = true

addActionListener {
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
FileChooser.chooseFile(descriptor, null, null) { file ->
childComponent.selectedItem = Paths.get(file.path)
}
}

pathTextField.document.addDocumentListener(
object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
onTextChanged()
}
}
)
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/autodev-core.xml
Expand Up @@ -12,6 +12,11 @@
id="cc.unitmesh.devti.settings.AutoDevSettingsConfigurable"
displayName="AutoDev"/>

<projectConfigurable provider="cc.unitmesh.devti.settings.configurable.CoUnitToolConfigurableProvider"
parentId="cc.unitmesh.devti.settings.AutoDevSettingsConfigurable"
id="cc.unitmesh.counit"
bundle="messages.AutoDevBundle" key="settings.external.counit.name"/>

<applicationService serviceImplementation="cc.unitmesh.devti.settings.AutoDevSettingsState"/>

<runConfigurationProducer
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -47,8 +47,8 @@ intentions.living.documentation.family.name=Generate documentation
intentions.request.background.process.title=LLM is processing your request
autodev.custom.response.format.placeholder=Use json path, for example: `$.choices[0].delta.content`
autodev.custom.prompt.placeholder=Custom your prompt here

# don't remove following line and don't rename them unless change [LLMSettingCOmpoent] class
settings.external.counit.name=CoUnit
settings.languageParam=Language
settings.customOpenAIHostParam=Custom OpenAI Host
settings.openAIKeyParam=OpenAI API key
Expand All @@ -66,3 +66,8 @@ settings.xingHuoApiKeyParam=XingHuo API Key
settings.xingHuoApiSecretParam=XingHuo API Secret
settings.xingHuoAppIDParam=XingHuo App ID
settings.customEngineResponseFormatParam=Custom Response Format (Json Path)
settings.external.counit.enable.label=Enable CoUnit (Experimental)
settings.external.counit.enable.label.comment=https://github.com/unit-mesh/co-unit
settings.external.counit.location.label=CoUnit Location (TODO, with JSON RPC) :
settings.external.counit.server.address.label=CoUnit Server address:

0 comments on commit b2215ba

Please sign in to comment.