diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7acef11b5..81f826a4b72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We excluded specific fields (e.g., `comment`, `pdf`, `sortkey`) from the consistency check to reduce false positives [#13131](https://github.com/JabRef/jabref/issues/13131) - We fixed an issue where moved or renamed linked files in the file directory were not automatically relinked by the “search for unlinked files” feature. [#13264](https://github.com/JabRef/jabref/issues/13264) - We fixed an issue with proxy setup in the absence of a password. [#12412](https://github.com/JabRef/jabref/issues/12412) +- We fixed an issue with the targets of the menu item "copy to". [#13741](https://github.com/JabRef/jabref/pull/13741) - We fixed an issue where the tab showing the fulltext search results was not displayed. [#12865](https://github.com/JabRef/jabref/issues/12865) - We fixed an issue showing an empty tooltip in maintable. [#11681](https://github.com/JabRef/jabref/issues/11681) - We fixed an issue displaying a warning if a file to open is not found. [#13430](https://github.com/JabRef/jabref/pull/13430) diff --git a/jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java b/jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java index 68a336b8bc4..a6909349f02 100644 --- a/jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java +++ b/jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java @@ -8,7 +8,6 @@ import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanExpression; import javafx.collections.ObservableList; -import javafx.scene.control.TabPane; import org.jabref.gui.StateManager; import org.jabref.logic.preferences.CliPreferences; @@ -38,8 +37,8 @@ public static BooleanExpression needsSharedDatabase(StateManager stateManager) { return BooleanExpression.booleanExpression(binding); } - public static BooleanExpression needsMultipleDatabases(TabPane tabbedPane) { - return Bindings.size(tabbedPane.getTabs()).greaterThan(1); + public static BooleanExpression needsMultipleDatabases(StateManager stateManager) { + return Bindings.size(stateManager.getOpenDatabases()).greaterThan(1); } public static BooleanExpression needsStudyDatabase(StateManager stateManager) { diff --git a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java index dfae60afdaf..34cac1a1f00 100644 --- a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java +++ b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java @@ -711,7 +711,7 @@ private class CloseOthersDatabaseAction extends SimpleCommand { public CloseOthersDatabaseAction(LibraryTab libraryTab) { this.libraryTab = libraryTab; - this.executable.bind(ActionHelper.needsMultipleDatabases(tabbedPane)); + this.executable.bind(ActionHelper.needsMultipleDatabases(stateManager)); } @Override diff --git a/jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java b/jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java index f95dc15be2d..0f59d35000d 100644 --- a/jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -98,6 +98,7 @@ public class MainTable extends TableView { private String columnSearchTerm; private boolean citationMergeMode = false; + /// There is one maintable instance per library tab public MainTable(MainTableDataModel model, LibraryTab libraryTab, LibraryTabContainer tabContainer, diff --git a/jabgui/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/jabgui/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index ec9c2ba5adb..a7a913bf6e3 100644 --- a/jabgui/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/jabgui/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -1,11 +1,7 @@ package org.jabref.gui.maintable; -import java.util.Optional; - import javax.swing.undo.UndoManager; -import javafx.beans.binding.Bindings; -import javafx.collections.ObservableList; import javafx.scene.control.ContextMenu; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; @@ -16,6 +12,7 @@ import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.edit.CopyMoreAction; import org.jabref.gui.edit.CopyTo; @@ -127,45 +124,38 @@ private static Menu createCopyToMenu(ActionFactory factory, ImportHandler importHandler) { Menu copyToMenu = factory.createMenu(StandardActions.COPY_TO); copyToMenu.disableProperty().bind( - Bindings.size(stateManager.getOpenDatabases()).lessThan(2) + ActionHelper.needsMultipleDatabases(stateManager).not() ); - ObservableList openDatabases = stateManager.getOpenDatabases(); + // Menu is created on each right-click, thus we can always assume that the list of open databases is up-to-date BibDatabaseContext sourceDatabaseContext = libraryTab.getBibDatabaseContext(); - Optional sourceDatabaseName = libraryTab - .getBibDatabaseContext().getDatabasePath().stream() - .flatMap(path -> FileUtil.getUniquePathFragment(stateManager.getAllDatabasePaths(), path).stream()) - .findFirst(); - - if (!openDatabases.isEmpty()) { - openDatabases.forEach(bibDatabaseContext -> { - Optional destinationPath = Optional.empty(); - String destinationDatabaseName = ""; - - if (bibDatabaseContext.getDatabasePath().isPresent()) { - Optional uniqueFilePathFragment = FileUtil.getUniquePathFragment(stateManager.getAllDatabasePaths(), 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 { - destinationDatabaseName = destinationPath.orElse(Localization.lang("untitled")); - } - - copyToMenu.getItems().addAll( - factory.createCustomMenuItem( - StandardActions.COPY_TO, - new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), importHandler, sourceDatabaseContext, bibDatabaseContext), - destinationDatabaseName - ) - ); - }); + for (BibDatabaseContext targetDatabaseContext : stateManager.getOpenDatabases()) { + if (targetDatabaseContext == sourceDatabaseContext) { + continue; + } + String targetDatabaseName; + + if (targetDatabaseContext.getDatabasePath().isPresent()) { + targetDatabaseName = FileUtil.getUniquePathFragment( + stateManager.getAllDatabasePaths(), + targetDatabaseContext.getDatabasePath().get() + ).orElse(Localization.lang("untitled")); + } else if (targetDatabaseContext.getLocation() == DatabaseLocation.SHARED) { + targetDatabaseName = targetDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]"; + } else { + targetDatabaseName = Localization.lang("untitled"); + } + + copyToMenu.getItems().add( + factory.createCustomMenuItem( + StandardActions.COPY_TO, + new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), + importHandler, sourceDatabaseContext, targetDatabaseContext), + targetDatabaseName + ) + ); } return copyToMenu;