Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Partially Deobfuscated Classes panel #482

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Comparator;
import java.util.EventObject;
import java.util.List;
import java.util.Map;

import javax.swing.JTree;
import javax.swing.event.CellEditorListener;
Expand All @@ -33,23 +34,26 @@
import javax.swing.tree.TreePath;

import cuchaz.enigma.gui.node.ClassSelectorClassNode;
import cuchaz.enigma.gui.panels.classlists.ClassPanel;
import cuchaz.enigma.gui.util.GuiUtil;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
import cuchaz.enigma.utils.validation.ValidationContext;

public class ClassSelector extends JTree {
public static final Comparator<ClassEntry> DEOBF_CLASS_COMPARATOR = Comparator.comparing(ClassEntry::getFullName);

private final ClassPanel parentPanel;
private final Comparator<ClassEntry> comparator;
private final GuiController controller;

private NestedPackages packageManager;
private ClassSelectionListener selectionListener;
private RenameSelectionListener renameSelectionListener;

public ClassSelector(Gui gui, Comparator<ClassEntry> comparator, boolean isRenamable) {
this.comparator = comparator;
public ClassSelector(ClassPanel panel, Gui gui, Comparator<ClassEntry> comparator, boolean isRenamable) {
this.parentPanel = panel;
this.controller = gui.getController();
this.comparator = comparator;

// configure the tree control
setEditable(true);
Expand Down Expand Up @@ -153,7 +157,7 @@ public void editingStopped(ChangeEvent e) {
Object prevData = node.getUserObject();
Object objectData = node.getUserObject() instanceof ClassEntry ? new ClassEntry(((ClassEntry) prevData).getPackageName() + "/" + data) : data;
gui.validateImmediateAction(vc -> {
renameSelectionListener.onSelectionRename(vc, node.getUserObject(), objectData, node);
renameSelectionListener.onSelectionRename(vc, node.getUserObject(), objectData, node, parentPanel);

if (vc.canProceed()) {
node.setUserObject(objectData); // Make sure that it's modified
Expand Down Expand Up @@ -212,6 +216,13 @@ public ClassEntry getSelectedClass() {
return null;
}

public int getClassesCount() {
return packageManager == null ? 0 : Math.toIntExact(packageManager.getClassToNodeMap().entrySet()
.stream()
.map(Map.Entry::getKey)
.count());
}

public enum State {
EXPANDED,
SELECTED
Expand Down Expand Up @@ -300,6 +311,6 @@ public interface ClassSelectionListener {
}

public interface RenameSelectionListener {
void onSelectionRename(ValidationContext vc, Object prevData, Object data, DefaultMutableTreeNode node);
void onSelectionRename(ValidationContext vc, Object prevData, Object data, DefaultMutableTreeNode node, ClassPanel panel);
}
}
Loading