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
*
* 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)

View File

@ -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);
}
}
}

View File

@ -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<String, Integer> workingOn = new HashMap<>();
public final HashSet<String> 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;
}
}
}
}

View File

@ -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;