Commit a8febb24 authored by javaeryang's avatar javaeryang Committed by skylot

feat(gui): add a menu to copy class name (#351)

parent 1b0b5268
package jadx.gui.ui;
import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.text.BadLocationException;
import java.awt.*;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
......@@ -15,13 +17,22 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import jadx.gui.treemodel.JCertificate;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.text.BadLocationException;
import jadx.api.ResourceFile;
import jadx.api.ResourceType;
import jadx.gui.treemodel.JCertificate;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JResource;
import jadx.gui.utils.JumpManager;
......@@ -252,6 +263,15 @@ class TabbedPane extends JTabbedPane {
private JPopupMenu createTabPopupMenu(final ContentPanel contentPanel) {
JPopupMenu menu = new JPopupMenu();
JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
copyRootClassName.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
copyRootClassName();
}
});
menu.add(copyRootClassName);
JMenuItem closeTab = new JMenuItem(NLS.str("tabs.close"));
closeTab.addActionListener(new ActionListener() {
@Override
......@@ -315,6 +335,16 @@ class TabbedPane extends JTabbedPane {
}
}
public void copyRootClassName(){
ContentPanel selectedPanel = getSelectedCodePanel();
JNode node = selectedPanel.getNode();
JClass jClass = node.getRootClass();
if (jClass != null){
String name = jClass.getFullName();
Utils.setClipboardString(name);
}
}
public void loadSettings() {
for (ContentPanel panel : openTabs.values()) {
panel.loadSettings();
......
package jadx.gui.utils;
import java.awt.*;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.InputStream;
import java.net.URL;
import javax.swing.*;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.utils.exceptions.JadxRuntimeException;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
......@@ -136,4 +146,10 @@ public class Utils {
public static char caseChar(char ch, boolean toLower) {
return toLower ? Character.toLowerCase(ch) : ch;
}
public static void setClipboardString(String text){
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(text);
clipboard.setContents(transferable, null);
}
}
......@@ -38,6 +38,7 @@ search.match_case=Match Case
search.whole_word=Whole word
search.find=Find
tabs.copy_class_name=Copy Name
tabs.close=Close
tabs.closeOthers=Close Others
tabs.closeAll=Close All
......
......@@ -38,6 +38,7 @@ search.match_case=Sensible a minúsculas/mayúsculas
search.whole_word=Palabra entera
search.find=Buscar
tabs.copy_class_name=Copy Name
tabs.close=Cerrar
tabs.closeOthers=Cerrar otros
tabs.closeAll=Cerrar todo
......
......@@ -38,6 +38,7 @@ search.match_case=区分大小写
search.whole_word=整个词语
search.find=查询
tabs.copy_class_name=复制类名
tabs.close=关闭
tabs.closeOthers=关闭其他文件
tabs.closeAll=全部关闭
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment