Skip to content

Commit bce6611

Browse files
authored
feat(gui): add "copy reference" to context menu (PR skylot#2863)
Co-authored-by: xxr0ss <xxr0ss@users.noreply.github.com>
1 parent 21aa90c commit bce6611

12 files changed

Lines changed: 59 additions & 0 deletions

jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public enum ActionModel {
107107
Shortcut.keyboard(KeyEvent.VK_F)),
108108
XPOSED_COPY(CODE_AREA, "popup.xposed", "popup.xposed", null,
109109
Shortcut.keyboard(KeyEvent.VK_Y)),
110+
COPY_REFERENCE(CODE_AREA, "popup.copy_reference", "popup.copy_reference", null,
111+
Shortcut.keyboard(KeyEvent.VK_R)),
110112
JSON_PRETTIFY(CODE_AREA, "popup.json_prettify", "popup.json_prettify", null,
111113
Shortcut.none()),
112114

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package jadx.gui.ui.action;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import jadx.api.JavaClass;
7+
import jadx.api.JavaField;
8+
import jadx.api.JavaMethod;
9+
import jadx.api.JavaNode;
10+
import jadx.gui.treemodel.JClass;
11+
import jadx.gui.treemodel.JField;
12+
import jadx.gui.treemodel.JMethod;
13+
import jadx.gui.treemodel.JNode;
14+
import jadx.gui.ui.codearea.CodeArea;
15+
import jadx.gui.utils.UiUtils;
16+
17+
public final class CopyReferenceAction extends JNodeAction {
18+
private static final Logger LOG = LoggerFactory.getLogger(CopyReferenceAction.class);
19+
private static final long serialVersionUID = -8816072267744391424L;
20+
21+
public CopyReferenceAction(CodeArea codeArea) {
22+
super(ActionModel.COPY_REFERENCE, codeArea);
23+
}
24+
25+
@Override
26+
public void runAction(JNode node) {
27+
JavaNode javaNode = node.getJavaNode();
28+
String ref;
29+
if (javaNode instanceof JavaClass) {
30+
ref = javaNode.getFullName();
31+
} else if (javaNode instanceof JavaMethod) {
32+
ref = ((JavaMethod) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName();
33+
} else if (javaNode instanceof JavaField) {
34+
ref = ((JavaField) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName();
35+
} else {
36+
LOG.warn("Copy reference not supported for node type: {}", node.getClass());
37+
return;
38+
}
39+
UiUtils.copyToClipboard(ref);
40+
}
41+
42+
@Override
43+
public boolean isActionEnabled(JNode node) {
44+
return node instanceof JMethod || node instanceof JClass || node instanceof JField;
45+
}
46+
}

jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import jadx.gui.treemodel.JResource;
3636
import jadx.gui.ui.MainWindow;
3737
import jadx.gui.ui.action.CommentSearchAction;
38+
import jadx.gui.ui.action.CopyReferenceAction;
3839
import jadx.gui.ui.action.FindUsageAction;
3940
import jadx.gui.ui.action.FridaAction;
4041
import jadx.gui.ui.action.GoToDeclarationAction;
@@ -191,6 +192,7 @@ private void appendCodeMenuItems(JPopupMenu popupMenu) {
191192
popup.add(new CommentAction(this));
192193
popup.add(new CommentSearchAction(this));
193194
popup.add(new RenameAction(this));
195+
popup.add(new CopyReferenceAction(this));
194196
popup.addSeparator();
195197
popup.add(new FridaAction(this));
196198
popup.add(new XposedAction(this));

jadx-gui/src/main/resources/i18n/Messages_de_DE.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=Kommentar
393393
popup.update_comment=Kommentar aktualisieren
394394
popup.search_comment=Kommentar suchen
395395
popup.rename=Umbennen
396+
#popup.copy_reference=Copy Reference
396397
popup.search=Suche "%s"
397398
popup.search_global=Globale Suche "%s"
398399
popup.remove=Entfernen

jadx-gui/src/main/resources/i18n/Messages_en_US.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=Comment
393393
popup.update_comment=Update comment
394394
popup.search_comment=Search comments
395395
popup.rename=Rename
396+
popup.copy_reference=Copy Reference
396397
popup.search=Search "%s"
397398
popup.search_global=Global Search "%s"
398399
popup.remove=Remove

jadx-gui/src/main/resources/i18n/Messages_es_ES.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.xposed=Copiar como fragmento de xposed
393393
#popup.update_comment=Update comment
394394
#popup.search_comment=Search comments
395395
popup.rename=Renombrar
396+
#popup.copy_reference=Copy Reference
396397
#popup.search=Search "%s"
397398
#popup.search_global=Global Search "%s"
398399
#popup.remove=Remove

jadx-gui/src/main/resources/i18n/Messages_id_ID.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=Komentar
393393
#popup.update_comment=Update comment
394394
popup.search_comment=Cari komentar
395395
popup.rename=Ganti nama
396+
#popup.copy_reference=Copy Reference
396397
popup.search=Cari "%s"
397398
popup.search_global=Cari Global "%s"
398399
popup.remove=Hapus

jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=주석
393393
#popup.update_comment=Update comment
394394
popup.search_comment=주석 검색
395395
popup.rename=이름 바꾸기
396+
#popup.copy_reference=Copy Reference
396397
popup.search="%s" 검색
397398
popup.search_global="%s" 전역 검색
398399
#popup.remove=Remove

jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=Comentar
393393
#popup.update_comment=Update comment
394394
popup.search_comment=Buscar comentários
395395
popup.rename=Renomear
396+
#popup.copy_reference=Copy Reference
396397
popup.search=Buscar "%s"
397398
popup.search_global=Busca global "%s"
398399
#popup.remove=Remove

jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ popup.add_comment=Комментарий
393393
#popup.update_comment=Update comment
394394
popup.search_comment=Поиск комментариев
395395
popup.rename=Переименовать
396+
#popup.copy_reference=Copy Reference
396397
popup.search=Найти "%s"
397398
popup.search_global=Глобальный поиск "%s"
398399
popup.remove=Удалить

0 commit comments

Comments
 (0)