@@ -2,93 +2,112 @@ package com.github.blarc.ai.commits.intellij.plugin.settings
22
33import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle
44import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
5+ import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClient
56import com.github.blarc.ai.commits.intellij.plugin.settings.clients.LLMClientTable
67import com.github.blarc.ai.commits.intellij.plugin.settings.prompts.Prompt
78import com.github.blarc.ai.commits.intellij.plugin.settings.prompts.PromptTable
89import com.intellij.openapi.options.BoundConfigurable
910import com.intellij.openapi.ui.ComboBox
1011import com.intellij.ui.CommonActionsPanel
1112import com.intellij.ui.ToolbarDecorator
12- import com.intellij.ui.components.JBLabel
1313import com.intellij.ui.dsl.builder.*
1414import java.util.*
1515
1616class AppSettingsConfigurable : BoundConfigurable (message("settings.general.group.title")) {
1717
1818 private val llmClientTable = LLMClientTable ()
19- private val promptTable = PromptTable ()
2019 private lateinit var llmClientToolbarDecorator: ToolbarDecorator
20+ private lateinit var llmClientComboBox: ComboBox <LLMClient >
21+ private val promptTable = PromptTable ()
2122 private lateinit var toolbarDecorator: ToolbarDecorator
22- private lateinit var promptComboBox: Cell < ComboBox <Prompt > >
23+ private lateinit var promptComboBox: ComboBox <Prompt >
2324
2425 override fun createPanel () = panel {
2526
26- group(JBLabel (" OpenAI" )) {
27- row {
28- llmClientToolbarDecorator = ToolbarDecorator .createDecorator(llmClientTable.table)
29- .setAddAction {
30- llmClientTable.addLlmClient()
27+ row {
28+ label(message(" settings.llmClient" )).widthGroup(" labelPrompt" )
29+ llmClientComboBox = comboBox(AppSettings2 .instance.llmClients, AICommitsListCellRenderer ())
30+ .bindItem(getter = AppSettings2 .instance::getActiveLLMClient) {
31+ it?.let {
32+ AppSettings2 .instance.setActiveLlmClient(it)
3133 }
32- .disableUpDownActions()
33-
34- cell(llmClientToolbarDecorator.createPanel())
35- .align(Align .FILL )
36- }
34+ }.widthGroup(" input" )
35+ .component
3736 }
38-
39- group(JBLabel (" Prompt" )) {
40- row {
41- label(message(" settings.locale" )).widthGroup(" labelPrompt" )
42- comboBox(Locale .getAvailableLocales()
43- .distinctBy { it.displayLanguage }
44- .sortedBy { it.displayLanguage },
45- AppSettingsListCellRenderer ()
46- )
47- .bindItem(AppSettings2 .instance::locale.toNullableProperty())
48- browserLink(message(" settings.more-prompts" ), AICommitsBundle .URL_PROMPTS_DISCUSSION .toString())
49- .align(AlignX .RIGHT )
50- }
51- row {
52- label(message(" settings.prompt" )).widthGroup(" labelPrompt" )
53- promptComboBox = comboBox(AppSettings2 .instance.prompts.values, AppSettingsListCellRenderer ())
54- .bindItem(AppSettings2 .instance::activePrompt.toNullableProperty())
55- }
56- row {
57- toolbarDecorator = ToolbarDecorator .createDecorator(promptTable.table)
58- .setAddAction {
59- promptTable.addPrompt().let {
60- promptComboBox.component.addItem(it)
61- }
62- }
63- .setEditAction {
64- promptTable.editPrompt()?.let {
65- val editingSelected = promptComboBox.component.selectedItem == it.first
66- promptComboBox.component.removeItem(it.first)
67- promptComboBox.component.addItem(it.second)
68-
69- if (editingSelected) {
70- promptComboBox.component.selectedItem = it.second
71- }
72- }
37+ row {
38+ llmClientToolbarDecorator = ToolbarDecorator .createDecorator(llmClientTable.table)
39+ .setAddAction {
40+ llmClientTable.addLlmClient()
41+ }
42+ .setEditAction {
43+ llmClientTable.editLlmClient()
44+ }
45+ .setRemoveAction {
46+ llmClientTable.removeLlmClient()?.let {
47+ llmClientComboBox.removeItem(it)
7348 }
74- .setEditActionUpdater {
75- updateActionAvailability(CommonActionsPanel .Buttons .EDIT )
76- true
49+ }
50+ .disableUpDownActions()
51+
52+ cell(llmClientToolbarDecorator.createPanel())
53+ .align(Align .FILL )
54+ }.resizableRow()
55+
56+ row {
57+ label(message(" settings.locale" )).widthGroup(" labelPrompt" )
58+ comboBox(Locale .getAvailableLocales()
59+ .distinctBy { it.displayLanguage }
60+ .sortedBy { it.displayLanguage },
61+ AICommitsListCellRenderer ()
62+ )
63+ .widthGroup(" input" )
64+ .bindItem(AppSettings2 .instance::locale.toNullableProperty())
65+
66+ browserLink(message(" settings.more-prompts" ), AICommitsBundle .URL_PROMPTS_DISCUSSION .toString())
67+ .align(AlignX .RIGHT )
68+ }
69+ row {
70+ label(message(" settings.prompt" )).widthGroup(" labelPrompt" )
71+ promptComboBox = comboBox(AppSettings2 .instance.prompts.values, AICommitsListCellRenderer ())
72+ .bindItem(AppSettings2 .instance::activePrompt.toNullableProperty())
73+ .widthGroup(" input" )
74+ .component
75+ }
76+ row {
77+ toolbarDecorator = ToolbarDecorator .createDecorator(promptTable.table)
78+ .setAddAction {
79+ promptTable.addPrompt().let {
80+ promptComboBox.addItem(it)
7781 }
78- .setRemoveAction {
79- promptTable.removePrompt()?.let {
80- promptComboBox.component.removeItem(it)
82+ }
83+ .setEditAction {
84+ promptTable.editPrompt()?.let {
85+ val editingSelected = promptComboBox.selectedItem == it.first
86+ promptComboBox.removeItem(it.first)
87+ promptComboBox.addItem(it.second)
88+
89+ if (editingSelected) {
90+ promptComboBox.selectedItem = it.second
8191 }
8292 }
83- .setRemoveActionUpdater {
84- updateActionAvailability(CommonActionsPanel .Buttons .REMOVE )
85- true
93+ }
94+ .setEditActionUpdater {
95+ updateActionAvailability(CommonActionsPanel .Buttons .EDIT )
96+ true
97+ }
98+ .setRemoveAction {
99+ promptTable.removePrompt()?.let {
100+ promptComboBox.removeItem(it)
86101 }
87- .disableUpDownActions()
102+ }
103+ .setRemoveActionUpdater {
104+ updateActionAvailability(CommonActionsPanel .Buttons .REMOVE )
105+ true
106+ }
107+ .disableUpDownActions()
88108
89- cell(toolbarDecorator.createPanel())
90- .align(Align .FILL )
91- }.resizableRow()
109+ cell(toolbarDecorator.createPanel())
110+ .align(Align .FILL )
92111 }.resizableRow()
93112
94113 row {
@@ -103,18 +122,20 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
103122 }
104123
105124 override fun isModified (): Boolean {
106- return super .isModified() || promptTable.isModified()
125+ return super .isModified() || promptTable.isModified() || llmClientTable.isModified()
107126 }
108127
109128 override fun apply () {
110129 // TODO @Blarc
111130 // AppSettings2.instance.getActiveLLMClient().hosts.add(hostComboBox.item)
112131 promptTable.apply ()
132+ llmClientTable.apply ()
113133 super .apply ()
114134 }
115135
116136 override fun reset () {
117137 promptTable.reset()
138+ llmClientTable.reset()
118139 super .reset()
119140 }
120141
0 commit comments