Skip to content

Commit

Permalink
feat(gui): add AutoDevVariableListComponent and improve popup behavio…
Browse files Browse the repository at this point in the history
…r in AutoDevInputSection #51

The commit introduces a new class `AutoDevVariableListComponent` to the GUI package, which is a custom Swing component. Additionally, the commit modifies the `AutoDevInputSection` class to improve the behavior of the popup when the user inputs a specific character. The popup is now created lazily and reused if it's not disposed, ensuring better memory management and a smoother user experience.
  • Loading branch information
phodal committed Mar 6, 2024
1 parent 741dda8 commit 8b54522
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt
Expand Up @@ -36,6 +36,7 @@ import com.intellij.util.ui.JBEmptyBorder
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.components.BorderLayoutPanel
import com.intellij.vcsUtil.showAbove
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import java.awt.Color
Expand Down Expand Up @@ -105,16 +106,17 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab

// check new input == $
if (event.newFragment.contentEquals("$") || event.newFragment.contentEquals("¥")) {
popup?.show(this@AutoDevInputSection)
if (popup?.isDisposed == true) {
popup = createPopup()
popup?.showAbove(input)
} else {
popup?.showAbove(input)
}
}
}
}

popup = JBPopupFactory.getInstance().createComponentPopupBuilder(JTextField(""), null)
.setRequestFocus(false)
.setMinSize(
Dimension(200, 200)
).createPopup()
popup = createPopup()

input.addDocumentListener(documentListener)
input.recreateDocument()
Expand Down Expand Up @@ -167,6 +169,12 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
tokenizer = TokenizerImpl.INSTANCE
}

private fun createPopup() = JBPopupFactory.getInstance().createComponentPopupBuilder(AutoDevVariableListComponent(), null)
.setRequestFocus(false)
.setMinSize(
Dimension(200, 200)
).createPopup()


private fun loadRagApps(): List<CustomAgentConfig> {
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
Expand Down
@@ -0,0 +1,11 @@
package cc.unitmesh.devti.gui.chat

import javax.swing.JPanel

class AutoDevVariableListComponent : JPanel() {
init {
// TODO
isOpaque = true
}
}

0 comments on commit 8b54522

Please sign in to comment.