Active Resource API Changes

This commit is contained in:
Konloch 2021-07-06 20:05:35 -07:00
parent d6be70dfb2
commit 99fde7156e
7 changed files with 41 additions and 26 deletions

View file

@ -12,7 +12,6 @@ import org.apache.commons.io.FileUtils;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bootloader.Boot;
import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.gui.components.*;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
@ -276,14 +275,40 @@ public class BytecodeViewer
return Configuration.java;
}
/**
* Returns true if there is currently a tab open with a resource inside of it
*/
public static boolean hasActiveResource()
{
return getActiveResource() != null;
}
/**
* Returns true if there is currently a tab open with a resource inside of it
*/
public static boolean isActiveResourceClass()
{
ResourceViewer resource = getActiveResource();
return resource instanceof ClassViewer;
}
/**
* Returns the currently opened & viewed resource
*/
public static ResourceViewer getActiveResource()
{
return BytecodeViewer.viewer.workPane.getActiveResource();
}
/**
* Returns the currently opened ClassNode
*
* @return the currently opened ClassNode
*/
public static ClassNode getCurrentlyOpenedClassNode() {
return viewer.workPane.getCurrentViewer().cn;
public static ClassNode getCurrentlyOpenedClassNode()
{
return getActiveResource().cn;
}
/**

View file

@ -96,8 +96,9 @@ public class GlobalHotKeys
else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
{
Configuration.lastHotKeyExecuted = System.currentTimeMillis();
if (BytecodeViewer.viewer.workPane.getCurrentViewer() != null)
BytecodeViewer.viewer.workPane.tabs.remove(BytecodeViewer.viewer.workPane.getCurrentViewer());
if (BytecodeViewer.hasActiveResource())
BytecodeViewer.viewer.workPane.tabs.remove(BytecodeViewer.viewer.workPane.getActiveResource());
}
}
}

View file

@ -16,8 +16,6 @@ import javax.swing.tree.DefaultMutableTreeNode;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.WorkPaneMainComponent;
import the.bytecode.club.bytecodeviewer.gui.components.VisibleComponent;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
@ -179,11 +177,10 @@ public class SearchBoxPane extends VisibleComponent
}
else if (radius == SearchRadius.Current_Class)
{
final ResourceViewer cv = Objects.requireNonNull(MainViewerGUI.getComponent(WorkPaneMainComponent.class)).getCurrentViewer();
final ResourceViewer cv = BytecodeViewer.getActiveResource();
if (cv != null)
{
searchType.details.search(cv.container, cv.cn, srn, exact.isSelected());
}
}
}

View file

@ -211,7 +211,7 @@ public class WorkPaneMainComponent extends VisibleComponent
}
}
public ResourceViewer getCurrentViewer() {
public ResourceViewer getActiveResource() {
return (ResourceViewer) tabs.getSelectedComponent();
}

View file

@ -15,7 +15,6 @@ import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Resources;
import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
/***************************************************************************
@ -58,19 +57,13 @@ public class CodeSequenceDiagram extends Plugin
if (BytecodeViewer.promptIfNoLoadedClasses())
return;
if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer))
if (!BytecodeViewer.isActiveResourceClass())
{
BytecodeViewer.showMessage("First open a class file.");
return;
}
ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
if (c == null)
{
BytecodeViewer.showMessage("Current viewer ClassNode is null inside of CodeSequenceDiagram. Please report to @Konloch");
return;
}
ClassNode c = BytecodeViewer.getCurrentlyOpenedClassNode();
JFrame frame = new JFrame("Code Sequence Diagram - " + c.name);
frame.setIconImages(Resources.iconList);

View file

@ -5,10 +5,8 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
import the.bytecode.club.bytecodeviewer.util.DialogueUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
@ -182,7 +180,7 @@ public class ResourceDecompiling
if (BytecodeViewer.promptIfNoLoadedClasses())
return;
if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer))
if (!BytecodeViewer.isActiveResourceClass())
{
BytecodeViewer.showMessage("First open a class file.");
return;
@ -193,7 +191,7 @@ public class ResourceDecompiling
if (BytecodeViewer.autoCompileSuccessful())
return;
final String s = BytecodeViewer.viewer.workPane.getCurrentViewer().cn.name;
final String s = BytecodeViewer.getCurrentlyOpenedClassNode().name;
if (s == null)
return;

View file

@ -14,8 +14,9 @@ public class RefreshWorkPane implements ActionListener
@Override
public void actionPerformed(ActionEvent e)
{
if (BytecodeViewer.viewer.refreshOnChange.isSelected()) {
if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null)
if (BytecodeViewer.viewer.refreshOnChange.isSelected())
{
if (!BytecodeViewer.hasActiveResource())
return;
BytecodeViewer.viewer.workPane.refreshClass.doClick();