@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevIcons
5
5
import cc.unitmesh.devti.settings.customize.customizeSetting
6
6
import cc.unitmesh.devti.agent.custom.model.CustomAgentConfig
7
7
import cc.unitmesh.devti.agent.custom.model.CustomAgentState
8
+ import cc.unitmesh.devti.gui.chat.ui.viewmodel.FileListViewModel
8
9
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
9
10
import cc.unitmesh.devti.llms.tokenizer.TokenizerFactory
10
11
import cc.unitmesh.devti.provider.RelatedClassesProvider
@@ -72,8 +73,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
72
73
private val buttonPanel = JPanel (CardLayout ())
73
74
private val inputPanel = BorderLayoutPanel ()
74
75
75
- private val listModel = DefaultListModel < FilePresentation >( )
76
- private val elementsList = JBList (listModel )
76
+ private val fileListViewModel = FileListViewModel (project )
77
+ private val elementsList = JBList (fileListViewModel.getListModel() )
77
78
78
79
private val defaultRag: CustomAgentConfig = CustomAgentConfig (" <Select Custom Agent>" , " Normal" )
79
80
private var customRag: ComboBox <CustomAgentConfig > = ComboBox (MutableCollectionComboBoxModel (listOf ()))
@@ -173,7 +174,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
173
174
scrollPane.verticalScrollBarPolicy = JScrollPane .VERTICAL_SCROLLBAR_AS_NEEDED
174
175
scrollPane.horizontalScrollBarPolicy = JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED
175
176
176
- val toolbar = InputFileToolbar .createToolbar(project, this @AutoDevInputSection.listModel )
177
+ val toolbar = InputFileToolbar .createToolbar(project, fileListViewModel )
177
178
178
179
val headerPanel = JPanel (BorderLayout ())
179
180
headerPanel.add(toolbar, BorderLayout .NORTH )
@@ -199,12 +200,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
199
200
200
201
val currentFile = FileEditorManager .getInstance(project).selectedFiles.firstOrNull()
201
202
currentFile?.let {
202
- listModel.addIfAbsent(currentFile, first = true )
203
- val index = listModel.indexOf(currentFile)
204
- if (index != - 1 ) {
205
- listModel.remove(index)
206
- listModel.insertElementAt(listModel.getElementAt(index), 0 )
207
- }
203
+ fileListViewModel.addFileIfAbsent(currentFile, first = true )
208
204
}
209
205
}
210
206
@@ -215,7 +211,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
215
211
override fun selectionChanged (event : FileEditorManagerEvent ) {
216
212
val file = event.newFile ? : return
217
213
ApplicationManager .getApplication().invokeLater {
218
- listModel.addIfAbsent (file, true )
214
+ fileListViewModel.addFileIfAbsent (file, true )
219
215
}
220
216
}
221
217
}
@@ -251,20 +247,19 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
251
247
val index = list.locationToIndex(e.point)
252
248
if (index == - 1 ) return
253
249
254
- val wrapper = listModel .getElementAt(index)
250
+ val wrapper = fileListViewModel.getListModel() .getElementAt(index)
255
251
val cellBounds = list.getCellBounds(index, index)
256
252
wrapper.panel?.components?.firstOrNull { it.contains(e.x - cellBounds.x - it.x, it.height - 1 ) }
257
253
?.let { component ->
258
254
when {
259
255
component is JPanel -> {
260
- listModel.removeElement (wrapper)
256
+ fileListViewModel.removeFile (wrapper)
261
257
val vfile = wrapper.virtualFile
262
258
val relativePath = vfile.path.substringAfter(project.basePath!! ).removePrefix(" /" )
263
- listModel.addIfAbsent (vfile)
259
+ fileListViewModel.addFileIfAbsent (vfile)
264
260
265
261
input.appendText(" \n /" + " file" + " :${relativePath} " )
266
- listModel.indexOf(wrapper.virtualFile).takeIf { it != - 1 }
267
- ?.let { listModel.remove(it) }
262
+ fileListViewModel.removeFileByVirtualFile(wrapper.virtualFile)
268
263
269
264
ApplicationManager .getApplication().invokeLater {
270
265
if (! vfile.isValid) return @invokeLater
@@ -275,17 +270,15 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
275
270
}
276
271
}
277
272
278
- component is JLabel && component.icon == AllIcons .Actions .Close -> listModel.removeElement(
279
- wrapper
280
- )
273
+ component is JLabel && component.icon == AllIcons .Actions .Close -> fileListViewModel.removeFile(wrapper)
281
274
282
275
else -> list.clearSelection()
283
276
}
284
277
} ? : list.clearSelection()
285
278
}
286
279
287
280
private fun updateElements (elements : List <PsiElement >? ) {
288
- elements?.forEach { listModel.addIfAbsent (it.containingFile.virtualFile) }
281
+ elements?.forEach { fileListViewModel.addFileIfAbsent (it.containingFile.virtualFile) }
289
282
}
290
283
291
284
fun showStopButton () {
@@ -432,5 +425,3 @@ fun JComponent.mediumFontFunction() {
432
425
}
433
426
putClientProperty(FONT_KEY , f)
434
427
}
435
-
436
-
0 commit comments