@@ -8,6 +8,7 @@ import com.intellij.notification.NotificationType
8
8
import com.intellij.notification.Notifications
9
9
import com.intellij.openapi.application.ApplicationManager
10
10
import com.intellij.openapi.application.runInEdt
11
+ import com.intellij.openapi.command.WriteCommandAction
11
12
import com.intellij.openapi.components.service
12
13
import com.intellij.openapi.diagnostic.Logger
13
14
import com.intellij.openapi.extensions.PluginId
@@ -16,6 +17,7 @@ import com.intellij.openapi.module.ModuleManager
16
17
import com.intellij.openapi.project.Project
17
18
import com.intellij.openapi.roots.ModuleRootManager
18
19
import com.intellij.openapi.roots.libraries.Library
20
+ import com.intellij.openapi.util.IconLoader
19
21
import com.intellij.openapi.vfs.VfsUtil
20
22
import com.intellij.psi.PsiDirectory
21
23
import com.intellij.psi.PsiFileFactory
@@ -45,6 +47,10 @@ class CopilotPluginUtil {
45
47
46
48
private const val NORMALIZED_LINE_SEPARATOR = " \n "
47
49
50
+ private const val NOTIFICATION_GROUP = " Vaadin Copilot"
51
+
52
+ private val COPILOT_ICON = IconLoader .getIcon(" /icons/copilot.svg" , CopilotPluginUtil ::class .java)
53
+
48
54
private var isVaadinProject = false
49
55
50
56
private enum class HANDLERS (val command : String ) {
@@ -77,7 +83,8 @@ class CopilotPluginUtil {
77
83
}
78
84
79
85
fun notify (content : String , type : NotificationType , project : Project ? ) {
80
- Notifications .Bus .notify(Notification (" Copilot" , content, type), project)
86
+ Notifications .Bus .notify(Notification (NOTIFICATION_GROUP , content, type)
87
+ .setIcon(COPILOT_ICON ), project)
81
88
}
82
89
83
90
fun isServerRunning (project : Project ): Boolean {
@@ -179,24 +186,27 @@ class CopilotPluginUtil {
179
186
}
180
187
}
181
188
182
- private fun getDotFileDirectory (project : Project ): PsiDirectory ? {
189
+ private fun getIdeaDir (project : Project ): File {
190
+ return File (project.basePath, IDEA_DIR )
191
+ }
192
+
193
+ fun getDotFileDirectory (project : Project ): PsiDirectory ? {
183
194
return ApplicationManager .getApplication().runReadAction<PsiDirectory ?> {
184
- val basePath = project.basePath
185
- if (basePath != null ) {
186
- val ideaDir = File (basePath, IDEA_DIR )
187
- VfsUtil .findFileByIoFile(ideaDir, false )?.let {
188
- return @runReadAction PsiManager .getInstance(project).findDirectory(it)
189
- }
190
- VfsUtil .createDirectoryIfMissing(ideaDir.path)?.let {
191
- LOG .info(" $ideaDir created" )
192
- return @runReadAction PsiManager .getInstance(project).findDirectory(it)
193
- }
195
+ VfsUtil .findFileByIoFile(getIdeaDir(project), false )?.let {
196
+ return @runReadAction PsiManager .getInstance(project).findDirectory(it)
194
197
}
195
198
return @runReadAction null
196
199
}
197
200
}
198
201
202
+ fun createIdeaDirectoryIfMissing (project : Project ) {
203
+ WriteCommandAction .runWriteCommandAction(project) {
204
+ val ideaDir = getIdeaDir(project).path
205
+ VfsUtil .createDirectoryIfMissing(ideaDir)?.let {
206
+ LOG .info(" $ideaDir created" )
207
+ }
208
+ }
209
+ }
199
210
}
200
211
201
-
202
212
}
0 commit comments