Skip to content

Commit 60f11ca

Browse files
committed
feat(gui): enhance file loading and display in WorkspacePanel #358
- Load and display recent files from EditorHistoryManager - Implement special styling for recent files - Refactor file loading logic to improve performance - Update UI to show file path and name for all files
1 parent 1ea63a7 commit 60f11ca

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/WorkspacePanel.kt

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
package cc.unitmesh.devti.gui.chat.ui
22

3+
import cc.unitmesh.devti.util.canBeAdded
34
import com.intellij.icons.AllIcons
45
import com.intellij.openapi.fileChooser.FileChooser
56
import com.intellij.openapi.fileChooser.FileChooserDescriptor
7+
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
68
import com.intellij.openapi.project.Project
9+
import com.intellij.openapi.roots.ProjectFileIndex
10+
import com.intellij.openapi.ui.popup.JBPopup
11+
import com.intellij.openapi.ui.popup.JBPopupFactory
712
import com.intellij.openapi.vfs.VirtualFile
813
import com.intellij.ui.JBColor
14+
import com.intellij.ui.awt.RelativePoint
915
import com.intellij.ui.components.JBLabel
1016
import com.intellij.util.ui.JBUI
17+
import com.intellij.util.ui.UIUtil
18+
import org.jetbrains.annotations.NotNull
1119
import java.awt.*
1220
import java.awt.event.MouseAdapter
1321
import java.awt.event.MouseEvent
14-
import javax.swing.JPanel
15-
import javax.swing.JList
16-
import javax.swing.ListCellRenderer
17-
import javax.swing.UIManager
18-
import javax.swing.JTextField
19-
import javax.swing.JScrollPane
20-
import javax.swing.DefaultListModel
21-
import javax.swing.BorderFactory
22+
import javax.swing.*
2223
import javax.swing.event.DocumentEvent
2324
import javax.swing.event.DocumentListener
24-
import com.intellij.openapi.ui.popup.JBPopupFactory
25-
import com.intellij.openapi.ui.popup.JBPopup
26-
import com.intellij.openapi.roots.ProjectRootManager
27-
import com.intellij.openapi.vfs.VfsUtil
28-
import com.intellij.ui.awt.RelativePoint
29-
import com.intellij.util.ui.UIUtil
30-
import org.jetbrains.annotations.NotNull
31-
import javax.swing.Box
32-
import javax.swing.BoxLayout
33-
import javax.swing.JComponent
3425

3526
class WorkspacePanel(
3627
private val project: Project,
@@ -148,15 +139,22 @@ class FileSearchPopup(
148139
}
149140

150141
private fun loadProjectFiles() {
151-
val projectRootManager = ProjectRootManager.getInstance(project)
152-
val roots = projectRootManager.contentRoots
142+
allProjectFiles.clear()
143+
EditorHistoryManager.getInstance(project).fileList.forEach { file ->
144+
if (file.canBeAdded(project)) {
145+
allProjectFiles.add(FileItem(file, isRecentFile = true))
146+
}
147+
}
153148

154-
roots.forEach { root ->
155-
VfsUtil.collectChildrenRecursively(root).forEach { file ->
156-
if (!file.isDirectory) {
157-
allProjectFiles.add(FileItem(file))
158-
}
149+
ProjectFileIndex.getInstance(project).iterateContent { file ->
150+
if (file.canBeAdded(project) &&
151+
!ProjectFileIndex.getInstance(project).isUnderIgnored(file) &&
152+
ProjectFileIndex.getInstance(project).isInContent(file) &&
153+
!allProjectFiles.any { it.file.path == file.path }) {
154+
155+
allProjectFiles.add(FileItem(file))
159156
}
157+
true
160158
}
161159

162160
updateFileList("")
@@ -173,7 +171,6 @@ class FileSearchPopup(
173171
}
174172
})
175173

176-
// Setup file list
177174
fileList.cellRenderer = FileListCellRenderer()
178175
fileList.addMouseListener(object : MouseAdapter() {
179176
override fun mouseClicked(e: MouseEvent) {
@@ -187,7 +184,6 @@ class FileSearchPopup(
187184
}
188185
})
189186

190-
// Layout components
191187
contentPanel.add(searchField, BorderLayout.NORTH)
192188
contentPanel.add(JScrollPane(fileList), BorderLayout.CENTER)
193189
contentPanel.preferredSize = minPopupSize
@@ -225,7 +221,10 @@ class FileSearchPopup(
225221
popup?.show(RelativePoint(component, Point(leftOffset, -minPopupSize.height + topOffset)))
226222
}
227223

228-
data class FileItem(val file: VirtualFile) {
224+
data class FileItem(
225+
val file: VirtualFile,
226+
val isRecentFile: Boolean = false
227+
) {
229228
val icon = file.fileType.icon
230229
val name = file.name
231230
val path = file.path
@@ -258,6 +257,11 @@ class FileSearchPopup(
258257
pathLabel.font = UIUtil.getFont(UIUtil.FontSize.SMALL, pathLabel.font)
259258
pathLabel.foreground = UIUtil.getContextHelpForeground()
260259

260+
// Special styling for recent files
261+
if (it.isRecentFile) {
262+
fileLabel.foreground = JBColor(0x0087FF, 0x589DF6)
263+
}
264+
261265
infoPanel.add(fileLabel)
262266
infoPanel.add(pathLabel)
263267
infoPanel.add(Box.createHorizontalGlue()) // This makes the layout adapt to width
@@ -410,4 +414,3 @@ class WrapLayout : FlowLayout {
410414
}
411415
}
412416
}
413-

0 commit comments

Comments
 (0)