From 70a8ff3ab5edbb080d5a9d9152fe4d406a6df487 Mon Sep 17 00:00:00 2001 From: lzmmxh <149454746+lzmmxh@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:19:55 +1100 Subject: [PATCH] Fix disable some actions when no libraries are open (#11936) * fix bug * Update MainMenu.java * Update MainMenu.java * Update MainToolBar.java * Update MainToolBar.java * Update MainMenu.java * Update MainToolBar.java * Update CHANGELOG.md * Update CHANGELOG.md format issue * Update MainMenu.java * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: zimu li --- CHANGELOG.md | 1 + src/main/java/org/jabref/gui/frame/MainMenu.java | 11 +++++++++-- src/main/java/org/jabref/gui/frame/MainToolBar.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffecf1b4298..f23a80be7c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Fixed +- We fixed an issue where certain actions were not disabled when no libraries were open. [#11923](https://github.com/JabRef/jabref/issues/11923) - We fixed an issue where the "Check for updates" preference was not saved. [#11485](https://github.com/JabRef/jabref/pull/11485) - We fixed an issue where an exception was thrown after changing "show preview as a tab" in the preferences. [#11515](https://github.com/JabRef/jabref/pull/11515) - We fixed an issue where JabRef put file paths as absolute path when an entry was created using drag and drop of a PDF file. [#11173](https://github.com/JabRef/jabref/issues/11173) diff --git a/src/main/java/org/jabref/gui/frame/MainMenu.java b/src/main/java/org/jabref/gui/frame/MainMenu.java index 93c52e22bac..1d0ff64a924 100644 --- a/src/main/java/org/jabref/gui/frame/MainMenu.java +++ b/src/main/java/org/jabref/gui/frame/MainMenu.java @@ -2,6 +2,7 @@ import java.util.function.Supplier; +import javafx.beans.binding.Bindings; import javafx.event.ActionEvent; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; @@ -146,13 +147,19 @@ private void createMenu() { Menu tools = new Menu(Localization.lang("Tools")); Menu help = new Menu(Localization.lang("Help")); + MenuItem saveAllMenuItem = factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame::getLibraryTabs, preferences, dialogService)); + saveAllMenuItem.disableProperty().bind(Bindings.isEmpty(stateManager.getOpenDatabases())); + + MenuItem newEntryFromPlainTextMenuItem = factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService)); + newEntryFromPlainTextMenuItem.disableProperty().bind(Bindings.isEmpty(stateManager.getOpenDatabases())); + file.getItems().addAll( factory.createMenuItem(StandardActions.NEW_LIBRARY, new NewDatabaseAction(frame, preferences)), factory.createMenuItem(StandardActions.OPEN_LIBRARY, openDatabaseActionSupplier.get()), fileHistoryMenu, factory.createMenuItem(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, frame::getCurrentLibraryTab, dialogService, preferences, stateManager)), factory.createMenuItem(StandardActions.SAVE_LIBRARY_AS, new SaveAction(SaveAction.SaveMethod.SAVE_AS, frame::getCurrentLibraryTab, dialogService, preferences, stateManager)), - factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame::getLibraryTabs, preferences, dialogService)), + saveAllMenuItem, factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new JabRefFrame.CloseDatabaseAction(frame, stateManager)), new SeparatorMenuItem(), @@ -233,7 +240,7 @@ private void createMenu() { library.getItems().addAll( factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(frame::getCurrentLibraryTab, dialogService, preferences, stateManager)), - factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService)), + newEntryFromPlainTextMenuItem, factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame::getCurrentLibraryTab, stateManager, undoManager)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/frame/MainToolBar.java b/src/main/java/org/jabref/gui/frame/MainToolBar.java index f7c5fa999aa..6be6d770e79 100644 --- a/src/main/java/org/jabref/gui/frame/MainToolBar.java +++ b/src/main/java/org/jabref/gui/frame/MainToolBar.java @@ -1,5 +1,6 @@ package org.jabref.gui.frame; +import javafx.beans.binding.Bindings; import javafx.concurrent.Task; import javafx.geometry.Orientation; import javafx.scene.Group; @@ -105,6 +106,10 @@ private void createToolBar() { final Button pushToApplicationButton = factory.createIconButton(pushToApplicationCommand.getAction(), pushToApplicationCommand); pushToApplicationCommand.registerReconfigurable(pushToApplicationButton); + Button newEntryFromPlainTextButton = factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService)); + + newEntryFromPlainTextButton.disableProperty().bind(Bindings.isEmpty(stateManager.getOpenDatabases())); + // Setup Toolbar getItems().addAll( @@ -118,12 +123,12 @@ private void createToolBar() { globalSearchBar, rightSpacer, - + new HBox( factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(frame::getCurrentLibraryTab, StandardEntryType.Article, dialogService, preferences, stateManager)), factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(frame::getCurrentLibraryTab, dialogService, preferences, stateManager)), createNewEntryFromIdButton(), - factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService)), + newEntryFromPlainTextButton, factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame::getCurrentLibraryTab, stateManager, undoManager))), new Separator(Orientation.VERTICAL), @@ -152,6 +157,8 @@ private void createToolBar() { new HBox( factory.createIconButton(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService, preferences.getExternalApplicationsPreferences())))); + globalSearchBar.disableProperty().bind(Bindings.isEmpty(stateManager.getOpenDatabases())); + leftSpacer.setPrefWidth(50); leftSpacer.setMinWidth(Region.USE_PREF_SIZE); leftSpacer.setMaxWidth(Region.USE_PREF_SIZE);