-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathCopyAtAction.kt
More file actions
61 lines (57 loc) · 2.41 KB
/
Copy pathCopyAtAction.kt
File metadata and controls
61 lines (57 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2021 minecraft-dev
*
* MIT License
*/
package com.demonwav.mcdev.platform.mcp.actions
import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
import com.demonwav.mcdev.util.ActionData
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
class CopyAtAction : SrgActionBase() {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
when (parent) {
is PsiField -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
val srg = getSrgField(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
classSrg + " " + srg.name + " # " + parent.name
)
}
is PsiMethod -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
val srg = getSrgMethod(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
classSrg + " " + srg.name + srg.descriptor + " # " + parent.name
)
}
is PsiClass -> {
val classMcpToSrg = getSrgClass(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(data.editor, data.element, classMcpToSrg)
}
else -> showBalloon("Not a valid element", e)
}
}
private fun copyToClipboard(editor: Editor, element: PsiElement, text: String) {
val stringSelection = StringSelection(text)
val clpbrd = Toolkit.getDefaultToolkit().systemClipboard
clpbrd.setContents(stringSelection, null)
showSuccessBalloon(editor, element, "Copied $text")
}
}