1
1
package cc.unitmesh.devti.gui.chat.ui
2
2
3
+ import cc.unitmesh.devti.util.canBeAdded
3
4
import com.intellij.icons.AllIcons
4
5
import com.intellij.openapi.fileChooser.FileChooser
5
6
import com.intellij.openapi.fileChooser.FileChooserDescriptor
7
+ import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
6
8
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
7
12
import com.intellij.openapi.vfs.VirtualFile
8
13
import com.intellij.ui.JBColor
14
+ import com.intellij.ui.awt.RelativePoint
9
15
import com.intellij.ui.components.JBLabel
10
16
import com.intellij.util.ui.JBUI
17
+ import com.intellij.util.ui.UIUtil
18
+ import org.jetbrains.annotations.NotNull
11
19
import java.awt.*
12
20
import java.awt.event.MouseAdapter
13
21
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.*
22
23
import javax.swing.event.DocumentEvent
23
24
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
34
25
35
26
class WorkspacePanel (
36
27
private val project : Project ,
@@ -148,15 +139,22 @@ class FileSearchPopup(
148
139
}
149
140
150
141
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
+ }
153
148
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))
159
156
}
157
+ true
160
158
}
161
159
162
160
updateFileList(" " )
@@ -173,7 +171,6 @@ class FileSearchPopup(
173
171
}
174
172
})
175
173
176
- // Setup file list
177
174
fileList.cellRenderer = FileListCellRenderer ()
178
175
fileList.addMouseListener(object : MouseAdapter () {
179
176
override fun mouseClicked (e : MouseEvent ) {
@@ -187,7 +184,6 @@ class FileSearchPopup(
187
184
}
188
185
})
189
186
190
- // Layout components
191
187
contentPanel.add(searchField, BorderLayout .NORTH )
192
188
contentPanel.add(JScrollPane (fileList), BorderLayout .CENTER )
193
189
contentPanel.preferredSize = minPopupSize
@@ -225,7 +221,10 @@ class FileSearchPopup(
225
221
popup?.show(RelativePoint (component, Point (leftOffset, - minPopupSize.height + topOffset)))
226
222
}
227
223
228
- data class FileItem (val file : VirtualFile ) {
224
+ data class FileItem (
225
+ val file : VirtualFile ,
226
+ val isRecentFile : Boolean = false
227
+ ) {
229
228
val icon = file.fileType.icon
230
229
val name = file.name
231
230
val path = file.path
@@ -258,6 +257,11 @@ class FileSearchPopup(
258
257
pathLabel.font = UIUtil .getFont(UIUtil .FontSize .SMALL , pathLabel.font)
259
258
pathLabel.foreground = UIUtil .getContextHelpForeground()
260
259
260
+ // Special styling for recent files
261
+ if (it.isRecentFile) {
262
+ fileLabel.foreground = JBColor (0x0087FF , 0x589DF6 )
263
+ }
264
+
261
265
infoPanel.add(fileLabel)
262
266
infoPanel.add(pathLabel)
263
267
infoPanel.add(Box .createHorizontalGlue()) // This makes the layout adapt to width
@@ -410,4 +414,3 @@ class WrapLayout : FlowLayout {
410
414
}
411
415
}
412
416
}
413
-
0 commit comments