1
- package cc.unitmesh.devti.gui.chat.ui
1
+ package cc.unitmesh.devti.gui.chat.ui.file
2
2
3
3
import cc.unitmesh.devti.completion.AutoDevInputLookupManagerListener
4
- import cc.unitmesh.devti.gui.chat.ui.file.RelatedFileListCellRenderer
5
- import cc.unitmesh.devti.gui.chat.ui.file.RelatedFileListViewModel
6
- import cc.unitmesh.devti.gui.chat.ui.file.WorkspaceFilePanel
7
- import cc.unitmesh.devti.gui.chat.ui.file.WorkspaceFileToolbar
4
+ import cc.unitmesh.devti.gui.chat.ui.AutoDevInput
8
5
import cc.unitmesh.devti.provider.RelatedClassesProvider
9
6
import com.intellij.codeInsight.lookup.LookupManagerListener
10
7
import com.intellij.openapi.Disposable
@@ -43,30 +40,30 @@ class FileWorkspaceManager(
43
40
setupElementsList()
44
41
setupEditorListener()
45
42
setupRelatedListener()
46
-
43
+
47
44
// Initialize with current file
48
45
val currentFile = FileEditorManager .getInstance(project).selectedFiles.firstOrNull()
49
46
currentFile?.let {
50
47
relatedFileListViewModel.addFileIfAbsent(currentFile, first = true )
51
48
}
52
-
49
+
53
50
return createHeaderPanel(input)
54
51
}
55
-
52
+
56
53
private fun setupElementsList () {
57
54
elementsList.selectionMode = ListSelectionModel .SINGLE_SELECTION
58
55
elementsList.layoutOrientation = JList .HORIZONTAL_WRAP
59
56
elementsList.visibleRowCount = 2
60
57
elementsList.cellRenderer = RelatedFileListCellRenderer (project)
61
58
elementsList.setEmptyText(" " )
62
-
59
+
63
60
elementsList.addMouseListener(object : MouseAdapter () {
64
61
override fun mouseClicked (e : MouseEvent ) {
65
62
calculateRelativeFile(e)
66
63
}
67
64
})
68
65
}
69
-
66
+
70
67
private fun setupEditorListener () {
71
68
project.messageBus.connect(disposable!! ).subscribe(
72
69
FileEditorManagerListener .FILE_EDITOR_MANAGER ,
@@ -80,74 +77,74 @@ class FileWorkspaceManager(
80
77
}
81
78
)
82
79
}
83
-
80
+
84
81
private fun setupRelatedListener () {
85
82
project.messageBus.connect(disposable!! )
86
83
.subscribe(LookupManagerListener .TOPIC , AutoDevInputLookupManagerListener (project) {
87
84
ApplicationManager .getApplication().invokeLater {
88
- val relatedElements = RelatedClassesProvider .provide(it.language)?.lookupIO(it)
85
+ val relatedElements = RelatedClassesProvider .Companion . provide(it.language)?.lookupIO(it)
89
86
updateElements(relatedElements)
90
87
}
91
88
})
92
89
}
93
-
90
+
94
91
private fun calculateRelativeFile (e : MouseEvent ) {
95
92
val list = e.source as JBList <* >
96
93
val index = list.locationToIndex(e.point)
97
94
if (index == - 1 ) return
98
-
95
+
99
96
val wrapper = relatedFileListViewModel.getListModel().getElementAt(index)
100
97
val cellBounds = list.getCellBounds(index, index)
101
-
98
+
102
99
val actionType = relatedFileListViewModel.determineFileAction(wrapper, e.point, cellBounds)
103
100
val actionPerformed = relatedFileListViewModel.handleFileAction(wrapper, actionType) { vfile, relativePath ->
104
101
if (relativePath != null ) {
105
102
getWorkspacePanel().addFileToWorkspace(vfile)
106
103
ApplicationManager .getApplication().invokeLater {
107
104
if (! vfile.isValid) return @invokeLater
108
105
val psiFile = PsiManager .getInstance(project).findFile(vfile) ? : return @invokeLater
109
- val relatedElements = RelatedClassesProvider .provide(psiFile.language)?.lookupIO(psiFile)
106
+ val relatedElements = RelatedClassesProvider .Companion . provide(psiFile.language)?.lookupIO(psiFile)
110
107
updateElements(relatedElements)
111
108
}
112
109
}
113
110
}
114
-
111
+
115
112
if (! actionPerformed) {
116
113
list.clearSelection()
117
114
}
118
115
}
119
-
116
+
120
117
private fun updateElements (elements : List <PsiElement >? ) {
121
118
elements?.forEach { relatedFileListViewModel.addFileIfAbsent(it.containingFile.virtualFile) }
122
119
}
123
-
120
+
124
121
private fun createHeaderPanel (input : AutoDevInput ): JPanel {
125
122
val scrollPane = JBScrollPane (elementsList)
126
123
scrollPane.verticalScrollBarPolicy = JScrollPane .VERTICAL_SCROLLBAR_AS_NEEDED
127
124
scrollPane.horizontalScrollBarPolicy = JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED
128
-
125
+
129
126
val toolbar = WorkspaceFileToolbar .createToolbar(project, relatedFileListViewModel, input)
130
-
127
+
131
128
val headerPanel = JPanel (BorderLayout ())
132
129
headerPanel.add(toolbar, BorderLayout .NORTH )
133
130
headerPanel.add(scrollPane, BorderLayout .CENTER )
134
-
131
+
135
132
return headerPanel
136
133
}
137
-
134
+
138
135
// Public API methods
139
136
fun renderText (): String {
140
137
relatedFileListViewModel.clearAllFiles()
141
138
val files = workspaceFilePanel.getAllFilesFormat()
142
139
workspaceFilePanel.clear()
143
140
return files
144
141
}
145
-
142
+
146
143
fun clearWorkspace () {
147
144
workspaceFilePanel.clear()
148
145
}
149
-
146
+
150
147
fun getWorkspacePanel (): WorkspaceFilePanel = workspaceFilePanel
151
-
148
+
152
149
fun getRelatedFileListViewModel (): RelatedFileListViewModel = relatedFileListViewModel
153
- }
150
+ }
0 commit comments