diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index baca17aabdd..4c214bac0ba 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -638,7 +638,7 @@ private ContextMenu createTabContextMenuFor(LibraryTab tab, KeyBindingRepository factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder(tab::getBibDatabaseContext)), factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab::getBibDatabaseContext, stateManager, prefs, dialogService)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction(this, tab)), + factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction(this, tab, stateManager)), factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction(tab)), factory.createMenuItem(StandardActions.CLOSE_ALL_LIBRARIES, new CloseAllDatabaseAction())); @@ -1063,16 +1063,17 @@ static protected class CloseDatabaseAction extends SimpleCommand { private final LibraryTabContainer tabContainer; private final LibraryTab libraryTab; - public CloseDatabaseAction(LibraryTabContainer tabContainer, LibraryTab libraryTab) { + public CloseDatabaseAction(LibraryTabContainer tabContainer, LibraryTab libraryTab, StateManager stateManager) { this.tabContainer = tabContainer; this.libraryTab = libraryTab; + this.executable.bind(ActionHelper.needsDatabase(stateManager)); } /** * Using this constructor will result in executing the command on the currently open library tab */ - public CloseDatabaseAction(LibraryTabContainer tabContainer) { - this(tabContainer, null); + public CloseDatabaseAction(LibraryTabContainer tabContainer, StateManager stateManager) { + this(tabContainer, null, stateManager); } @Override diff --git a/src/main/java/org/jabref/gui/MainMenu.java b/src/main/java/org/jabref/gui/MainMenu.java index db5c69c7fd2..566290dd4e3 100644 --- a/src/main/java/org/jabref/gui/MainMenu.java +++ b/src/main/java/org/jabref/gui/MainMenu.java @@ -137,7 +137,7 @@ private void createMenu() { factory.createMenuItem(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), factory.createMenuItem(StandardActions.SAVE_LIBRARY_AS, new SaveAction(SaveAction.SaveMethod.SAVE_AS, frame::getCurrentLibraryTab, dialogService, preferencesService, stateManager)), factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame::getLibraryTabs, preferencesService, dialogService)), - factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new JabRefFrame.CloseDatabaseAction(frame)), + factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new JabRefFrame.CloseDatabaseAction(frame, stateManager)), new SeparatorMenuItem(),