From d0b075ca1b7c4bbbfe3b34da570a3c9a5e239888 Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 29 Sep 2024 09:05:01 -0600 Subject: [PATCH] Added GetLastActiveClass To make temporary plugins work with the BCV.getCurrentlyOpenedClassNode() API, we have to store the last active class viewer in memory There is probably a better way of doing this, but the only code using these APIs are user plugins, so it shouldn't impact the rest of the program if we have a resource mismatch --- .../club/bytecodeviewer/BytecodeViewer.java | 10 +++++++++- .../gui/resourceviewer/Workspace.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index c31fce83..14ce11c7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -350,7 +350,15 @@ public class BytecodeViewer */ public static ClassNode getCurrentlyOpenedClassNode() { - return getActiveResource().resource.getResourceClassNode(); + return getActiveClass().resource.getResourceClassNode(); + } + + /** + * Returns the currently opened & viewed resource + */ + public static ResourceViewer getActiveClass() + { + return BytecodeViewer.viewer.workPane.getLastActiveClass(); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java index 9875fda4..cb5b1154 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java @@ -54,6 +54,7 @@ public class Workspace extends TranslatedVisibleComponent public final JButton refreshClass; public final Set openedTabs = new HashSet<>(); public HashMap classFiles = new HashMap<>(); + private ResourceViewer lastActiveClassViewer; public Workspace() { @@ -61,6 +62,14 @@ public class Workspace extends TranslatedVisibleComponent this.tabs = new DraggableTabbedPane(); + tabs.addChangeListener(e -> + { + ResourceViewer viewer = (ResourceViewer) tabs.getSelectedComponent(); + + if(viewer instanceof ClassViewer) + lastActiveClassViewer = viewer; + }); + // configure popup menu of close tabs JTabbedPanePopupMenuTabsCloser popupMenuTabsCloser = new JTabbedPanePopupMenuTabsCloser(this.tabs); PopupMenuTabsCloseConfiguration.Builder builder = new PopupMenuTabsCloseConfiguration.Builder(); @@ -173,6 +182,11 @@ public class Workspace extends TranslatedVisibleComponent return (ResourceViewer) tabs.getSelectedComponent(); } + public ResourceViewer getLastActiveClass() + { + return lastActiveClassViewer; + } + public Component[] getLoadedViewers() { return tabs.getComponents();