Skip to content

Commit

Permalink
Merge branch 'main' into fix/non-existing-plugin-id
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinVaadin authored Dec 12, 2024
2 parents ed79ae7 + 4bd0f31 commit 77a4d48
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
43 changes: 22 additions & 21 deletions src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.findDirectory
import com.intellij.openapi.vfs.findFile
import com.intellij.openapi.vfs.findOrCreateDirectory
import com.vaadin.plugin.copilot.handler.GetModulePathsHandler
Expand Down Expand Up @@ -120,24 +121,24 @@ class CopilotPluginUtil {
}

private fun saveDotFileInternal(project: Project) {
val dotFileDirectory = getDotFileDirectory(project)
if (dotFileDirectory != null) {
val props = Properties()
props.setProperty("endpoint", RestUtil.getEndpoint())
props.setProperty("ide", "intellij")
props.setProperty("version", pluginVersion)
props.setProperty("supportedActions", HANDLERS.entries.joinToString(",") { a -> a.command })
runInEdt {
WriteAction.run<Throwable> {
val dotFileDirectory = getDotFileDirectory(project, true)
if (dotFileDirectory != null) {
val props = Properties()
props.setProperty("endpoint", RestUtil.getEndpoint())
props.setProperty("ide", "intellij")
props.setProperty("version", pluginVersion)
props.setProperty("supportedActions", HANDLERS.entries.joinToString(",") { a -> a.command })

val stringWriter = StringWriter()
val bufferedWriter =
object : BufferedWriter(stringWriter) {
override fun newLine() {
write(NORMALIZED_LINE_SEPARATOR)
}
}
props.store(bufferedWriter, "Vaadin Copilot Integration Runtime Properties")
runInEdt {
WriteAction.run<Throwable> {
val stringWriter = StringWriter()
val bufferedWriter =
object : BufferedWriter(stringWriter) {
override fun newLine() {
write(NORMALIZED_LINE_SEPARATOR)
}
}
props.store(bufferedWriter, "Vaadin Copilot Integration Runtime Properties")
val dotFile = dotFileDirectory.findFile(DOTFILE)
dotFile?.let {
try {
Expand Down Expand Up @@ -168,7 +169,7 @@ class CopilotPluginUtil {
fun removeDotFile(project: Project) {
runInEdt {
WriteAction.run<Throwable> {
val dotFile = getDotFileDirectory(project)?.findFile(DOTFILE)
val dotFile = getDotFileDirectory(project, false)?.findFile(DOTFILE)
dotFile?.let {
try {
it.delete(this)
Expand All @@ -181,18 +182,18 @@ class CopilotPluginUtil {
}
}

private fun getDotFileDirectory(project: Project): VirtualFile? {
private fun getDotFileDirectory(project: Project, create: Boolean): VirtualFile? {
val projectDir = project.guessProjectDir()
if (projectDir == null) {
LOG.error("Cannot guess project directory")
return null
}
LOG.info("Project directory: $projectDir")
return projectDir.findOrCreateDirectory(IDEA_DIR)
return if (create) projectDir.findOrCreateDirectory(IDEA_DIR) else projectDir.findDirectory(IDEA_DIR)
}

fun getDotFile(project: Project): VirtualFile? {
return getDotFileDirectory(project)?.findFile(DOTFILE)
return getDotFileDirectory(project, false)?.findFile(DOTFILE)
}

fun isActive(project: Project): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CopilotVaadinProjectListener : VaadinProjectListener {
private var triggered = false

override fun vaadinProjectDetected(project: Project) {
if (!triggered) {
if (!triggered && !project.isDisposed) {
triggered = true
saveDotFile(project)
removeDotFileOnExit(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.icons.AllIcons
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.NewUiValue
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBEmptyBorder
import com.intellij.util.ui.JBFont
Expand Down Expand Up @@ -86,7 +87,7 @@ class VaadinStatusBarInfoPopupPanel(private val project: Project) : JPanel() {

private fun createDescription(text: String): JComponent {
val desc = JLabel(text)
desc.font = JBFont.smallOrNewUiMedium()
desc.font = if (NewUiValue.isEnabled()) JBFont.medium() else JBFont.small()
desc.foreground = UIUtil.getLabelInfoForeground()

return desc
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/com/vaadin/plugin/ui/VaadinStatusBarWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.WindowManager
import com.intellij.ui.BadgeIconSupplier
import com.intellij.ui.IconManager
import com.intellij.ui.awt.RelativePoint
import com.intellij.util.Consumer
import com.intellij.util.ui.JBUI.CurrentTheme.IconBadge
import com.vaadin.plugin.copilot.CopilotPluginUtil
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasEndpoints
Expand All @@ -23,8 +24,6 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta
}
}

private val iconSupplier: BadgeIconSupplier = BadgeIconSupplier(VaadinIcons.VAADIN)

override fun ID(): String {
return ID
}
Expand Down Expand Up @@ -57,9 +56,9 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta

override fun getIcon(): Icon {
if (!CopilotPluginUtil.isActive(project) || !hasEndpoints()) {
return iconSupplier.warningIcon
return IconManager.getInstance().withIconBadge(VaadinIcons.VAADIN, IconBadge.WARNING)
}

return iconSupplier.originalIcon
return VaadinIcons.VAADIN
}
}

0 comments on commit 77a4d48

Please sign in to comment.