From bce6611aaf32ac16b8ef27bccd7a8646a368a0bd Mon Sep 17 00:00:00 2001 From: xxr0ss Date: Sat, 2 May 2026 04:30:27 +0800 Subject: [PATCH] feat(gui): add "copy reference" to context menu (PR #2863) Co-authored-by: xxr0ss --- .../java/jadx/gui/ui/action/ActionModel.java | 2 + .../gui/ui/action/CopyReferenceAction.java | 46 +++++++++++++++++++ .../java/jadx/gui/ui/codearea/CodeArea.java | 2 + .../resources/i18n/Messages_de_DE.properties | 1 + .../resources/i18n/Messages_en_US.properties | 1 + .../resources/i18n/Messages_es_ES.properties | 1 + .../resources/i18n/Messages_id_ID.properties | 1 + .../resources/i18n/Messages_ko_KR.properties | 1 + .../resources/i18n/Messages_pt_BR.properties | 1 + .../resources/i18n/Messages_ru_RU.properties | 1 + .../resources/i18n/Messages_zh_CN.properties | 1 + .../resources/i18n/Messages_zh_TW.properties | 1 + 12 files changed, 59 insertions(+) create mode 100644 jadx-gui/src/main/java/jadx/gui/ui/action/CopyReferenceAction.java diff --git a/jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java b/jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java index 1da55fce1..6a5114322 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java @@ -107,6 +107,8 @@ public enum ActionModel { Shortcut.keyboard(KeyEvent.VK_F)), XPOSED_COPY(CODE_AREA, "popup.xposed", "popup.xposed", null, Shortcut.keyboard(KeyEvent.VK_Y)), + COPY_REFERENCE(CODE_AREA, "popup.copy_reference", "popup.copy_reference", null, + Shortcut.keyboard(KeyEvent.VK_R)), JSON_PRETTIFY(CODE_AREA, "popup.json_prettify", "popup.json_prettify", null, Shortcut.none()), diff --git a/jadx-gui/src/main/java/jadx/gui/ui/action/CopyReferenceAction.java b/jadx-gui/src/main/java/jadx/gui/ui/action/CopyReferenceAction.java new file mode 100644 index 000000000..a18258bea --- /dev/null +++ b/jadx-gui/src/main/java/jadx/gui/ui/action/CopyReferenceAction.java @@ -0,0 +1,46 @@ +package jadx.gui.ui.action; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import jadx.api.JavaClass; +import jadx.api.JavaField; +import jadx.api.JavaMethod; +import jadx.api.JavaNode; +import jadx.gui.treemodel.JClass; +import jadx.gui.treemodel.JField; +import jadx.gui.treemodel.JMethod; +import jadx.gui.treemodel.JNode; +import jadx.gui.ui.codearea.CodeArea; +import jadx.gui.utils.UiUtils; + +public final class CopyReferenceAction extends JNodeAction { + private static final Logger LOG = LoggerFactory.getLogger(CopyReferenceAction.class); + private static final long serialVersionUID = -8816072267744391424L; + + public CopyReferenceAction(CodeArea codeArea) { + super(ActionModel.COPY_REFERENCE, codeArea); + } + + @Override + public void runAction(JNode node) { + JavaNode javaNode = node.getJavaNode(); + String ref; + if (javaNode instanceof JavaClass) { + ref = javaNode.getFullName(); + } else if (javaNode instanceof JavaMethod) { + ref = ((JavaMethod) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName(); + } else if (javaNode instanceof JavaField) { + ref = ((JavaField) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName(); + } else { + LOG.warn("Copy reference not supported for node type: {}", node.getClass()); + return; + } + UiUtils.copyToClipboard(ref); + } + + @Override + public boolean isActionEnabled(JNode node) { + return node instanceof JMethod || node instanceof JClass || node instanceof JField; + } +} diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java index d07d2f414..faf0f1276 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java @@ -35,6 +35,7 @@ import jadx.gui.treemodel.JNode; import jadx.gui.treemodel.JResource; import jadx.gui.ui.MainWindow; import jadx.gui.ui.action.CommentSearchAction; +import jadx.gui.ui.action.CopyReferenceAction; import jadx.gui.ui.action.FindUsageAction; import jadx.gui.ui.action.FridaAction; import jadx.gui.ui.action.GoToDeclarationAction; @@ -191,6 +192,7 @@ public final class CodeArea extends AbstractCodeArea implements CodePanelSyncerA popup.add(new CommentAction(this)); popup.add(new CommentSearchAction(this)); popup.add(new RenameAction(this)); + popup.add(new CopyReferenceAction(this)); popup.addSeparator(); popup.add(new FridaAction(this)); popup.add(new XposedAction(this)); diff --git a/jadx-gui/src/main/resources/i18n/Messages_de_DE.properties b/jadx-gui/src/main/resources/i18n/Messages_de_DE.properties index 7dc548283..ba9558c3e 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_de_DE.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_de_DE.properties @@ -393,6 +393,7 @@ popup.add_comment=Kommentar popup.update_comment=Kommentar aktualisieren popup.search_comment=Kommentar suchen popup.rename=Umbennen +#popup.copy_reference=Copy Reference popup.search=Suche "%s" popup.search_global=Globale Suche "%s" popup.remove=Entfernen diff --git a/jadx-gui/src/main/resources/i18n/Messages_en_US.properties b/jadx-gui/src/main/resources/i18n/Messages_en_US.properties index af19d3a57..5a0414bef 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_en_US.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_en_US.properties @@ -393,6 +393,7 @@ popup.add_comment=Comment popup.update_comment=Update comment popup.search_comment=Search comments popup.rename=Rename +popup.copy_reference=Copy Reference popup.search=Search "%s" popup.search_global=Global Search "%s" popup.remove=Remove diff --git a/jadx-gui/src/main/resources/i18n/Messages_es_ES.properties b/jadx-gui/src/main/resources/i18n/Messages_es_ES.properties index 5bb651e68..85304fa09 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_es_ES.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_es_ES.properties @@ -393,6 +393,7 @@ popup.xposed=Copiar como fragmento de xposed #popup.update_comment=Update comment #popup.search_comment=Search comments popup.rename=Renombrar +#popup.copy_reference=Copy Reference #popup.search=Search "%s" #popup.search_global=Global Search "%s" #popup.remove=Remove diff --git a/jadx-gui/src/main/resources/i18n/Messages_id_ID.properties b/jadx-gui/src/main/resources/i18n/Messages_id_ID.properties index ca3e2c3a4..ce0651c3d 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_id_ID.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_id_ID.properties @@ -393,6 +393,7 @@ popup.add_comment=Komentar #popup.update_comment=Update comment popup.search_comment=Cari komentar popup.rename=Ganti nama +#popup.copy_reference=Copy Reference popup.search=Cari "%s" popup.search_global=Cari Global "%s" popup.remove=Hapus diff --git a/jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties b/jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties index 7ed10bb55..16df0f21f 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties @@ -393,6 +393,7 @@ popup.add_comment=주석 #popup.update_comment=Update comment popup.search_comment=주석 검색 popup.rename=이름 바꾸기 +#popup.copy_reference=Copy Reference popup.search="%s" 검색 popup.search_global="%s" 전역 검색 #popup.remove=Remove diff --git a/jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties b/jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties index c660c62ec..71768804e 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties @@ -393,6 +393,7 @@ popup.add_comment=Comentar #popup.update_comment=Update comment popup.search_comment=Buscar comentários popup.rename=Renomear +#popup.copy_reference=Copy Reference popup.search=Buscar "%s" popup.search_global=Busca global "%s" #popup.remove=Remove diff --git a/jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties b/jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties index d2094227b..26bc14ae8 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties @@ -393,6 +393,7 @@ popup.add_comment=Комментарий #popup.update_comment=Update comment popup.search_comment=Поиск комментариев popup.rename=Переименовать +#popup.copy_reference=Copy Reference popup.search=Найти "%s" popup.search_global=Глобальный поиск "%s" popup.remove=Удалить diff --git a/jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties b/jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties index 3aea75d7e..5613ec300 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties @@ -393,6 +393,7 @@ popup.add_comment=添加注释 popup.update_comment=更新注释 popup.search_comment=搜索注释 popup.rename=重命名 +popup.copy_reference=复制引用 popup.search=搜索 “%s” popup.search_global=全局搜索 “%s” popup.remove=移除 diff --git a/jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties b/jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties index bf11b1787..ba9b3bf93 100644 --- a/jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties +++ b/jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties @@ -393,6 +393,7 @@ popup.add_comment=註解 popup.update_comment=更新註解 popup.search_comment=搜尋註解 popup.rename=重新命名 +popup.copy_reference=複製引用 popup.search=搜尋 "%s" popup.search_global=全域搜尋 "%s" popup.remove=移除