Skip to content

Commit 673e53b

Browse files
authored
Fix import into currently open library (#5717)
Remove unnecessary parallel execution of `addTab`, which fixes #5537.
1 parent d0f6c2b commit 673e53b

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
6262
- The "Automatically set file links" feature now follows symbolic links. [#5664](https://github.com/JabRef/jabref/issues/5664)
6363
- After successful import of one or multiple bib entries the main table scrolls to the first imported entry [#5383](https://github.com/JabRef/jabref/issues/5383)
6464
- We fixed an exception which occurred when an invalid jstyle was loaded. [#5452](https://github.com/JabRef/jabref/issues/5452)
65+
- We fixed an issue where the command line arguments `importBibtex` and `importToOpen` did not import into the currently open library, but opened a new one. [#5537](https://github.com/JabRef/jabref/issues/5537)
6566
- We fixed an error where the preview theme did not adapt to the "Dark" mode [#5463](https://github.com/JabRef/jabref/issues/5463)
6667
- We fixed an issue where the merge dialog showed the wrong text colour in "Dark" mode [#5516](https://github.com/JabRef/jabref/issues/5516)
6768
- We fixed visibility issues with the scrollbar and group selection highlight in "Dark" mode, and enabled "Dark" mode for the OpenOffice preview in the style selection window. [#5522](https://github.com/JabRef/jabref/issues/5522)

src/main/java/org/jabref/JabRefGUI.java

+34-33
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.io.File;
44
import java.sql.SQLException;
55
import java.util.ArrayList;
6-
import java.util.Iterator;
76
import java.util.List;
7+
import java.util.stream.Collectors;
88

99
import javafx.application.Platform;
1010
import javafx.scene.Scene;
@@ -97,6 +97,13 @@ private void openDatabases() {
9797
openLastEditedDatabases();
9898
}
9999

100+
// Remove invalid databases
101+
List<ParserResult> invalidDatabases = bibDatabases.stream()
102+
.filter(ParserResult::isInvalid)
103+
.collect(Collectors.toList());
104+
failed.addAll(invalidDatabases);
105+
bibDatabases.removeAll(invalidDatabases);
106+
100107
// passed file (we take the first one) should be focused
101108
String focusedFile = bibDatabases.stream()
102109
.findFirst()
@@ -106,40 +113,34 @@ private void openDatabases() {
106113

107114
// Add all bibDatabases databases to the frame:
108115
boolean first = false;
109-
if (!bibDatabases.isEmpty()) {
110-
for (Iterator<ParserResult> parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext();) {
111-
ParserResult pr = parserResultIterator.next();
112-
// Define focused tab
113-
if (pr.getFile().filter(path -> path.getAbsolutePath().equals(focusedFile)).isPresent()) {
114-
first = true;
115-
}
116+
for (ParserResult pr : bibDatabases) {
117+
// Define focused tab
118+
if (pr.getFile().filter(path -> path.getAbsolutePath().equals(focusedFile)).isPresent()) {
119+
first = true;
120+
}
116121

117-
if (pr.isInvalid()) {
118-
failed.add(pr);
119-
parserResultIterator.remove();
120-
} else if (pr.getDatabase().isShared()) {
121-
try {
122-
new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
123-
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
124-
NotASharedDatabaseException e) {
125-
pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file
126-
pr.getDatabase().clearSharedDatabaseID();
127-
128-
LOGGER.error("Connection error", e);
129-
mainFrame.getDialogService().showErrorDialogAndWait(
130-
Localization.lang("Connection error"),
131-
Localization.lang("A local copy will be opened."),
132-
e);
133-
}
134-
toOpenTab.add(pr);
135-
} else if (pr.toOpenTab()) {
136-
// things to be appended to an opened tab should be done after opening all tabs
137-
// add them to the list
138-
toOpenTab.add(pr);
139-
} else {
140-
mainFrame.addParserResult(pr, first);
141-
first = false;
122+
if (pr.getDatabase().isShared()) {
123+
try {
124+
new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
125+
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
126+
NotASharedDatabaseException e) {
127+
pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file
128+
pr.getDatabase().clearSharedDatabaseID();
129+
130+
LOGGER.error("Connection error", e);
131+
mainFrame.getDialogService().showErrorDialogAndWait(
132+
Localization.lang("Connection error"),
133+
Localization.lang("A local copy will be opened."),
134+
e);
142135
}
136+
toOpenTab.add(pr);
137+
} else if (pr.toOpenTab()) {
138+
// things to be appended to an opened tab should be done after opening all tabs
139+
// add them to the list
140+
toOpenTab.add(pr);
141+
} else {
142+
mainFrame.addParserResult(pr, first);
143+
first = false;
143144
}
144145
}
145146

src/main/java/org/jabref/gui/JabRefFrame.java

+22-24
Original file line numberDiff line numberDiff line change
@@ -972,37 +972,35 @@ public void updateAllTabTitles() {
972972
}
973973

974974
public void addTab(BasePanel basePanel, boolean raisePanel) {
975-
DefaultTaskExecutor.runInJavaFXThread(() -> {
976-
// add tab
977-
Tab newTab = new Tab(basePanel.getTabTitle(), basePanel);
978-
tabbedPane.getTabs().add(newTab);
979-
newTab.setOnCloseRequest(event -> {
980-
closeTab((BasePanel) newTab.getContent());
981-
event.consume();
982-
});
975+
// add tab
976+
Tab newTab = new Tab(basePanel.getTabTitle(), basePanel);
977+
tabbedPane.getTabs().add(newTab);
978+
newTab.setOnCloseRequest(event -> {
979+
closeTab((BasePanel) newTab.getContent());
980+
event.consume();
981+
});
983982

984-
// update all tab titles
985-
updateAllTabTitles();
983+
// update all tab titles
984+
updateAllTabTitles();
986985

987-
if (raisePanel) {
988-
tabbedPane.getSelectionModel().select(newTab);
989-
}
986+
if (raisePanel) {
987+
tabbedPane.getSelectionModel().select(newTab);
988+
}
990989

991-
// Register undo/redo listener
992-
basePanel.getUndoManager().registerListener(new UndoRedoEventManager());
990+
// Register undo/redo listener
991+
basePanel.getUndoManager().registerListener(new UndoRedoEventManager());
993992

994-
BibDatabaseContext context = basePanel.getBibDatabaseContext();
993+
BibDatabaseContext context = basePanel.getBibDatabaseContext();
995994

996-
if (readyForAutosave(context)) {
997-
AutosaveManager autosaver = AutosaveManager.start(context);
998-
autosaver.registerListener(new AutosaveUIManager(basePanel));
999-
}
995+
if (readyForAutosave(context)) {
996+
AutosaveManager autosaver = AutosaveManager.start(context);
997+
autosaver.registerListener(new AutosaveUIManager(basePanel));
998+
}
1000999

1001-
BackupManager.start(context, Globals.entryTypesManager, prefs);
1000+
BackupManager.start(context, Globals.entryTypesManager, prefs);
10021001

1003-
// Track opening
1004-
trackOpenNewDatabase(basePanel);
1005-
});
1002+
// Track opening
1003+
trackOpenNewDatabase(basePanel);
10061004
}
10071005

10081006
private void trackOpenNewDatabase(BasePanel basePanel) {

0 commit comments

Comments
 (0)