Skip to content

Commit

Permalink
fix: add stateManager to the CloseDatabaseAction command to disable i…
Browse files Browse the repository at this point in the history
…t when unusable (JabRef#10948)
  • Loading branch information
martinctl committed Feb 29, 2024
1 parent fc3f037 commit 53382de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down

0 comments on commit 53382de

Please sign in to comment.