1
+ package cc.unitmesh.devti.gui.pair
2
+
3
+ import cc.unitmesh.devti.fullWidthCell
4
+ import cc.unitmesh.devti.gui.chat.AutoDevInputListener
5
+ import cc.unitmesh.devti.gui.chat.AutoDevInputSection
6
+ import cc.unitmesh.devti.gui.chat.AutoDevInputTrigger
7
+ import cc.unitmesh.devti.gui.chat.ChatRole
8
+ import cc.unitmesh.devti.pair.arch.ProjectPackageTree
9
+ import cc.unitmesh.devti.pair.tasking.Tasking
10
+ import cc.unitmesh.devti.provider.architecture.LayeredArchProvider
11
+ import cc.unitmesh.devti.util.parser.Code
12
+ import com.intellij.openapi.Disposable
13
+ import com.intellij.openapi.fileTypes.PlainTextLanguage
14
+ import com.intellij.openapi.project.Project
15
+ import com.intellij.openapi.ui.NullableComponent
16
+ import com.intellij.openapi.ui.SimpleToolWindowPanel
17
+ import com.intellij.temporary.gui.block.CodeBlock
18
+ import com.intellij.temporary.gui.block.CodeBlockView
19
+ import com.intellij.temporary.gui.block.SimpleMessage
20
+ import com.intellij.ui.dsl.builder.bindText
21
+ import com.intellij.ui.dsl.builder.panel
22
+
23
+ data class PairContext (
24
+ var input : String = " " ,
25
+ var tasks : List <Tasking > = listOf(),
26
+ var arch : ProjectPackageTree ? = null ,
27
+ )
28
+
29
+ class AutoDevPairToolWindow (val project : Project , val disposable : Disposable ) : SimpleToolWindowPanel(true , true ),
30
+ NullableComponent {
31
+ init {
32
+ val layeredArch = LayeredArchProvider .find(project)?.getLayeredArch(project)
33
+ val model = PairContext (arch = layeredArch)
34
+
35
+ // https://plugins.jetbrains.com/docs/intellij/kotlin-ui-dsl-version-2.html
36
+ val panel = panel {
37
+ row(" Your Task" ) {
38
+ text(" Your context-aware pair for help you!" )
39
+ textField()
40
+ .comment(" Your task for asking help!" )
41
+ .bindText(model::input)
42
+ }
43
+
44
+ row {
45
+ val inputSection = AutoDevInputSection (project, disposable)
46
+ inputSection.addListener(object : AutoDevInputListener {
47
+ override fun onSubmit (component : AutoDevInputSection , trigger : AutoDevInputTrigger ) {
48
+ val prompt = component.text
49
+ println (" prompt: $prompt " )
50
+ }
51
+ })
52
+ }
53
+ row {
54
+ val text = layeredArch?.print () ? : " No Layered Arch"
55
+ val block = CodeBlock (SimpleMessage (text, text, ChatRole .User ))
56
+ block.code = Code (PlainTextLanguage .INSTANCE , text, true )
57
+
58
+ val codeBlockView = CodeBlockView (block, project, disposable)
59
+ val component = codeBlockView.getComponent()
60
+
61
+ fullWidthCell(component)
62
+ }
63
+ }
64
+
65
+ setContent(panel)
66
+ }
67
+
68
+ override fun isNull (): Boolean {
69
+ return false
70
+ }
71
+ }
0 commit comments