提交 78eed862 编写于 作者: S Soul Trace 提交者: skylot

feat(gui): reopened tabs on file reload (PR #793 #792)

* Add getRealFullName() to ClassNode and JavaClass and searchJavaClassByRealName() to JadxWrapper

Those methods is like getFullName() and searchJavaClassByClassName(), but for class names without aliases.
It is necessary for renaming classes/methods/fields.

* MainWindow: Try to restore open tabs on deobfuscation toggle

Restore open tabs if possible when user toggles deobfuscation mode.
Try to scroll to the position before toggling deobfuscation mode (may be not exact cause of the comments).
上级 cc29da8e
......@@ -174,6 +174,10 @@ public final class JavaClass implements JavaNode {
return cls.getFullName();
}
public String getRealFullName() {
return cls.getRealFullName();
}
public String getPackage() {
return cls.getPackage();
}
......
......@@ -517,6 +517,10 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
return clsInfo.getAliasFullName();
}
public String getRealFullName() {
return clsInfo.getType().getObject();
}
public String getPackage() {
return clsInfo.getAliasPkg();
}
......
......@@ -147,4 +147,13 @@ public class JadxWrapper {
return decompiler.getClasses().stream().filter(cls -> cls.getFullName().equals(fullName))
.findFirst().orElse(null);
}
/**
* @param realName Real name of an outer class. Inner classes are not supported.
* @return
*/
public @Nullable JavaClass searchJavaClassByRealName(String realName) {
return decompiler.getClasses().stream().filter(cls -> cls.getRealFullName().equals(realName))
.findFirst().orElse(null);
}
}
......@@ -19,8 +19,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
......@@ -38,11 +40,13 @@ import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.JadxArgs;
import jadx.api.JavaClass;
import jadx.api.JavaNode;
import jadx.api.ResourceFile;
import jadx.gui.JadxWrapper;
......@@ -373,9 +377,46 @@ public class MainWindow extends JFrame {
public void reOpenFile() {
File openedFile = wrapper.getOpenFile();
Map<String, Integer> openTabs = storeOpenTabs();
if (openedFile != null) {
open(openedFile.toPath());
}
restoreOpenTabs(openTabs);
}
@NotNull
private Map<String, Integer> storeOpenTabs() {
Map<String, Integer> openTabs = new LinkedHashMap<>();
for (Map.Entry<JNode, ContentPanel> entry : tabbedPane.getOpenTabs().entrySet()) {
JavaNode javaNode = entry.getKey().getJavaNode();
String classRealName = "";
if (javaNode instanceof JavaClass) {
JavaClass javaClass = (JavaClass) javaNode;
classRealName = javaClass.getRealFullName();
}
@Nullable
JumpPosition position = entry.getValue().getTabbedPane().getCurrentPosition();
int line = 0;
if (position != null) {
line = position.getLine();
}
openTabs.put(classRealName, line);
}
return openTabs;
}
private void restoreOpenTabs(Map<String, Integer> openTabs) {
for (Map.Entry<String, Integer> entry : openTabs.entrySet()) {
String classRealName = entry.getKey();
int position = entry.getValue();
@Nullable
JavaClass newClass = wrapper.searchJavaClassByRealName(classRealName);
if (newClass == null) {
continue;
}
JNode newNode = cacheObject.getNodeCache().makeFrom(newClass);
tabbedPane.codeJump(new JumpPosition(newNode, position));
}
}
private void saveAll(boolean export) {
......
......@@ -105,7 +105,7 @@ public class TabbedPane extends JTabbedPane {
}
@Nullable
private JumpPosition getCurrentPosition() {
JumpPosition getCurrentPosition() {
ContentPanel selectedCodePanel = getSelectedCodePanel();
if (selectedCodePanel instanceof AbstractCodeContentPanel) {
return ((AbstractCodeContentPanel) selectedCodePanel).getCodeArea().getCurrentPosition();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册