From 340fa1695e992ad366d5788db1c698f64e3bb1c9 Mon Sep 17 00:00:00 2001 From: Loay Ghreeb Date: Sun, 13 Oct 2024 07:48:45 +0300 Subject: [PATCH] Disable actions when no libraries are open (#11941) * Revert "Fix disable some actions when no libraries are open (#11936)" This reverts commit 70a8ff3ab5edbb080d5a9d9152fe4d406a6df487. * Disable actions when no libraries are open --- .../java/org/jabref/gui/exporter/SaveAllAction.java | 6 +++++- src/main/java/org/jabref/gui/frame/MainMenu.java | 11 ++--------- src/main/java/org/jabref/gui/frame/MainToolBar.java | 11 ++--------- .../PlainCitationParserAction.java | 6 +++++- .../java/org/jabref/gui/search/GlobalSearchBar.java | 2 +- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index a31329039be..1de83c4a039 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -5,6 +5,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.LibraryTab; +import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.preferences.GuiPreferences; import org.jabref.logic.l10n.Localization; @@ -12,16 +13,19 @@ import com.airhacks.afterburner.injection.Injector; +import static org.jabref.gui.actions.ActionHelper.needsDatabase; + public class SaveAllAction extends SimpleCommand { private final Supplier> tabsSupplier; private final DialogService dialogService; private final GuiPreferences preferences; - public SaveAllAction(Supplier> tabsSupplier, GuiPreferences preferences, DialogService dialogService) { + public SaveAllAction(Supplier> tabsSupplier, GuiPreferences preferences, DialogService dialogService, StateManager stateManager) { this.tabsSupplier = tabsSupplier; this.dialogService = dialogService; this.preferences = preferences; + this.executable.bind(needsDatabase(stateManager)); } @Override diff --git a/src/main/java/org/jabref/gui/frame/MainMenu.java b/src/main/java/org/jabref/gui/frame/MainMenu.java index 1d0ff64a924..4a90a556172 100644 --- a/src/main/java/org/jabref/gui/frame/MainMenu.java +++ b/src/main/java/org/jabref/gui/frame/MainMenu.java @@ -2,7 +2,6 @@ import java.util.function.Supplier; -import javafx.beans.binding.Bindings; import javafx.event.ActionEvent; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; @@ -147,19 +146,13 @@ 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)), - saveAllMenuItem, + factory.createMenuItem(StandardActions.SAVE_ALL, new SaveAllAction(frame::getLibraryTabs, preferences, dialogService, stateManager)), factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new JabRefFrame.CloseDatabaseAction(frame, stateManager)), new SeparatorMenuItem(), @@ -240,7 +233,7 @@ private void createMenu() { library.getItems().addAll( factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(frame::getCurrentLibraryTab, dialogService, preferences, stateManager)), - newEntryFromPlainTextMenuItem, + factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService, stateManager)), 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 6be6d770e79..bcbe2b8ba69 100644 --- a/src/main/java/org/jabref/gui/frame/MainToolBar.java +++ b/src/main/java/org/jabref/gui/frame/MainToolBar.java @@ -1,6 +1,5 @@ package org.jabref.gui.frame; -import javafx.beans.binding.Bindings; import javafx.concurrent.Task; import javafx.geometry.Orientation; import javafx.scene.Group; @@ -106,10 +105,6 @@ 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( @@ -123,12 +118,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(), - newEntryFromPlainTextButton, + factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new PlainCitationParserAction(dialogService, stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, frame::getCurrentLibraryTab, stateManager, undoManager))), new Separator(Orientation.VERTICAL), @@ -157,8 +152,6 @@ 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); diff --git a/src/main/java/org/jabref/gui/plaincitationparser/PlainCitationParserAction.java b/src/main/java/org/jabref/gui/plaincitationparser/PlainCitationParserAction.java index 307ce5483d1..16f63a8f92e 100644 --- a/src/main/java/org/jabref/gui/plaincitationparser/PlainCitationParserAction.java +++ b/src/main/java/org/jabref/gui/plaincitationparser/PlainCitationParserAction.java @@ -1,13 +1,17 @@ package org.jabref.gui.plaincitationparser; import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import static org.jabref.gui.actions.ActionHelper.needsDatabase; + public class PlainCitationParserAction extends SimpleCommand { private final DialogService dialogService; - public PlainCitationParserAction(DialogService dialogService) { + public PlainCitationParserAction(DialogService dialogService, StateManager stateManager) { this.dialogService = dialogService; + this.executable.bind(needsDatabase(stateManager)); } @Override diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index cc87b5cfd17..a4cad4a6ccb 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -285,7 +285,7 @@ private void initSearchModifierButtons() { searchField.requestFocus(); }); - openGlobalSearchButton.disableProperty().bindBidirectional(globalSearchActive); + openGlobalSearchButton.disableProperty().bind(globalSearchActive.or(needsDatabase(stateManager).not())); openGlobalSearchButton.setTooltip(new Tooltip(Localization.lang("Search across libraries in a new window"))); initSearchModifierButton(openGlobalSearchButton); openGlobalSearchButton.setOnAction(evt -> openGlobalSearchDialog());