diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 7c1572fc..b387a35c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -74,8 +74,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * http://the.bytecode.club * * TODO BUGS: - * + Removing a tab disrupts the tab order - * Tab index orders need to be recounted on removal probably * + Last selected directory isn't set on most file chooser dialogues * + Synchronized scrolling is broken * + Spam-clicking the refresh button will cause the swing thread to deadlock (Quickly opening resources used to also do this) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java index ba93b15e..3cab0afd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabRemovalEvent.java @@ -25,12 +25,12 @@ public class TabRemovalEvent implements ContainerListener if (c instanceof ClassViewer) { String workingName = ((ClassViewer) c).workingName; - BytecodeViewer.viewer.workPane.workingOn.remove(workingName); + BytecodeViewer.viewer.workPane.openedTabs.remove(workingName); } else if (c instanceof FileViewer) { String workingName = ((FileViewer) c).workingName; - BytecodeViewer.viewer.workPane.workingOn.remove(workingName); + BytecodeViewer.viewer.workPane.openedTabs.remove(workingName); } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java index 5244acee..bc8a5bb7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java @@ -7,6 +7,7 @@ import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.HashMap; +import java.util.HashSet; import javax.swing.JButton; import javax.swing.JMenuItem; import javax.swing.JPanel; @@ -51,7 +52,7 @@ public class WorkPaneMainComponent extends VisibleComponent public final JTabbedPane tabs; public final JPanel buttonPanel; public final JButton refreshClass; - public final HashMap workingOn = new HashMap<>(); + public final HashSet openedTabs = new HashSet<>(); public WorkPaneMainComponent() { @@ -178,11 +179,14 @@ public class WorkPaneMainComponent extends VisibleComponent { final String workingName = container.name + ">" + name; - if (!workingOn.containsKey(workingName)) + //create a new tab if the resource isn't opened currently + if (!openedTabs.contains(workingName)) { + resourceView.workingName = workingName; + tabs.add(resourceView); final int tabIndex = tabs.indexOfComponent(resourceView); - workingOn.put(workingName, tabIndex); + openedTabs.add(workingName); TabbedPane tabbedPane = new TabbedPane(tabIndex, workingName, container.name, name, tabs, resourceView); resourceView.tabbedPane = tabbedPane; @@ -190,16 +194,17 @@ public class WorkPaneMainComponent extends VisibleComponent tabs.setSelectedIndex(tabIndex); resourceView.refreshTitle(); } + //if the resource is already opened select this tab as the active one else { - tabs.setSelectedIndex(workingOn.get(workingName)); - - // TODO: need to look into if this exception is actually needed - // removing it for now, but keeping it incase this causes issues - try { - } catch (Exception e) { - //workingOn.remove(workingName); - e.printStackTrace(); + for(int i = 0; i < tabs.getTabCount(); i++) + { + ResourceViewer tab = ((TabbedPane)tabs.getTabComponentAt(i)).resource; + if(tab.workingName.equals(workingName)) + { + tabs.setSelectedIndex(i); + break; + } } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ResourceViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ResourceViewer.java index 6ac9508e..af21baf7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ResourceViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ResourceViewer.java @@ -35,6 +35,7 @@ public abstract class ResourceViewer extends JPanel { public ClassNode cn; public String name; + public String workingName; public FileContainer container; public TabbedPane tabbedPane;