@@ -191,10 +191,14 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
191
191
setupEditorListener()
192
192
setupRelatedListener()
193
193
194
- // / get current open file and add to the list
195
194
val currentFile = FileEditorManager .getInstance(project).selectedFiles.firstOrNull()
196
195
currentFile?.let {
197
196
listModel.addIfAbsent(currentFile, first = true )
197
+ val index = listModel.indexOf(currentFile)
198
+ if (index != - 1 ) {
199
+ listModel.remove(index)
200
+ listModel.insertElementAt(listModel.getElementAt(index), 0 )
201
+ }
198
202
}
199
203
}
200
204
@@ -231,45 +235,48 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
231
235
232
236
elementsList.addMouseListener(object : MouseAdapter () {
233
237
override fun mouseClicked (e : MouseEvent ) {
234
- val list = e.source as JBList <* >
235
- val index = list.locationToIndex(e.point)
236
- if (index == - 1 ) return
237
-
238
- val wrapper = listModel.getElementAt(index)
239
- val cellBounds = list.getCellBounds(index, index)
240
- wrapper.panel?.components?.firstOrNull { it.contains(e.x - cellBounds.x - it.x, it.height - 1 ) }
241
- ?.let { component ->
242
- when {
243
- component is JPanel -> {
244
- listModel.removeElement(wrapper)
245
- val vfile = wrapper.virtualFile
246
- val relativePath = vfile.path.substringAfter(project.basePath!! ).removePrefix(" /" )
247
- listModel.addIfAbsent(vfile)
248
-
249
- input.appendText(" \n /" + " file" + " :${relativePath} " )
250
- listModel.indexOf(wrapper.virtualFile).takeIf { it != - 1 }
251
- ?.let { listModel.remove(it) }
252
-
253
- // invoake later
254
- ApplicationManager .getApplication().invokeLater {
255
- val psiFile = PsiManager .getInstance(project).findFile(vfile) ? : return @invokeLater
256
- val relatedElements =
257
- RelatedClassesProvider .provide(psiFile.language)?.lookupIO(psiFile)
258
- updateElements(relatedElements)
259
- }
260
- }
261
-
262
- component is JLabel && component.icon == AllIcons .Actions .Close -> listModel.removeElement(
263
- wrapper
264
- )
265
-
266
- else -> list.clearSelection()
267
- }
268
- } ? : list.clearSelection()
238
+ calculateRelativeFile(e)
269
239
}
270
240
})
271
241
}
272
242
243
+ private fun calculateRelativeFile (e : MouseEvent ) {
244
+ val list = e.source as JBList <* >
245
+ val index = list.locationToIndex(e.point)
246
+ if (index == - 1 ) return
247
+
248
+ val wrapper = listModel.getElementAt(index)
249
+ val cellBounds = list.getCellBounds(index, index)
250
+ wrapper.panel?.components?.firstOrNull { it.contains(e.x - cellBounds.x - it.x, it.height - 1 ) }
251
+ ?.let { component ->
252
+ when {
253
+ component is JPanel -> {
254
+ listModel.removeElement(wrapper)
255
+ val vfile = wrapper.virtualFile
256
+ val relativePath = vfile.path.substringAfter(project.basePath!! ).removePrefix(" /" )
257
+ listModel.addIfAbsent(vfile)
258
+
259
+ input.appendText(" \n /" + " file" + " :${relativePath} " )
260
+ listModel.indexOf(wrapper.virtualFile).takeIf { it != - 1 }
261
+ ?.let { listModel.remove(it) }
262
+
263
+ ApplicationManager .getApplication().invokeLater {
264
+ val psiFile = PsiManager .getInstance(project).findFile(vfile) ? : return @invokeLater
265
+ val relatedElements =
266
+ RelatedClassesProvider .provide(psiFile.language)?.lookupIO(psiFile)
267
+ updateElements(relatedElements)
268
+ }
269
+ }
270
+
271
+ component is JLabel && component.icon == AllIcons .Actions .Close -> listModel.removeElement(
272
+ wrapper
273
+ )
274
+
275
+ else -> list.clearSelection()
276
+ }
277
+ } ? : list.clearSelection()
278
+ }
279
+
273
280
private fun updateElements (elements : List <PsiElement >? ) {
274
281
elements?.forEach { listModel.addIfAbsent(it.containingFile.virtualFile) }
275
282
}
0 commit comments