Commit 4a39af7c authored by Jan S's avatar Jan S Committed by skylot

feat(gui): make search bar usable for smali code (PR #652)

parent c7890f24
...@@ -2,9 +2,7 @@ package jadx.api; ...@@ -2,9 +2,7 @@ package jadx.api;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -312,7 +310,7 @@ public final class JadxDecompiler { ...@@ -312,7 +310,7 @@ public final class JadxDecompiler {
Path path = cls.dex().getDexFile().getPath(); Path path = cls.dex().getDexFile().getPath();
String className = cls.getAlias().makeRawFullName(); String className = cls.getAlias().makeRawFullName();
className = 'L' + className.replace('.', '/') + ';'; className = 'L' + className.replace('.', '/') + ';';
try (InputStream in = Files.newInputStream(path)) { try {
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(path.toFile(), Opcodes.getDefault()); DexBackedDexFile dexFile = DexFileFactory.loadDexFile(path.toFile(), Opcodes.getDefault());
boolean decompiled = false; boolean decompiled = false;
for (DexBackedClassDef classDef : dexFile.getClasses()) { for (DexBackedClassDef classDef : dexFile.getClasses()) {
......
...@@ -45,11 +45,16 @@ public final class CodePanel extends ContentPanel { ...@@ -45,11 +45,16 @@ public final class CodePanel extends ContentPanel {
add(areaTabbedPane); add(areaTabbedPane);
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Utils.ctrlButton()); KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Utils.ctrlButton());
Utils.addKeyBinding(codeArea, key, "SearchAction", new SearchAction()); SearchAction searchAction = new SearchAction();
Utils.addKeyBinding(codeArea, key, "SearchAction", searchAction);
Utils.addKeyBinding(smaliArea, key, "SearchAction", searchAction);
areaTabbedPane.addChangeListener(e -> { areaTabbedPane.addChangeListener(e -> {
if (areaTabbedPane.getSelectedComponent() == smaliScrollPane) { if (areaTabbedPane.getSelectedComponent() == smaliScrollPane) {
smaliArea.load(); smaliArea.load();
searchBar.setRTextArea(smaliArea);
} else if (areaTabbedPane.getSelectedComponent() == codeScrollPane) {
searchBar.setRTextArea(codeArea);
} }
}); });
} }
......
...@@ -32,7 +32,7 @@ class SearchBar extends JToolBar { ...@@ -32,7 +32,7 @@ class SearchBar extends JToolBar {
private static final Icon ICON_DOWN = Utils.openIcon("arrow_down"); private static final Icon ICON_DOWN = Utils.openIcon("arrow_down");
private static final Icon ICON_CLOSE = Utils.openIcon("cross"); private static final Icon ICON_CLOSE = Utils.openIcon("cross");
private final RSyntaxTextArea rTextArea; private RSyntaxTextArea rTextArea;
private final JTextField searchField; private final JTextField searchField;
private final JCheckBox markAllCB; private final JCheckBox markAllCB;
...@@ -168,4 +168,11 @@ class SearchBar extends JToolBar { ...@@ -168,4 +168,11 @@ class SearchBar extends JToolBar {
searchField.setBackground(COLOR_BG_NORMAL); searchField.setBackground(COLOR_BG_NORMAL);
} }
} }
public void setRTextArea(RSyntaxTextArea rTextArea) {
this.rTextArea = rTextArea;
if (isVisible()) {
this.search(0);
}
}
} }
...@@ -18,6 +18,7 @@ public final class SmaliArea extends RSyntaxTextArea { ...@@ -18,6 +18,7 @@ public final class SmaliArea extends RSyntaxTextArea {
void load() { void load() {
if (getText().isEmpty()) { if (getText().isEmpty()) {
setText(node.getSmali()); setText(node.getSmali());
setCaretPosition(0);
} }
} }
} }
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