Skip to content

Commit

Permalink
add a menu to copy class name.
Browse files Browse the repository at this point in the history
  • Loading branch information
javaeryang committed Aug 28, 2018
1 parent 1b0b526 commit f0cf7f5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
46 changes: 38 additions & 8 deletions jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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;
Expand All @@ -15,13 +17,22 @@
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;
Expand Down Expand Up @@ -252,6 +263,15 @@ public void mouseClicked(MouseEvent e) {
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
Expand Down Expand Up @@ -315,6 +335,16 @@ public void closeAllTabs() {
}
}

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();
Expand Down
26 changes: 21 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
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);
Expand Down Expand Up @@ -136,4 +146,10 @@ private static String format(long mem) {
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);
}
}
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ search.match_case=区分大小写
search.whole_word=整个词语
search.find=查询

tabs.copy_class_name=复制类名
tabs.close=关闭
tabs.closeOthers=关闭其他文件
tabs.closeAll=全部关闭
Expand Down

0 comments on commit f0cf7f5

Please sign in to comment.