Skip to content
Merged
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
17 changes: 10 additions & 7 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.maintable;

import java.nio.file.Path;
import java.util.Optional;

import javax.swing.undo.UndoManager;
Expand Down Expand Up @@ -120,27 +119,31 @@ private static Menu createCopyToMenu(ActionFactory factory,
StateManager stateManager,
GuiPreferences preferences,
LibraryTab libraryTab,
ImportHandler importHandler
) {
ImportHandler importHandler) {
Menu copyToMenu = factory.createMenu(StandardActions.COPY_TO);

ObservableList<BibDatabaseContext> openDatabases = stateManager.getOpenDatabases();

BibDatabaseContext sourceDatabaseContext = libraryTab.getBibDatabaseContext();

Optional<Path> sourcePath = libraryTab.getBibDatabaseContext().getDatabasePath();
String sourceDatabaseName = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), sourcePath.get()).get();
Optional<String> sourceDatabaseName = libraryTab
.getBibDatabaseContext().getDatabasePath().stream()
.flatMap(path -> FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), path).stream())
.findFirst();

if (!openDatabases.isEmpty()) {
openDatabases.forEach(bibDatabaseContext -> {
Optional<String> destinationPath = Optional.empty();
String destinationDatabaseName = "";

if (bibDatabaseContext.getDatabasePath().isPresent()) {
destinationDatabaseName = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), bibDatabaseContext.getDatabasePath().get()).get();
if (destinationDatabaseName.equals(sourceDatabaseName)) {
Optional<String> uniqueFilePathFragment = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), bibDatabaseContext.getDatabasePath().get());
if (uniqueFilePathFragment.equals(sourceDatabaseName)) {
return;
}
if (uniqueFilePathFragment.isPresent()) {
destinationDatabaseName = uniqueFilePathFragment.get();
}
} else if (bibDatabaseContext.getLocation() == DatabaseLocation.SHARED) {
destinationDatabaseName = bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
} else {
Expand Down