diff --git a/CHANGELOG.md b/CHANGELOG.md index cff7a7ef220..ac0adcfdd41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where typing an invalid UNC path into the "Main file directory" text field caused an error. [#8107](https://github.com/JabRef/jabref/issues/8107) - We fixed an issue where "Open Folder" didn't select the file on macOS in Finder [#8130](https://github.com/JabRef/jabref/issues/8130) - We fixed an issue where importing PDFs resulted in an uncaught exception [#8143](https://github.com/JabRef/jabref/issues/8143) +- We fixed an issue where right-clicking on a tab and selecting close will close the focused tab even if it is not the tab we right-clicked [#8193](https://github.com/JabRef/jabref/pull/8193) ### Removed diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 0d44b51ad38..ec94b8e45c2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1038,16 +1038,16 @@ public void setupAllTables() { }); } - private ContextMenu createTabContextMenu(KeyBindingRepository keyBindingRepository) { + private ContextMenu createTabContextMenuFor(LibraryTab tab, KeyBindingRepository keyBindingRepository) { ContextMenu contextMenu = new ContextMenu(); ActionFactory factory = new ActionFactory(keyBindingRepository); contextMenu.getItems().addAll( - factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder()), - factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(stateManager, prefs)), + factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder(tab.getBibDatabaseContext())), + factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab.getBibDatabaseContext(), stateManager, prefs)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction()), - factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction()), + factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction(tab)), + factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction(tab)), factory.createMenuItem(StandardActions.CLOSE_ALL_LIBRARIES, new CloseAllDatabaseAction()) ); @@ -1063,7 +1063,7 @@ public void addTab(LibraryTab libraryTab, boolean raisePanel) { event.consume(); }); - libraryTab.setContextMenu(createTabContextMenu(Globals.getKeyPrefs())); + libraryTab.setContextMenu(createTabContextMenuFor(libraryTab, Globals.getKeyPrefs())); if (raisePanel) { tabbedPane.getSelectionModel().select(libraryTab); @@ -1233,25 +1233,39 @@ public void execute() { } private class CloseDatabaseAction extends SimpleCommand { + private final LibraryTab libraryTab; + + public CloseDatabaseAction(LibraryTab libraryTab) { + this.libraryTab = libraryTab; + } + + /** + * Using this constructor will result in executing the command on the currently open library tab + * */ + public CloseDatabaseAction() { + this(null); + } @Override public void execute() { - closeTab(getCurrentLibraryTab()); + closeTab(Optional.ofNullable(libraryTab).orElse(getCurrentLibraryTab())); } } private class CloseOthersDatabaseAction extends SimpleCommand { + private final LibraryTab libraryTab; - public CloseOthersDatabaseAction() { + public CloseOthersDatabaseAction(LibraryTab libraryTab) { + this.libraryTab = libraryTab; this.executable.bind(ActionHelper.isOpenMultiDatabase(tabbedPane)); } @Override public void execute() { - LibraryTab currentLibraryTab = getCurrentLibraryTab(); + LibraryTab toKeepLibraryTab = Optional.of(libraryTab).get(); for (Tab tab : tabbedPane.getTabs()) { LibraryTab libraryTab = (LibraryTab) tab; - if (libraryTab != currentLibraryTab) { + if (libraryTab != toKeepLibraryTab) { closeTab(libraryTab); } } @@ -1269,10 +1283,15 @@ public void execute() { } private class OpenDatabaseFolder extends SimpleCommand { + private final BibDatabaseContext databaseContext; + + public OpenDatabaseFolder(BibDatabaseContext databaseContext) { + this.databaseContext = databaseContext; + } @Override public void execute() { - stateManager.getActiveDatabase().flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { + Optional.of(databaseContext).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { try { JabRefDesktop.openFolderAndSelectFile(path, prefs); } catch (IOException e) { diff --git a/src/main/java/org/jabref/gui/OpenConsoleAction.java b/src/main/java/org/jabref/gui/OpenConsoleAction.java index c95ff39d65b..bbd2de42509 100644 --- a/src/main/java/org/jabref/gui/OpenConsoleAction.java +++ b/src/main/java/org/jabref/gui/OpenConsoleAction.java @@ -1,6 +1,7 @@ package org.jabref.gui; import java.io.IOException; +import java.util.Optional; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -14,19 +15,28 @@ public class OpenConsoleAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(OpenConsoleAction.class); + private final BibDatabaseContext databaseContext; private final StateManager stateManager; private final PreferencesService preferencesService; - public OpenConsoleAction(StateManager stateManager, PreferencesService preferencesService) { + public OpenConsoleAction(BibDatabaseContext databaseContext, StateManager stateManager, PreferencesService preferencesService) { + this.databaseContext = databaseContext; this.stateManager = stateManager; this.preferencesService = preferencesService; this.executable.bind(ActionHelper.needsDatabase(stateManager)); } + /** + * Using this constructor will result in executing the command on the active database + */ + public OpenConsoleAction(StateManager stateManager, PreferencesService preferencesService) { + this(null, stateManager, preferencesService); + } + @Override public void execute() { - stateManager.getActiveDatabase().flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { + Optional.ofNullable(databaseContext).or(stateManager::getActiveDatabase).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { try { JabRefDesktop.openConsole(path.toFile(), preferencesService); } catch (IOException e) { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java index fb17d02c6e8..c1543e6d2d6 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java @@ -11,6 +11,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; @@ -26,6 +27,7 @@ * Tests the CompositeIdFetcher, for which Fetchers implementing the * IdBasedFetcher interface are a prerequisite. Excluding TitleFetcher. */ +@FetcherTest class CompositeIdFetcherTest { private CompositeIdFetcher compositeIdFetcher;