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

Fix deobfuscation icons not updating after initial stat generation completes #250

Merged
merged 2 commits into from
Feb 10, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import org.quiltmc.enigma.api.service.ReadWriteService;
import org.quiltmc.enigma.api.translation.representation.entry.LocalVariableEntry;
import org.quiltmc.enigma.gui.dialog.CrashDialog;
import org.quiltmc.enigma.gui.docker.ClassesDocker;
import org.quiltmc.enigma.gui.docker.CollabDocker;
import org.quiltmc.enigma.gui.docker.Docker;
import org.quiltmc.enigma.gui.network.IntegratedEnigmaClient;
import org.quiltmc.enigma.impl.analysis.IndexTreeBuilder;
import org.quiltmc.enigma.api.analysis.tree.MethodImplementationsTreeNode;
Expand All @@ -29,7 +32,6 @@
import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider;
import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.dialog.ProgressDialog;
import org.quiltmc.enigma.gui.docker.CollabDocker;
import org.quiltmc.enigma.api.stats.StatType;
import org.quiltmc.enigma.gui.util.History;
import org.quiltmc.enigma.network.ClientPacketHandler;
Expand Down Expand Up @@ -181,6 +183,13 @@ public CompletableFuture<Void> openMappings(ReadWriteService readWriteService, P
ProgressListener progressListener = ProgressListener.createEmpty();
this.gui.getMainWindow().getStatusBar().syncWith(progressListener);
this.statsGenerator.generate(progressListener, EditableType.toStatTypes(this.gui.getEditableTypes()), false);

// ensure all class tree dockers show the update to the stats icons
for (Docker docker : this.gui.getDockerManager().getActiveDockers().values()) {
if (docker instanceof ClassesDocker) {
docker.repaint();
}
}
}).start();
} catch (MappingParseException e) {
JOptionPane.showMessageDialog(this.gui.getFrame(), e.getMessage());
Expand Down
36 changes: 30 additions & 6 deletions enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.quiltmc.enigma.gui.docker.component.DockerSelector;
import org.quiltmc.enigma.gui.docker.component.Draggable;

import javax.annotation.Nullable;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import java.awt.BorderLayout;
Expand All @@ -17,7 +18,9 @@
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -37,6 +40,9 @@ public class Dock extends JPanel {
*/
private Docker.VerticalLocation hovered;
private boolean isSplit;
/**
* {@code null} if the view is currently split.
*/
private DockerContainer unifiedDock;
private Docker toSave;

Expand Down Expand Up @@ -145,7 +151,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea
if (verticalLocation == Docker.VerticalLocation.BOTTOM || verticalLocation == Docker.VerticalLocation.TOP) {
// if we'd be leaving empty space via opening, we want to host the docker as the full panel
// this is to avoid wasting space
if (avoidEmptySpace && ((this.isSplit && this.getDock(verticalLocation.inverse()).getHostedDocker() == null)
if (avoidEmptySpace && ((this.isSplit && this.getContainer(verticalLocation.inverse()).getHostedDocker() == null)
|| (!this.isSplit && this.unifiedDock.getHostedDocker() == null)
|| (!this.isSplit && this.unifiedDock.getHostedDocker().getId().equals(docker.getId())))) {
this.host(docker, Docker.VerticalLocation.FULL);
Expand All @@ -158,7 +164,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea

// preserve divider location and host
int location = this.splitPane.getDividerLocation();
this.getDock(verticalLocation).setHostedDocker(docker);
this.getContainer(verticalLocation).setHostedDocker(docker);
this.splitPane.setDividerLocation(location);

if (this.toSave != null && !this.toSave.equals(docker)) {
Expand Down Expand Up @@ -229,12 +235,12 @@ public void removeDocker(Docker.VerticalLocation location) {

private void removeDocker(Docker.VerticalLocation location, boolean avoidEmptySpace) {
// do not leave empty dockers
if (avoidEmptySpace && location != Docker.VerticalLocation.FULL && this.getDock(location.inverse()).getHostedDocker() != null) {
this.host(this.getDock(location.inverse()).getHostedDocker(), Docker.VerticalLocation.FULL, false);
if (avoidEmptySpace && location != Docker.VerticalLocation.FULL && this.getContainer(location.inverse()).getHostedDocker() != null) {
this.host(this.getContainer(location.inverse()).getHostedDocker(), Docker.VerticalLocation.FULL, false);
return;
}

DockerContainer container = this.getDock(location);
DockerContainer container = this.getContainer(location);
if (container != null) {
container.setHostedDocker(null);
}
Expand Down Expand Up @@ -308,7 +314,24 @@ public boolean dropDockerFromMouse(Docker docker, MouseEvent event) {
return false;
}

public DockerContainer getDock(Docker.VerticalLocation verticalLocation) {
/**
* {@return a map of all hosted dockers, keyed by their locations}
*/
public Map<Docker.VerticalLocation, Docker> getHostedDockers() {
Map<Docker.VerticalLocation, Docker> map = new HashMap<>();
for (Docker.VerticalLocation verticalLocation : Docker.VerticalLocation.values()) {
var container = this.getContainer(verticalLocation);

if (container != null && container.getHostedDocker() != null) {
map.put(verticalLocation, container.getHostedDocker());
}
}

return map;
}

@Nullable
private DockerContainer getContainer(Docker.VerticalLocation verticalLocation) {
return switch (verticalLocation) {
case TOP -> this.topDock;
case BOTTOM -> this.bottomDock;
Expand Down Expand Up @@ -368,6 +391,7 @@ private static class DockerContainer extends JPanel {
this.hostedDocker = null;
}

@Nullable
public Docker getHostedDocker() {
return this.hostedDocker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class DockerManager {
private final Map<Class<? extends Docker>, Docker> dockers = new LinkedHashMap<>();
Expand Down Expand Up @@ -35,6 +36,25 @@ public Dock getLeftDock() {
return this.leftDock;
}

/**
* {@return a map of all currently active dockers, keyed by their locations}
*/
public Map<Docker.Location, Docker> getActiveDockers() {
Map<Docker.Location, Docker> activeDockers = new HashMap<>();

activeDockers.putAll(this.leftDock.getHostedDockers().entrySet().stream().collect(Collectors.toMap(
entry -> new Docker.Location(Docker.Side.LEFT, entry.getKey()),
Map.Entry::getValue
)));

activeDockers.putAll(this.rightDock.getHostedDockers().entrySet().stream().collect(Collectors.toMap(
entry -> new Docker.Location(Docker.Side.RIGHT, entry.getKey()),
Map.Entry::getValue
)));

return activeDockers;
}

/**
* Hosts a docker, making it visible, in the location provided.
* @param docker the docker to be hosted
Expand Down