Skip to content

Commit

Permalink
Fix action helper when no library is open
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed May 3, 2020
1 parent c937601 commit f49a839
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;

import org.jabref.gui.StateManager;
Expand Down Expand Up @@ -51,6 +52,10 @@ public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields

public static BooleanExpression isFilePresentForSelectedEntry(StateManager stateManager, PreferencesService preferencesService) {
return Bindings.createBooleanBinding(() -> {

if (stateManager.getSelectedEntries().isEmpty()) {
return false;
}
List<LinkedFile> files = stateManager.getSelectedEntries().get(0).getFiles();
if ((files.size() > 0) && stateManager.getActiveDatabase().isPresent()) {
Optional<Path> filename = FileHelper.find(
Expand All @@ -62,6 +67,6 @@ public static BooleanExpression isFilePresentForSelectedEntry(StateManager state
return false;
}
}, stateManager.getSelectedEntries(),
stateManager.getSelectedEntries().get(0).getFieldBinding(StandardField.FILE));
stateManager.getSelectedEntries().isEmpty() ? new SimpleStringProperty("") : stateManager.getSelectedEntries().get(0).getFieldBinding(StandardField.FILE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.preferences.PreferencesService;

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

public class ShowDocumentViewerAction extends SimpleCommand {

public ShowDocumentViewerAction(StateManager stateManager, PreferencesService preferences) {
this.executable.bind(ActionHelper.isFilePresentForSelectedEntry(stateManager, preferences));
this.executable.bind(needsEntriesSelected(stateManager).and(ActionHelper.isFilePresentForSelectedEntry(stateManager, preferences)));
}

@Override
Expand Down

0 comments on commit f49a839

Please sign in to comment.