@@ -31,7 +31,7 @@ import javax.swing.table.DefaultTableCellRenderer
31
31
import kotlin.math.max
32
32
33
33
class LLMClientTable {
34
- private var llmClients = AppSettings2 .instance.llmClientConfigurations
34
+ private var llmClients = fetchSortedLlmClients()
35
35
private val tableModel = createTableModel()
36
36
37
37
val table = TableView (tableModel).apply {
@@ -60,33 +60,35 @@ class LLMClientTable {
60
60
llmClients.toList()
61
61
)
62
62
63
+ private fun fetchSortedLlmClients () = AppSettings2 .instance.llmClientConfigurations.sortedWith(
64
+ compareBy({ it.getClientName() }, { it.name })
65
+ )
66
+
67
+ private fun updateLlmClients (newClients : List <LLMClientConfiguration >) {
68
+ llmClients = newClients.sortedWith(compareBy({ it.getClientName() }, { it.name }))
69
+ refreshTableModel()
70
+ }
71
+
63
72
fun addLlmClient (): LLMClientConfiguration ? {
64
73
val dialog = LLMClientDialog ()
65
-
66
74
if (dialog.showAndGet()) {
67
- llmClients = llmClients.plus(dialog.llmClient)
68
- refreshTableModel()
75
+ updateLlmClients(llmClients + dialog.llmClient)
69
76
return dialog.llmClient
70
77
}
71
78
return null
72
79
}
73
80
74
81
fun removeLlmClient (): LLMClientConfiguration ? {
75
82
val selectedLlmClient = table.selectedObject ? : return null
76
- llmClients = llmClients.minus(selectedLlmClient)
77
- refreshTableModel()
83
+ updateLlmClients(llmClients - selectedLlmClient)
78
84
return selectedLlmClient
79
-
80
85
}
81
86
82
87
fun editLlmClient (): Pair <LLMClientConfiguration , LLMClientConfiguration >? {
83
88
val selectedLlmClient = table.selectedObject ? : return null
84
89
val dialog = LLMClientDialog (selectedLlmClient.clone())
85
-
86
90
if (dialog.showAndGet()) {
87
- llmClients = llmClients.minus(selectedLlmClient)
88
- llmClients = llmClients.plus(dialog.llmClient)
89
- refreshTableModel()
91
+ updateLlmClients(llmClients - selectedLlmClient + dialog.llmClient)
90
92
return selectedLlmClient to dialog.llmClient
91
93
}
92
94
return null
@@ -97,14 +99,14 @@ class LLMClientTable {
97
99
}
98
100
99
101
fun reset () {
100
- llmClients = AppSettings2 .instance.llmClientConfigurations
102
+ llmClients = fetchSortedLlmClients()
101
103
refreshTableModel()
102
104
}
103
105
104
- fun isModified () = llmClients != AppSettings2 .instance.llmClientConfigurations
106
+ fun isModified () = llmClients.toSet() != AppSettings2 .instance.llmClientConfigurations
105
107
106
108
fun apply () {
107
- AppSettings2 .instance.llmClientConfigurations = llmClients
109
+ AppSettings2 .instance.llmClientConfigurations = llmClients.toSet()
108
110
}
109
111
110
112
private class LLMClientDialog (val newLlmClientConfiguration : LLMClientConfiguration ? = null ) : DialogWrapper(true ) {
0 commit comments