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 for issue 6966: open all files of multiple entries #7709

Merged
merged 20 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 @@ -22,6 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added a feature that allows the user to copy highlighted text in the preview window. [#6962](https://github.com/JabRef/jabref/issues/6962)
- We added a feature that allows you to create new BibEntry via paste arxivId [#2292](https://github.com/JabRef/jabref/issues/2292)
- We added a feature that allows the user to choose whether to trust the target site when unable to find a valid certification path from the file download site. [#7616](https://github.com/JabRef/jabref/issues/7616)
- We added a feature that allows the user to open all linked files of multiple selected entries by "Open file" option. [#6966](https://github.com/JabRef/jabref/issues/6966)
- We added a keybinding preset for new entries. [#7705](https://github.com/JabRef/jabref/issues/7705)

### Changed
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@ public static BooleanExpression isFilePresentForSelectedEntry(StateManager state
return BooleanExpression.booleanExpression(fileIsPresent);
}

/**
* Check if at least one of the selected entries has linked files
* <br>
* Used in {@link org.jabref.gui.maintable.OpenExternalFileAction} when multiple entries selected
* @param stateManager manager for the state of the GUI
* @param preferencesService services of preferences
* @return a boolean binding
*/
public static BooleanExpression hasPresentFileForSelectedEntries(StateManager stateManager, PreferencesService preferencesService) {
return Bindings.createBooleanBinding(() -> {
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
ObservableList<BibEntry> selectedEntries = stateManager.getSelectedEntries();
List<LinkedFile> files;
for (BibEntry entry:selectedEntries) {
files = entry.getFiles();

if ((entry.getFiles().size() > 0) && stateManager.getActiveDatabase().isPresent()) {
if (files.get(0).isOnlineLink()) {
Copy link
Member

@Siedlerchr Siedlerchr May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would exclude online file links. Otherwise you will suddenly have 300 Tabs open in your browser f you select 300 entries and they have at least one link

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference to selecting 300 entries that have pdf attached?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set a limit?
For example, if a user is trying to open 100 files, pop out a dialog to ask the user whether to continue or cancel.
But how to determine the limit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a good idea. "You are about to open more than 10 files". Continue?
I would simply create a constant with 10. I think that's appropriate.

  • Continue / Cancel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

return true;
}

Optional<Path> filename = FileHelper.find(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check the filename for presence here, just later on try to open the file. Either it works or not.

stateManager.getActiveDatabase().get(),
files.get(0).getLink(),
preferencesService.getFilePreferences());
if (filename.isPresent()) {
return true;
}
}
}
return false;
});
}

public static BooleanExpression isOpenMultiDatabase(TabPane tabbedPane) {
return Bindings.size(tabbedPane.getTabs()).greaterThan(1);
}
Expand Down
45 changes: 27 additions & 18 deletions src/main/java/org/jabref/gui/maintable/OpenExternalFileAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.maintable;

import java.util.LinkedList;
import java.util.List;

import org.jabref.gui.DialogService;
Expand All @@ -9,7 +10,6 @@
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

Expand All @@ -24,32 +24,41 @@ public OpenExternalFileAction(DialogService dialogService, StateManager stateMan
this.stateManager = stateManager;
this.preferencesService = preferencesService;

this.executable.bind(ActionHelper.isFilePresentForSelectedEntry(stateManager, preferencesService)
.and(ActionHelper.needsEntriesSelected(1, stateManager)));
this.executable.bind(ActionHelper.hasPresentFileForSelectedEntries(stateManager, preferencesService)
.and(ActionHelper.needsEntriesSelected(stateManager))
);
}

/**
* Open all linked files of the selected entries.
* <br>
* If some selected entries have linked file and others do not, ignore the latter.
*/
@Override
public void execute() {
stateManager.getActiveDatabase().ifPresent(databaseContext -> {
final List<BibEntry> selectedEntries = stateManager.getSelectedEntries();

if (selectedEntries.size() != 1) {
dialogService.notify(Localization.lang("This operation requires exactly one item to be selected."));
return;
List<LinkedFileViewModel> linkedFileViewModelList = new LinkedList<>();
LinkedFileViewModel linkedFileViewModel;

for (BibEntry entry:selectedEntries) {
if (!entry.getFiles().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An entry can have multiple files linked. I would suggest you open all

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

linkedFileViewModelList.add(linkedFileViewModel);
}
}

final BibEntry entry = selectedEntries.get(0);

LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
entry.getFiles().get(0),
entry,
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
ExternalFileTypes.getInstance());
linkedFileViewModel.open();
linkedFileViewModelList.forEach(LinkedFileViewModel::open);
});
}
}