Skip to content

Commit

Permalink
gui: fix sync with editor
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jun 20, 2014
1 parent 26aa504 commit eaf623a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -122,6 +123,17 @@ private void addPackage(Map<String, JPackage> pkgs, JPackage pkg) {
}
}

public JClass searchClassInTree(JClass node) {
Enumeration en = this.breadthFirstEnumeration();
while (en.hasMoreElements()) {
Object obj = en.nextElement();
if (node.equals(obj)) {
return (JClass) obj;
}
}
return null;
}

public boolean isFlatPackages() {
return flatPackages;
}
Expand Down
12 changes: 10 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class MainWindow extends JFrame {

private JTree tree;
private DefaultTreeModel treeModel;
private JRoot treeRoot;
private TabbedPane tabbedPane;

public MainWindow(JadxWrapper wrapper) {
Expand Down Expand Up @@ -116,7 +117,7 @@ private void saveAllAction() {
}

private void initTree() {
JRoot treeRoot = new JRoot(wrapper);
treeRoot = new JRoot(wrapper);
treeModel.setRoot(treeRoot);
treeModel.reload();
tree.expandRow(0);
Expand Down Expand Up @@ -152,13 +153,20 @@ private void syncWithEditor() {
return;
}
JClass jCls = selectedCodePanel.getCls();
if (jCls.getParent() == null && treeRoot != null) {
// node not register in tree
jCls = treeRoot.searchClassInTree(jCls);
if (jCls == null) {
LOG.error("Class not found in tree");
return;
}
}
TreeNode[] pathNodes = treeModel.getPathToRoot(jCls);
if (pathNodes == null) {
return;
}
TreePath path = new TreePath(pathNodes);
tree.setSelectionPath(path);
tree.expandPath(path);
tree.makeVisible(path);
}

Expand Down

0 comments on commit eaf623a

Please sign in to comment.