mirror of
https://github.com/deathmarine/Luyten.git
synced 2024-11-26 22:20:32 +00:00
Fix duplicate file names replacing tabs (Fixes #20)
This is done by comparing the paths instead of the file names when calculating if a new tab should be opened and also checking if component at the found index is actually the one we want to open before switching to it.
This commit is contained in:
parent
27c6bba26f
commit
d2e0a2b411
@ -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) {
|
||||
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);
|
||||
house.setSelectedIndex(house.indexOfTab(title));
|
||||
int index = house.indexOfTab(title);
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user