Skip to content

Commit

Permalink
correct popup position (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinVaadin authored Jan 3, 2025
1 parent c8eaa53 commit 5f6c57d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/kotlin/com/vaadin/plugin/ui/VaadinStatusBarWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.vaadin.plugin.ui
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.WindowManager
import com.intellij.ui.IconManager
Expand All @@ -13,6 +14,7 @@ import com.intellij.util.ui.UIUtil
import com.vaadin.plugin.copilot.CopilotPluginUtil
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasEndpoints
import java.awt.Point
import java.awt.event.MouseEvent
import javax.swing.Icon

Expand Down Expand Up @@ -55,19 +57,23 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta
override fun getClickConsumer(): Consumer<MouseEvent> {
return Consumer {
clicked = true
showPopup(RelativePoint.fromScreen(it.locationOnScreen))
showPopup(it)
update(project)
}
}

private fun showPopup(relativePoint: RelativePoint) {
private fun showPopup(e: MouseEvent) {
val panel = VaadinStatusBarInfoPopupPanel(project)
val popup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null).createPopup()
panel.afterRestart = {
popup.cancel()
showPopup(relativePoint)
showPopup(e)
}
popup.show(relativePoint)
val dimension = popup.content.preferredSize
val at = Point(0, -dimension.height)
popup.show(RelativePoint(e.component, at))
// destroy popup on unexpected project close
Disposer.register(this, popup)
}

override fun getTooltipText(): String {
Expand Down

0 comments on commit 5f6c57d

Please sign in to comment.