Skip to content

Commit

Permalink
Fix action helper (#6122)
Browse files Browse the repository at this point in the history
* fix: not every selected entry will have a file

Related #6085

* fix: this will probably fix missing selection information on Linux

I is hard to test this, as normally a selection should be given when the method is triggered.
Fixes #6085

* Update src/main/java/org/jabref/gui/actions/ActionHelper.java

Co-Authored-By: Tobias Diez <tobiasdiez@gmx.de>

* Update ActionHelper.java

* Fix binding

* Add changelog entry

Co-authored-by: Tobias Diez <tobiasdiez@gmx.de>
Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
  • Loading branch information
3 people committed May 3, 2020
1 parent 1d9957b commit b472942
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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)
- We fixed an issue when importing into current library an erroneous message "import cancelled" is displayed even though import is successful. [#6266](https://github.com/JabRef/jabref/issues/6266)
- We fixed an issue where custom jstyles for Open/LibreOffice where not saved correctly. [#6170](https://github.com/JabRef/jabref/issues/6170)
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 @@ -7,6 +7,7 @@

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;
Expand All @@ -16,6 +17,9 @@
import org.jabref.model.util.FileHelper;
import org.jabref.preferences.PreferencesService;

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 @@ -36,11 +40,13 @@ 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);
}

public static BooleanExpression isFilePresentForSelectedEntry(StateManager stateManager, PreferencesService preferencesService) {
Expand Down
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 @@ -26,17 +26,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();
}));
}
}

0 comments on commit b472942

Please sign in to comment.