From 47ede4952ce45e0a633f9c5e7ff3ea8a18babf14 Mon Sep 17 00:00:00 2001 From: GraxCode Date: Mon, 28 Sep 2020 17:11:03 +0200 Subject: [PATCH] quick search in decompiler panel --- .../swing/panel/DecompilerPanel.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/gui/src/main/java/me/nov/threadtear/swing/panel/DecompilerPanel.java b/gui/src/main/java/me/nov/threadtear/swing/panel/DecompilerPanel.java index ec9ca7a..ccd4dc8 100644 --- a/gui/src/main/java/me/nov/threadtear/swing/panel/DecompilerPanel.java +++ b/gui/src/main/java/me/nov/threadtear/swing/panel/DecompilerPanel.java @@ -26,6 +26,8 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -37,24 +39,18 @@ public class DecompilerPanel extends JPanel implements ActionListener { private static final long serialVersionUID = 1L; - - private DecompilerTextArea textArea; - - private int searchIndex = -1; - private String lastSearchText = null; - + private static int preferredDecompilerIndex = 0; private final AnalysisFrame analysisFrame; - public File archive; - public Clazz clazz; - - private final JComboBox decompilerSelection; + private final JComboBox> decompilerSelection; private final JComboBox conversionMethod; private final JCheckBox ignoreTCB; private final JCheckBox ignoreMon; private final JCheckBox aggressive; - - private static int preferredDecompilerIndex = 0; - private IDecompilerBridge decompilerBridge; + public File archive; + public Clazz clazz; + private DecompilerTextArea textArea; + private int searchIndex = -1; + private String lastSearchText = null; public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) { this.analysisFrame = analysisFrame; @@ -64,7 +60,7 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) { this.setLayout(new BorderLayout(4, 4)); JPanel leftActionPanel = new JPanel(); leftActionPanel.setLayout(new GridBagLayout()); - decompilerSelection = new JComboBox<>(DecompilerInfo.getDecompilerInfos().toArray(new DecompilerInfo[0])); + decompilerSelection = new JComboBox>(DecompilerInfo.getDecompilerInfos().toArray(new DecompilerInfo[0])); decompilerSelection.setSelectedIndex(preferredDecompilerIndex); decompilerSelection.addActionListener(this); leftActionPanel.add(decompilerSelection); @@ -86,6 +82,7 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) { ReloadButton reload = new ReloadButton(); reload.addActionListener(this); SearchTextField search = new SearchTextField(); + search.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Search for text or regex"); search.setPreferredSize(new Dimension(200, reload.getPreferredSize().height)); search.addSearchListener(l -> { @@ -145,6 +142,20 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) { this.add(topPanel, BorderLayout.NORTH); Threadtear.getInstance().statusBar.runWithLoadIndicator("Decompiling class file... ", () -> { this.textArea = new DecompilerTextArea(); + this.textArea.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) + if (e.getKeyCode() == KeyEvent.VK_F) { + search.requestFocusInWindow(); + String text = textArea.getSelectedText(); + if (text != null && !text.trim().isEmpty()) { + search.setText(text); + search.postActionEvent(); + } + } + } + }); this.update(); this.add(SwingUtils.withBorder( SwingUtils.wrap(SwingUtils.createRSyntaxOverlayScrollPane(textArea)), @@ -195,7 +206,7 @@ public void update() { .forEach(i -> m.instructions.set(i, new InsnNode(POP)))); } bytes = Conversion.toBytecode0(copy); - decompilerBridge = decompilerSelection.getModel() + IDecompilerBridge decompilerBridge = decompilerSelection.getModel() .getElementAt(decompilerSelection.getSelectedIndex()) .createDecompilerBridge(); preferredDecompilerIndex = decompilerSelection.getSelectedIndex();