Fixed Tab Removal Order

This commit is contained in:
Konloch 2021-06-26 07:52:28 -07:00
parent 2d80244e1f
commit 6dac259299
4 changed files with 19 additions and 15 deletions

View file

@ -74,8 +74,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
* http://the.bytecode.club * http://the.bytecode.club
* *
* TODO BUGS: * 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 * + Last selected directory isn't set on most file chooser dialogues
* + Synchronized scrolling is broken * + Synchronized scrolling is broken
* + Spam-clicking the refresh button will cause the swing thread to deadlock (Quickly opening resources used to also do this) * + Spam-clicking the refresh button will cause the swing thread to deadlock (Quickly opening resources used to also do this)

View file

@ -25,12 +25,12 @@ public class TabRemovalEvent implements ContainerListener
if (c instanceof ClassViewer) if (c instanceof ClassViewer)
{ {
String workingName = ((ClassViewer) c).workingName; String workingName = ((ClassViewer) c).workingName;
BytecodeViewer.viewer.workPane.workingOn.remove(workingName); BytecodeViewer.viewer.workPane.openedTabs.remove(workingName);
} }
else if (c instanceof FileViewer) else if (c instanceof FileViewer)
{ {
String workingName = ((FileViewer) c).workingName; String workingName = ((FileViewer) c).workingName;
BytecodeViewer.viewer.workPane.workingOn.remove(workingName); BytecodeViewer.viewer.workPane.openedTabs.remove(workingName);
} }
} }
} }

View file

@ -7,6 +7,7 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -51,7 +52,7 @@ public class WorkPaneMainComponent extends VisibleComponent
public final JTabbedPane tabs; public final JTabbedPane tabs;
public final JPanel buttonPanel; public final JPanel buttonPanel;
public final JButton refreshClass; public final JButton refreshClass;
public final HashMap<String, Integer> workingOn = new HashMap<>(); public final HashSet<String> openedTabs = new HashSet<>();
public WorkPaneMainComponent() public WorkPaneMainComponent()
{ {
@ -178,11 +179,14 @@ public class WorkPaneMainComponent extends VisibleComponent
{ {
final String workingName = container.name + ">" + name; 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); tabs.add(resourceView);
final int tabIndex = tabs.indexOfComponent(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); TabbedPane tabbedPane = new TabbedPane(tabIndex, workingName, container.name, name, tabs, resourceView);
resourceView.tabbedPane = tabbedPane; resourceView.tabbedPane = tabbedPane;
@ -190,16 +194,17 @@ public class WorkPaneMainComponent extends VisibleComponent
tabs.setSelectedIndex(tabIndex); tabs.setSelectedIndex(tabIndex);
resourceView.refreshTitle(); resourceView.refreshTitle();
} }
//if the resource is already opened select this tab as the active one
else else
{ {
tabs.setSelectedIndex(workingOn.get(workingName)); for(int i = 0; i < tabs.getTabCount(); i++)
{
// TODO: need to look into if this exception is actually needed ResourceViewer tab = ((TabbedPane)tabs.getTabComponentAt(i)).resource;
// removing it for now, but keeping it incase this causes issues if(tab.workingName.equals(workingName))
try { {
} catch (Exception e) { tabs.setSelectedIndex(i);
//workingOn.remove(workingName); break;
e.printStackTrace(); }
} }
} }
} }

View file

@ -35,6 +35,7 @@ public abstract class ResourceViewer extends JPanel
{ {
public ClassNode cn; public ClassNode cn;
public String name; public String name;
public String workingName;
public FileContainer container; public FileContainer container;
public TabbedPane tabbedPane; public TabbedPane tabbedPane;