Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix action helper #6122

Merged
merged 7 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939)
- We fixed an issue with inconsistent capitalization of file extensions when downloading files [#6115](https://github.com/JabRef/jabref/issues/6115)
- We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130)
- We fixed an error that sometimes occurred when using the context menu. [#6085](https://github.com/JabRef/jabref/issues/6085)
- We fixed an issue where search full-text documents downloaded files with same name, overwriting existing files. [#6174](https://github.com/JabRef/jabref/pull/6174)

### Removed
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

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

import org.jabref.gui.StateManager;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;

public class ActionHelper {
public static BooleanExpression needsDatabase(StateManager stateManager) {
return stateManager.activeDatabaseProperty().isPresent();
Expand All @@ -30,10 +34,12 @@ public static BooleanExpression isFieldSetForSelectedEntry(Field field, StateMan
}

public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields, StateManager stateManager) {
BibEntry entry = stateManager.getSelectedEntries().get(0);
return Bindings.createBooleanBinding(
() -> entry.getFields().stream().anyMatch(fields::contains),
entry.getFieldsObservable(),
stateManager.getSelectedEntries());
ObservableList<BibEntry> selectedEntries = stateManager.getSelectedEntries();
MonadicBinding<Boolean> fieldsAreSet = EasyBind.monadic(Bindings.valueAt(selectedEntries, 0))
.flatMap(entry -> Bindings.createBooleanBinding(() -> {
return entry.getFields().stream().anyMatch(fields::contains);
}, entry.getFieldsObservable()))
.orElse(false);
return BooleanExpression.booleanExpression(fieldsAreSet);
}
}
29 changes: 17 additions & 12 deletions src/main/java/org/jabref/gui/maintable/OpenFolderAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ public OpenFolderAction(DialogService dialogService, StateManager stateManager,
@Override
public void execute() {
stateManager.getActiveDatabase().ifPresent(databaseContext ->
stateManager.getSelectedEntries().forEach(entry -> {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
entry.getFiles().get(0),
entry,
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getFilePreferences(),
ExternalFileTypes.getInstance());
linkedFileViewModel.openFolder();
}));
stateManager.getSelectedEntries().forEach(entry -> {
if (entry.getFiles().isEmpty()) {
return;
}

LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
entry.getFiles().get(0),
entry,
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getFilePreferences(),
ExternalFileTypes.getInstance()
);
linkedFileViewModel.openFolder();
}));
}
}