@@ -18,7 +18,7 @@ class WorkspacePanel(
18
18
private val project : Project ,
19
19
private val input : AutoDevInput
20
20
) : JPanel(BorderLayout ()) {
21
- private val workspaceFiles = mutableListOf<VirtualFile >()
21
+ private val workspaceFiles = mutableListOf<FilePresentation >()
22
22
private val filesPanel = JPanel (WrapLayout (FlowLayout .LEFT , 2 , 2 ))
23
23
24
24
init {
@@ -56,19 +56,12 @@ class WorkspacePanel(
56
56
}
57
57
58
58
fun addFileToWorkspace (file : VirtualFile ) {
59
- if (! workspaceFiles.contains(file)) {
60
- workspaceFiles.add(file)
59
+ val filePresentation = FilePresentation .from(project, file)
60
+ if (workspaceFiles.none { it.virtualFile == file }) {
61
+ workspaceFiles.add(filePresentation)
61
62
updateFilesPanel()
62
63
63
- val relativePath = try {
64
- project.basePath?.let { basePath ->
65
- file.path.substringAfter(basePath).removePrefix(" /" )
66
- } ? : file.path
67
- } catch (e: Exception ) {
68
- file.path
69
- }
70
-
71
- input.appendText(" \n /file:$relativePath " )
64
+ // input.appendText("\n/file:${filePresentation.relativePath(project)}")
72
65
}
73
66
}
74
67
@@ -88,9 +81,9 @@ class WorkspacePanel(
88
81
})
89
82
filesPanel.add(addButton)
90
83
91
- for (file in workspaceFiles) {
92
- val fileLabel = FileItemPanel (project, file ) {
93
- removeFile(file )
84
+ for (filePresentation in workspaceFiles) {
85
+ val fileLabel = FileItemPanel (project, filePresentation ) {
86
+ removeFile(filePresentation )
94
87
}
95
88
filesPanel.add(fileLabel)
96
89
}
@@ -99,20 +92,30 @@ class WorkspacePanel(
99
92
filesPanel.repaint()
100
93
}
101
94
102
- private fun removeFile (file : VirtualFile ) {
103
- workspaceFiles.remove(file )
95
+ private fun removeFile (filePresentation : FilePresentation ) {
96
+ workspaceFiles.remove(filePresentation )
104
97
updateFilesPanel()
105
98
}
106
99
107
100
fun clear () {
108
101
workspaceFiles.clear()
109
102
updateFilesPanel()
110
103
}
104
+
105
+ fun getAllFiles (): List <FilePresentation > {
106
+ return workspaceFiles.toList()
107
+ }
108
+
109
+ fun getAllFilesFormat (): String {
110
+ return workspaceFiles.joinToString(separator = " \n " ) {
111
+ " \n /file:${it.presentablePath} "
112
+ }
113
+ }
111
114
}
112
115
113
116
class FileItemPanel (
114
117
private val project : Project ,
115
- private val file : VirtualFile ,
118
+ private val filePresentation : FilePresentation ,
116
119
private val onRemove : () -> Unit
117
120
) : JPanel(FlowLayout (FlowLayout .LEFT , 2, 0)) {
118
121
init {
@@ -123,8 +126,7 @@ class FileItemPanel(
123
126
background = JBColor (0xEDF4FE , 0x313741 )
124
127
isOpaque = true
125
128
126
- val icon = file.fileType.icon
127
- val fileLabel = JBLabel (file.name, icon, JBLabel .LEFT )
129
+ val fileLabel = JBLabel (filePresentation.name, filePresentation.icon, JBLabel .LEFT )
128
130
129
131
val removeLabel = JBLabel (AllIcons .Actions .Close )
130
132
removeLabel.cursor = Cursor (Cursor .HAND_CURSOR )
@@ -227,3 +229,4 @@ class WrapLayout : FlowLayout {
227
229
}
228
230
}
229
231
}
232
+
0 commit comments