Merge pull request #226 from Phoenix616/pr/fix-duplicate-tab-names

Fix duplicate file names replacing tabs (Fixes #20)
This commit is contained in:
Josh 2019-12-04 12:46:37 -05:00 committed by GitHub
commit a8622231d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View File

@ -1,5 +1,6 @@
package us.deathmarine.luyten; package us.deathmarine.luyten;
import java.awt.Component;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
@ -198,15 +199,25 @@ public class Model extends JSplitPane {
try { try {
final String title = open.name; final String title = open.name;
RTextScrollPane rTextScrollPane = open.scrollPane; RTextScrollPane rTextScrollPane = open.scrollPane;
if (house.indexOfTab(title) < 0) {
house.addTab(title, rTextScrollPane);
house.setSelectedIndex(house.indexOfTab(title));
int index = house.indexOfTab(title); int index = house.indexOfTab(title);
if (index > -1 && house.getTabComponentAt(index) != open.scrollPane) {
index = -1;
for (int i = 0; i < house.getTabCount(); i++) {
if (house.getComponentAt(i) == open.scrollPane) {
index = i;
break;
}
}
}
if (index < 0) {
house.addTab(title, rTextScrollPane);
index = house.indexOfComponent(rTextScrollPane);
house.setSelectedIndex(index);
Tab ct = new Tab(title); Tab ct = new Tab(title);
ct.getButton().addMouseListener(new CloseTab(title)); ct.getButton().addMouseListener(new CloseTab(title));
house.setTabComponentAt(index, ct); house.setTabComponentAt(index, ct);
} else { } else {
house.setSelectedIndex(house.indexOfTab(title)); house.setSelectedIndex(index);
} }
open.onAddedToScreen(); open.onAddedToScreen();
} catch (Exception e) { } catch (Exception e) {
@ -384,13 +395,12 @@ public class Model extends JSplitPane {
} }
OpenFile sameTitledOpen = null; OpenFile sameTitledOpen = null;
for (OpenFile nextOpen : hmap) { for (OpenFile nextOpen : hmap) {
if (tabTitle.equals(nextOpen.name)) { if (tabTitle.equals(nextOpen.name) && path.equals(nextOpen.path) && type.equals(nextOpen.getType())) {
sameTitledOpen = nextOpen; sameTitledOpen = nextOpen;
break; break;
} }
} }
if (sameTitledOpen != null && path.equals(sameTitledOpen.path) && type.equals(sameTitledOpen.getType()) if (sameTitledOpen != null && sameTitledOpen.isContentValid()) {
&& sameTitledOpen.isContentValid()) {
sameTitledOpen.setInitialNavigationLink(navigatonLink); sameTitledOpen.setInitialNavigationLink(navigatonLink);
addOrSwitchToTab(sameTitledOpen); addOrSwitchToTab(sameTitledOpen);
return; return;
@ -430,12 +440,12 @@ public class Model extends JSplitPane {
} }
OpenFile sameTitledOpen = null; OpenFile sameTitledOpen = null;
for (OpenFile nextOpen : hmap) { for (OpenFile nextOpen : hmap) {
if (tabTitle.equals(nextOpen.name)) { if (tabTitle.equals(nextOpen.name) && path.equals(nextOpen.path)) {
sameTitledOpen = nextOpen; sameTitledOpen = nextOpen;
break; break;
} }
} }
if (sameTitledOpen != null && path.equals(sameTitledOpen.path)) { if (sameTitledOpen != null) {
addOrSwitchToTab(sameTitledOpen); addOrSwitchToTab(sameTitledOpen);
return; return;
} }

View File

@ -820,7 +820,7 @@ public class OpenFile implements SyntaxConstants {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode());
return result; return result;
} }
@ -833,10 +833,10 @@ public class OpenFile implements SyntaxConstants {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
OpenFile other = (OpenFile) obj; OpenFile other = (OpenFile) obj;
if (name == null) { if (path == null) {
if (other.name != null) if (other.path != null)
return false; return false;
} else if (!name.equals(other.name)) } else if (!path.equals(other.path))
return false; return false;
return true; return true;
} }