Skip to content

Commit

Permalink
Fix issue where "Close library" menu item is not disabled correctly (#…
Browse files Browse the repository at this point in the history
…10950)

* fix: check that the current tab is not null before closing it

* fix: add stateManager to the CloseDatabaseAction command to disable it when unusable (JabRef#10948)

* feat: update CHANGELOG.md

* fix: move check on null to CloseDatabaseAction#execute

* Removed superfluous new line

---------

Co-authored-by: Carl Christian Snethlage <[email protected]>
  • Loading branch information
martinctl and calixtus authored Mar 3, 2024
1 parent 50249c7 commit 3c632e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the CrossRef field did not work if autocompletion was disabled [#8145](https://github.com/JabRef/jabref/issues/8145)
- We fixed an issue where exporting`@electronic` and `@online` entry types to the Office XMl would duplicate the field `title` [#10807](https://github.com/JabRef/jabref/issues/10807)
- We fixed an issue where the `CommentsTab` was not properly formatted when the `defaultOwner` contained capital or special letters. [#10870](https://github.com/JabRef/jabref/issues/10870)
- We fixed an issue where the `File -> Close library` menu item was not disabled when no library was open. [#10948](https://github.com/JabRef/jabref/issues/10948)
- We fixed an issue where the Document Viewer would show the PDF in only half the window when maximized. [#10934](https://github.com/JabRef/jabref/issues/10934)

### Removed
Expand Down
13 changes: 9 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 @@ -1059,22 +1059,27 @@ 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
public void execute() {
Platform.runLater(() -> {
if (libraryTab == null) {
if (tabContainer.getCurrentLibraryTab() == null) {
LOGGER.error("No library tab to close");
return;
}
tabContainer.closeCurrentTab();
} else {
tabContainer.closeTab(libraryTab);
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 3c632e3

Please sign in to comment.