Skip to content

Commit

Permalink
Fix import into currently open library (#5717)
Browse files Browse the repository at this point in the history
Remove unnecessary parallel execution of `addTab`, which fixes #5537.
  • Loading branch information
tobiasdiez authored Dec 7, 2019
1 parent d0f6c2b commit 673e53b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
67 changes: 34 additions & 33 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,6 +97,13 @@ private void openDatabases() {
openLastEditedDatabases();
}

// Remove invalid databases
List<ParserResult> 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()
Expand All @@ -106,40 +113,34 @@ private void openDatabases() {

// Add all bibDatabases databases to the frame:
boolean first = false;
if (!bibDatabases.isEmpty()) {
for (Iterator<ParserResult> 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;
}
}

Expand Down
46 changes: 22 additions & 24 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 673e53b

Please sign in to comment.