diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a75af1b603..e62873f5eed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - The "Automatically set file links" feature now follows symbolic links. [#5664](https://github.com/JabRef/jabref/issues/5664) - 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) - We fixed an exception which occurred when an invalid jstyle was loaded. [#5452](https://github.com/JabRef/jabref/issues/5452) +- 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) - We fixed an error where the preview theme did not adapt to the "Dark" mode [#5463](https://github.com/JabRef/jabref/issues/5463) - We fixed an issue where the merge dialog showed the wrong text colour in "Dark" mode [#5516](https://github.com/JabRef/jabref/issues/5516) - 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) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index e5070ca912b..4ddd788eff9 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -3,8 +3,8 @@ import java.io.File; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; import javafx.application.Platform; import javafx.scene.Scene; @@ -97,6 +97,13 @@ private void openDatabases() { openLastEditedDatabases(); } + // Remove invalid databases + List invalidDatabases = bibDatabases.stream() + .filter(ParserResult::isInvalid) + .collect(Collectors.toList()); + failed.addAll(invalidDatabases); + bibDatabases.removeAll(invalidDatabases); + // passed file (we take the first one) should be focused String focusedFile = bibDatabases.stream() .findFirst() @@ -106,40 +113,34 @@ private void openDatabases() { // Add all bibDatabases databases to the frame: boolean first = false; - if (!bibDatabases.isEmpty()) { - for (Iterator parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext();) { - ParserResult pr = parserResultIterator.next(); - // Define focused tab - if (pr.getFile().filter(path -> path.getAbsolutePath().equals(focusedFile)).isPresent()) { - first = true; - } + for (ParserResult pr : bibDatabases) { + // Define focused tab + if (pr.getFile().filter(path -> path.getAbsolutePath().equals(focusedFile)).isPresent()) { + first = true; + } - if (pr.isInvalid()) { - failed.add(pr); - parserResultIterator.remove(); - } else if (pr.getDatabase().isShared()) { - try { - new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr); - } catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | - NotASharedDatabaseException e) { - pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file - pr.getDatabase().clearSharedDatabaseID(); - - LOGGER.error("Connection error", e); - mainFrame.getDialogService().showErrorDialogAndWait( - Localization.lang("Connection error"), - Localization.lang("A local copy will be opened."), - e); - } - toOpenTab.add(pr); - } else if (pr.toOpenTab()) { - // things to be appended to an opened tab should be done after opening all tabs - // add them to the list - toOpenTab.add(pr); - } else { - mainFrame.addParserResult(pr, first); - first = false; + if (pr.getDatabase().isShared()) { + try { + new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr); + } catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | + NotASharedDatabaseException e) { + pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file + pr.getDatabase().clearSharedDatabaseID(); + + LOGGER.error("Connection error", e); + mainFrame.getDialogService().showErrorDialogAndWait( + Localization.lang("Connection error"), + Localization.lang("A local copy will be opened."), + e); } + toOpenTab.add(pr); + } else if (pr.toOpenTab()) { + // things to be appended to an opened tab should be done after opening all tabs + // add them to the list + toOpenTab.add(pr); + } else { + mainFrame.addParserResult(pr, first); + first = false; } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 39c5c3c72b3..541da4646e2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -972,37 +972,35 @@ public void updateAllTabTitles() { } public void addTab(BasePanel basePanel, boolean raisePanel) { - DefaultTaskExecutor.runInJavaFXThread(() -> { - // add tab - Tab newTab = new Tab(basePanel.getTabTitle(), basePanel); - tabbedPane.getTabs().add(newTab); - newTab.setOnCloseRequest(event -> { - closeTab((BasePanel) newTab.getContent()); - event.consume(); - }); + // add tab + Tab newTab = new Tab(basePanel.getTabTitle(), basePanel); + tabbedPane.getTabs().add(newTab); + newTab.setOnCloseRequest(event -> { + closeTab((BasePanel) newTab.getContent()); + event.consume(); + }); - // update all tab titles - updateAllTabTitles(); + // update all tab titles + updateAllTabTitles(); - if (raisePanel) { - tabbedPane.getSelectionModel().select(newTab); - } + if (raisePanel) { + tabbedPane.getSelectionModel().select(newTab); + } - // Register undo/redo listener - basePanel.getUndoManager().registerListener(new UndoRedoEventManager()); + // Register undo/redo listener + basePanel.getUndoManager().registerListener(new UndoRedoEventManager()); - BibDatabaseContext context = basePanel.getBibDatabaseContext(); + BibDatabaseContext context = basePanel.getBibDatabaseContext(); - if (readyForAutosave(context)) { - AutosaveManager autosaver = AutosaveManager.start(context); - autosaver.registerListener(new AutosaveUIManager(basePanel)); - } + if (readyForAutosave(context)) { + AutosaveManager autosaver = AutosaveManager.start(context); + autosaver.registerListener(new AutosaveUIManager(basePanel)); + } - BackupManager.start(context, Globals.entryTypesManager, prefs); + BackupManager.start(context, Globals.entryTypesManager, prefs); - // Track opening - trackOpenNewDatabase(basePanel); - }); + // Track opening + trackOpenNewDatabase(basePanel); } private void trackOpenNewDatabase(BasePanel basePanel) {