Tabbed Plugin Exceptions

This commit is contained in:
Konloch 2021-07-23 20:26:23 -07:00
parent 9bf7e012b3
commit ff793b5fc3
2 changed files with 46 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsole;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ComponentViewer;
import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
import the.bytecode.club.bytecodeviewer.resources.IconResources;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
@ -116,7 +117,7 @@ public class ExceptionUI extends JFrameConsole
//embed error log as a new tab
if(Configuration.errorLogsAsNewTab)
{
ComponentViewer.addComponentAsTab("Error #" + errorCounter++, getComponent(0));
PluginManager.addExceptionUI(this, "Error #" + errorCounter++);
}
//pop open a new window frame
else

View File

@ -7,6 +7,7 @@ import java.util.List;
import javax.swing.filechooser.FileFilter;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.api.PluginConsole;
import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsoleTabbed;
@ -55,7 +56,10 @@ public final class PluginManager
private static Plugin activePlugin;
private static JFrameConsoleTabbed activeTabbedConsole;
private static JFrameConsoleTabbed activeTabbedException;
private static HashMap<String, ExceptionUI> exceptionTabs = new HashMap<>();
private static int consoleCount = 0;
private static int exceptionCount = 0;
static
{
@ -85,9 +89,12 @@ public final class PluginManager
{
//reset the console count
consoleCount = 0;
exceptionCount = 0;
//reset the active tabbed console
activeTabbedConsole = null;
activeTabbedException = null;
exceptionTabs.clear();
//reset the active plugin
activePlugin = newPluginInstance;
@ -122,6 +129,43 @@ public final class PluginManager
runPlugin(p);
}
/**
* Add an active console from a plugin being ran
*/
public static void addExceptionUI(ExceptionUI ui, String title)
{
if(activePlugin == null)
{
ui.setLocationRelativeTo(BytecodeViewer.viewer);
ui.setVisible(true);
return;
}
final String name = (activePlugin == null || activePlugin.activeContainer == null)
? ("#" + (activeTabbedException.getTabbedPane().getTabCount() + 1)) : activePlugin.activeContainer.name;
ExceptionUI existingUI = exceptionTabs.get(name);
int id = exceptionCount++;
if(activeTabbedException == null)
{
activeTabbedException = new JFrameConsoleTabbed(title);
if(Configuration.pluginConsoleAsNewTab)
ComponentViewer.addComponentAsTab(title, activeTabbedException.getComponent(0));
else
activeTabbedException.setVisible(true);
}
if(existingUI == null)
{
activeTabbedException.addConsole(ui.getComponent(0), name);
exceptionTabs.put(name, ui);
}
else
existingUI.appendText("\n\r" + ui.getTextArea().getText());
}
/**
* Add an active console from a plugin being ran
*/