Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ org.gradle.jvmargs=-Xmx1g

ideaVersionName = 2024.3

coreVersion = 1.8.7
coreVersion = 1.8.8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't bump the version in PRs


# Silences a build-time warning because we are bundling our own kotlin library
kotlin.stdlib.default.dependency = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2025 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.platform.mcp.actions.platform.mcp.actions

import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showBalloon
import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showSuccessBalloon
import com.demonwav.mcdev.util.descriptor
import com.demonwav.mcdev.util.getDataFromActionEvent
import com.demonwav.mcdev.util.internalName
import com.intellij.openapi.actionSystem.AnAction
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.PsiIdentifier
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiReference
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection

class CopyNeoAtAction : AnAction() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a separate action? Could you not just fix the existing AT action to work on 1.21.4+?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill reopen a new PR with it done better.


override fun actionPerformed(e: AnActionEvent) {
val data = getDataFromActionEvent(e) ?: return showBalloon("Unknown failure", e)
val editor = data.editor

val element = data.element
if (element !is PsiIdentifier) {
showBalloon("Invalid element", e)
return
}

val target = when (val parent = element.parent) {
is PsiMember -> parent
is PsiReference -> parent.resolve()
else -> null
} ?: return showBalloon("Invalid element", e)

doCopy(target, element, editor, e)
}

companion object {

fun doCopy(target: PsiElement, element: PsiElement, editor: Editor?, e: AnActionEvent?) {
when (target) {
is PsiClass -> {
val text = "public ${target.internalName}"
val text2 = text.replace("/",".").replace(" (","(")
copyToClipboard(editor, element, text2)
}
is PsiField -> {
val containing = target.containingClass?.internalName
?: return maybeShow("Could not get owner of field", e)
val text = "public $containing ${target.name}"
val text2 = text.replace("/",".").replace(" (","(")
copyToClipboard(editor, element, text2)
}
is PsiMethod -> {
val containing = target.containingClass?.internalName
?: return maybeShow("Could not get owner of method", e)
val desc = target.descriptor ?: return maybeShow("Could not get descriptor of method", e)
val modifiedContaining = containing.replace("/",".");
val text = "public ${modifiedContaining} ${target.internalName}$desc"
copyToClipboard(editor, element, text)
}
else -> maybeShow("Invalid element", e)
}
}

private fun copyToClipboard(editor: Editor?, element: PsiElement, text: String) {
val stringSelection = StringSelection(text)
val clpbrd = Toolkit.getDefaultToolkit().systemClipboard
clpbrd.setContents(stringSelection, null)
if (editor != null) {
showSuccessBalloon(editor, element, "Copied: \"$text\"")
}
}

private fun maybeShow(text: String, e: AnActionEvent?) {
if (e != null) {
showBalloon(text, e)
}
}
}
}
7 changes: 6 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1652,10 +1652,15 @@
text="Minecraft Class" description="Create skeleton classes used in Minecraft Mods">
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
</action>
<action class="com.demonwav.mcdev.platform.mcp.actions.platform.mcp.actions.CopyNeoAtAction" id="CopyNeoATAction"
text="Neo AT Entry"
description="Copy the reference to clipboard in Neo Access Transformer format">
<add-to-group relative-to-action="CopyATAction" anchor="after" group-id="Copy.Paste.Special"/>
</action>
<action class="com.demonwav.mcdev.platform.mcp.actions.CopyAwAction" id="CopyAWAction"
text="AW Entry"
description="Copy the reference to clipboard in Access Widener format">
<add-to-group relative-to-action="CopyATAction" anchor="after" group-id="Copy.Paste.Special"/>
<add-to-group relative-to-action="CopyNeoATAction" anchor="after" group-id="Copy.Paste.Special"/>
</action>
</actions>
</idea-plugin>