Skip to content

Commit

Permalink
Added GetLastActiveClass
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Konloch committed Sep 29, 2024
1 parent 269aed2 commit d0b075c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,15 @@ public static ResourceViewer getActiveResource()
*/
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@ public class Workspace extends TranslatedVisibleComponent
public final JButton refreshClass;
public final Set<String> openedTabs = new HashSet<>();
public HashMap<String, ClassFileContainer> classFiles = new HashMap<>();
private ResourceViewer lastActiveClassViewer;

public Workspace()
{
super("Workspace", TranslatedComponents.WORK_SPACE);

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();
Expand Down Expand Up @@ -173,6 +182,11 @@ public ResourceViewer getActiveResource()
return (ResourceViewer) tabs.getSelectedComponent();
}

public ResourceViewer getLastActiveClass()
{
return lastActiveClassViewer;
}

public Component[] getLoadedViewers()
{
return tabs.getComponents();
Expand Down

0 comments on commit d0b075c

Please sign in to comment.