Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import into currently open library #5717

Merged
merged 1 commit into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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