1
+ package com.coder.gateway.views
2
+
3
+ import com.intellij.icons.AllIcons
4
+ import com.intellij.ide.BrowserUtil
5
+ import com.intellij.ide.IdeBundle
6
+ import com.intellij.openapi.actionSystem.AnActionEvent
7
+ import com.intellij.openapi.actionSystem.DefaultActionGroup
8
+ import com.intellij.openapi.actionSystem.ex.ActionManagerEx
9
+ import com.intellij.openapi.ide.CopyPasteManager
10
+ import com.intellij.openapi.project.DumbAwareAction
11
+ import com.intellij.ui.components.ActionLink
12
+ import org.jetbrains.annotations.Nls
13
+ import java.awt.datatransfer.StringSelection
14
+ import javax.swing.Icon
15
+
16
+ class LazyBrowserLink (icon : Icon , @Nls text : String ) : ActionLink() {
17
+ init {
18
+ setIcon(icon, false )
19
+ setText(text)
20
+ }
21
+
22
+ var url: String? = " "
23
+ set(value) {
24
+ field = value
25
+ if (value != null ) {
26
+ addActionListener { BrowserUtil .browse(value) }
27
+ ActionManagerEx .doWithLazyActionManager { instance ->
28
+ val group = DefaultActionGroup (OpenLinkInBrowser (value), CopyLinkAction (value))
29
+ componentPopupMenu = instance.createActionPopupMenu(" popup@browser.link.context.menu" , group).component
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ private class CopyLinkAction (val url : String ) : DumbAwareAction(IdeBundle .messagePointer("action.text.copy.link.address"), AllIcons .Actions .Copy ) {
36
+
37
+ override fun actionPerformed (event : AnActionEvent ) {
38
+ CopyPasteManager .getInstance().setContents(StringSelection (url))
39
+ }
40
+ }
41
+
42
+ private class OpenLinkInBrowser (val url : String ) : DumbAwareAction(IdeBundle .messagePointer("action.text.open.link.in.browser"), AllIcons .Nodes .PpWeb ) {
43
+
44
+ override fun actionPerformed (event : AnActionEvent ) {
45
+ BrowserUtil .browse(url)
46
+ }
47
+ }
0 commit comments