Skip to content

Commit ff793b5

Browse files
committed
Tabbed Plugin Exceptions
1 parent 9bf7e01 commit ff793b5

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import the.bytecode.club.bytecodeviewer.Configuration;
1212
import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsole;
1313
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ComponentViewer;
14+
import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
1415
import the.bytecode.club.bytecodeviewer.resources.IconResources;
1516
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
1617

@@ -116,7 +117,7 @@ private void setupFrame(String error, String author)
116117
//embed error log as a new tab
117118
if(Configuration.errorLogsAsNewTab)
118119
{
119-
ComponentViewer.addComponentAsTab("Error #" + errorCounter++, getComponent(0));
120+
PluginManager.addExceptionUI(this, "Error #" + errorCounter++);
120121
}
121122
//pop open a new window frame
122123
else

src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.swing.filechooser.FileFilter;
88
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
99
import the.bytecode.club.bytecodeviewer.Configuration;
10+
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
1011
import the.bytecode.club.bytecodeviewer.api.Plugin;
1112
import the.bytecode.club.bytecodeviewer.api.PluginConsole;
1213
import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsoleTabbed;
@@ -55,7 +56,10 @@ public final class PluginManager
5556

5657
private static Plugin activePlugin;
5758
private static JFrameConsoleTabbed activeTabbedConsole;
59+
private static JFrameConsoleTabbed activeTabbedException;
60+
private static HashMap<String, ExceptionUI> exceptionTabs = new HashMap<>();
5861
private static int consoleCount = 0;
62+
private static int exceptionCount = 0;
5963

6064
static
6165
{
@@ -85,9 +89,12 @@ public static void runPlugin(Plugin newPluginInstance)
8589
{
8690
//reset the console count
8791
consoleCount = 0;
92+
exceptionCount = 0;
8893

8994
//reset the active tabbed console
9095
activeTabbedConsole = null;
96+
activeTabbedException = null;
97+
exceptionTabs.clear();
9198

9299
//reset the active plugin
93100
activePlugin = newPluginInstance;
@@ -122,6 +129,43 @@ public static void runPlugin(File f) throws Throwable
122129
runPlugin(p);
123130
}
124131

132+
/**
133+
* Add an active console from a plugin being ran
134+
*/
135+
public static void addExceptionUI(ExceptionUI ui, String title)
136+
{
137+
if(activePlugin == null)
138+
{
139+
ui.setLocationRelativeTo(BytecodeViewer.viewer);
140+
ui.setVisible(true);
141+
return;
142+
}
143+
144+
final String name = (activePlugin == null || activePlugin.activeContainer == null)
145+
? ("#" + (activeTabbedException.getTabbedPane().getTabCount() + 1)) : activePlugin.activeContainer.name;
146+
147+
ExceptionUI existingUI = exceptionTabs.get(name);
148+
149+
int id = exceptionCount++;
150+
if(activeTabbedException == null)
151+
{
152+
activeTabbedException = new JFrameConsoleTabbed(title);
153+
154+
if(Configuration.pluginConsoleAsNewTab)
155+
ComponentViewer.addComponentAsTab(title, activeTabbedException.getComponent(0));
156+
else
157+
activeTabbedException.setVisible(true);
158+
}
159+
160+
if(existingUI == null)
161+
{
162+
activeTabbedException.addConsole(ui.getComponent(0), name);
163+
exceptionTabs.put(name, ui);
164+
}
165+
else
166+
existingUI.appendText("\n\r" + ui.getTextArea().getText());
167+
}
168+
125169
/**
126170
* Add an active console from a plugin being ran
127171
*/

0 commit comments

Comments
 (0)