|
1 | 1 | package org.jabref.gui.maintable; |
2 | 2 |
|
3 | | -import java.nio.file.Path; |
4 | 3 | import java.util.Optional; |
5 | 4 |
|
6 | 5 | import javax.swing.undo.UndoManager; |
@@ -120,27 +119,31 @@ private static Menu createCopyToMenu(ActionFactory factory, |
120 | 119 | StateManager stateManager, |
121 | 120 | GuiPreferences preferences, |
122 | 121 | LibraryTab libraryTab, |
123 | | - ImportHandler importHandler |
124 | | - ) { |
| 122 | + ImportHandler importHandler) { |
125 | 123 | Menu copyToMenu = factory.createMenu(StandardActions.COPY_TO); |
126 | 124 |
|
127 | 125 | ObservableList<BibDatabaseContext> openDatabases = stateManager.getOpenDatabases(); |
128 | 126 |
|
129 | 127 | BibDatabaseContext sourceDatabaseContext = libraryTab.getBibDatabaseContext(); |
130 | 128 |
|
131 | | - Optional<Path> sourcePath = libraryTab.getBibDatabaseContext().getDatabasePath(); |
132 | | - String sourceDatabaseName = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), sourcePath.get()).get(); |
| 129 | + Optional<String> sourceDatabaseName = libraryTab |
| 130 | + .getBibDatabaseContext().getDatabasePath().stream() |
| 131 | + .flatMap(path -> FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), path).stream()) |
| 132 | + .findFirst(); |
133 | 133 |
|
134 | 134 | if (!openDatabases.isEmpty()) { |
135 | 135 | openDatabases.forEach(bibDatabaseContext -> { |
136 | 136 | Optional<String> destinationPath = Optional.empty(); |
137 | 137 | String destinationDatabaseName = ""; |
138 | 138 |
|
139 | 139 | if (bibDatabaseContext.getDatabasePath().isPresent()) { |
140 | | - destinationDatabaseName = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), bibDatabaseContext.getDatabasePath().get()).get(); |
141 | | - if (destinationDatabaseName.equals(sourceDatabaseName)) { |
| 140 | + Optional<String> uniqueFilePathFragment = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), bibDatabaseContext.getDatabasePath().get()); |
| 141 | + if (uniqueFilePathFragment.equals(sourceDatabaseName)) { |
142 | 142 | return; |
143 | 143 | } |
| 144 | + if (uniqueFilePathFragment.isPresent()) { |
| 145 | + destinationDatabaseName = uniqueFilePathFragment.get(); |
| 146 | + } |
144 | 147 | } else if (bibDatabaseContext.getLocation() == DatabaseLocation.SHARED) { |
145 | 148 | destinationDatabaseName = bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]"; |
146 | 149 | } else { |
|
0 commit comments