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

View File

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