@@ -29,11 +29,11 @@ class FileSearchPopup(
29
29
private val onFilesSelected : (List <VirtualFile >) -> Unit
30
30
) {
31
31
private var popup: JBPopup ? = null
32
- private val fileListModel = DefaultListModel <FileItem >()
32
+ private val fileListModel = DefaultListModel <FilePresentation >()
33
33
private val fileList = JBList (fileListModel)
34
34
private val searchField = JTextField ()
35
35
private val contentPanel = JPanel (BorderLayout ())
36
- private val allProjectFiles = mutableListOf<FileItem >()
36
+ private val allProjectFiles = mutableListOf<FilePresentation >()
37
37
private val minPopupSize = Dimension (435 , 300 )
38
38
39
39
init {
@@ -45,18 +45,19 @@ class FileSearchPopup(
45
45
allProjectFiles.clear()
46
46
EditorHistoryManager .Companion .getInstance(project).fileList.forEach { file ->
47
47
if (file.canBeAdded(project)) {
48
- allProjectFiles.add(FileItem (file, isRecentFile = true ))
48
+ val presentation = FilePresentation .from(project, file)
49
+ presentation.isRecentFile = true
50
+ allProjectFiles.add(presentation)
49
51
}
50
52
}
51
53
52
54
ProjectFileIndex .getInstance(project).iterateContent { file ->
53
55
if (file.canBeAdded(project) &&
54
56
! ProjectFileIndex .getInstance(project).isUnderIgnored(file) &&
55
57
ProjectFileIndex .getInstance(project).isInContent(file) &&
56
- ! allProjectFiles.any { it.file. path == file.path }
58
+ ! allProjectFiles.any { it.path == file.path }
57
59
) {
58
-
59
- allProjectFiles.add(FileItem (file))
60
+ allProjectFiles.add(FilePresentation .from(project, file))
60
61
}
61
62
true
62
63
}
@@ -79,7 +80,7 @@ class FileSearchPopup(
79
80
fileList.addMouseListener(object : MouseAdapter () {
80
81
override fun mouseClicked (e : MouseEvent ) {
81
82
if (e.clickCount == 2 ) {
82
- val selectedFiles = fileList.selectedValuesList.map { it.file }
83
+ val selectedFiles = fileList.selectedValuesList.map { it.virtualFile }
83
84
if (selectedFiles.isNotEmpty()) {
84
85
onFilesSelected(selectedFiles)
85
86
popup?.cancel()
@@ -100,8 +101,8 @@ class FileSearchPopup(
100
101
allProjectFiles
101
102
} else {
102
103
allProjectFiles.filter { item ->
103
- item.file. name.contains(searchText, ignoreCase = true ) ||
104
- item.file. path.contains(searchText, ignoreCase = true )
104
+ item.name.contains(searchText, ignoreCase = true ) ||
105
+ item.path.contains(searchText, ignoreCase = true )
105
106
}
106
107
}
107
108
@@ -125,22 +126,13 @@ class FileSearchPopup(
125
126
popup?.show(RelativePoint (component, Point (leftOffset, - minPopupSize.height + topOffset)))
126
127
}
127
128
128
- data class FileItem (
129
- val file : VirtualFile ,
130
- val isRecentFile : Boolean = false
131
- ) {
132
- val icon = file.fileType.icon
133
- val name = file.name
134
- val path = file.path
135
- }
136
-
137
- class FileListCellRenderer : ListCellRenderer <FileItem > {
129
+ class FileListCellRenderer () : ListCellRenderer<FilePresentation> {
138
130
private val noBorderFocus = BorderFactory .createEmptyBorder(1 , 1 , 1 , 1 )
139
131
140
132
@NotNull
141
133
override fun getListCellRendererComponent (
142
- list : JList <out FileItem >? ,
143
- value : FileItem ,
134
+ list : JList <out FilePresentation >? ,
135
+ value : FilePresentation ,
144
136
index : Int ,
145
137
isSelected : Boolean ,
146
138
cellHasFocus : Boolean
@@ -152,7 +144,7 @@ class FileSearchPopup(
152
144
val fileLabel = JBLabel (value.name, value.icon, JBLabel .LEFT )
153
145
fileLabel.border = JBUI .Borders .emptyRight(8 )
154
146
155
- val relativePath = getRelativePath( value)
147
+ val relativePath = value.presentablePath
156
148
val pathLabel = JBLabel (" - $relativePath " , JBLabel .LEFT )
157
149
pathLabel.font = UIUtil .getFont(UIUtil .FontSize .SMALL , pathLabel.font)
158
150
pathLabel.foreground = UIUtil .getContextHelpForeground()
@@ -183,15 +175,5 @@ class FileSearchPopup(
183
175
184
176
return mainPanel
185
177
}
186
-
187
- private fun getRelativePath (item : FileItem ): String {
188
- // Try to make the path shorter for display purposes
189
- return try {
190
- val basePath = item.path.substringBeforeLast(item.name, " " )
191
- if (basePath.isEmpty()) item.path else basePath
192
- } catch (e: Exception ) {
193
- item.path
194
- }
195
- }
196
178
}
197
179
}
0 commit comments