Skip to content

Commit

Permalink
Disable actions when no libraries are open (#11941)
Browse files Browse the repository at this point in the history
* Revert "Fix disable some actions when no libraries are open (#11936)"

This reverts commit 70a8ff3.

* Disable actions when no libraries are open
  • Loading branch information
LoayGhreeb authored Oct 13, 2024
1 parent 8404312 commit 340fa16
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/exporter/SaveAllAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

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;
import org.jabref.model.entry.BibEntryTypesManager;

import com.airhacks.afterburner.injection.Injector;

import static org.jabref.gui.actions.ActionHelper.needsDatabase;

public class SaveAllAction extends SimpleCommand {

private final Supplier<List<LibraryTab>> tabsSupplier;
private final DialogService dialogService;
private final GuiPreferences preferences;

public SaveAllAction(Supplier<List<LibraryTab>> tabsSupplier, GuiPreferences preferences, DialogService dialogService) {
public SaveAllAction(Supplier<List<LibraryTab>> tabsSupplier, GuiPreferences preferences, DialogService dialogService, StateManager stateManager) {
this.tabsSupplier = tabsSupplier;
this.dialogService = dialogService;
this.preferences = preferences;
this.executable.bind(needsDatabase(stateManager));
}

@Override
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/org/jabref/gui/frame/MainToolBar.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 340fa16

Please sign in to comment.