Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields
ObservableList<BibEntry> selectedEntries = stateManager.getSelectedEntries();
Binding<Boolean> fieldsAreSet = EasyBind.valueAt(selectedEntries, 0)
.mapObservable(entry -> Bindings.createBooleanBinding(
() -> entry.getFields().stream().anyMatch(fields::contains),
entry.getFieldsObservable()))
() -> entry.getFields().stream().anyMatch(fields::contains),
entry.getFieldsObservable()))
.orElseOpt(false);
return BooleanExpression.booleanExpression(fieldsAreSet);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public static BooleanExpression isFilePresentForSelectedEntry(StateManager state
/**
* 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
* Used in {@link org.jabref.gui.maintable.OpenSelectedEntriesFilesAction} when multiple entries selected
*
* @param stateManager manager for the state of the GUI
* @return a boolean binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.jabref.gui.documentviewer.DocumentViewerView;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.entryeditor.EntryEditorTab;
import org.jabref.gui.maintable.OpenExternalFileAction;
import org.jabref.gui.maintable.OpenFolderAction;
import org.jabref.gui.maintable.OpenSingleExternalFileAction;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.search.SearchType;
import org.jabref.gui.util.TooltipTextUtil;
Expand Down Expand Up @@ -180,8 +180,9 @@ private ContextMenu getFileContextMenu(LinkedFile file) {
ContextMenu fileContextMenu = new ContextMenu();
fileContextMenu.getItems().add(actionFactory.createMenuItem(
StandardActions.OPEN_FOLDER, new OpenFolderAction(dialogService, stateManager, preferences, entry, file, taskExecutor)));
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();
fileContextMenu.getItems().add(actionFactory.createMenuItem(
StandardActions.OPEN_EXTERNAL_FILE, new OpenExternalFileAction(dialogService, stateManager, preferences, entry, file, taskExecutor)));
StandardActions.OPEN_EXTERNAL_FILE, new OpenSingleExternalFileAction(dialogService, preferences, entry, file, taskExecutor, databaseContext)));
return fileContextMenu;
}

Expand Down
6 changes: 2 additions & 4 deletions jabgui/src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

@AllowedToUseClassGetResource("JavaFX internally handles the passed URLs properly.")
public class MainTable extends TableView<BibEntryTableViewModel> {

private static final Logger LOGGER = LoggerFactory.getLogger(MainTable.class);
private static final PseudoClass MATCHING_SEARCH_AND_GROUPS = PseudoClass.getPseudoClass("matching-search-and-groups");
private static final PseudoClass MATCHING_SEARCH_NOT_GROUPS = PseudoClass.getPseudoClass("matching-search-not-groups");
Expand Down Expand Up @@ -112,7 +111,6 @@ public MainTable(MainTableDataModel model,
TaskExecutor taskExecutor,
ImportHandler importHandler) {
super();

this.libraryTab = libraryTab;
this.stateManager = stateManager;
this.database = Objects.requireNonNull(database);
Expand Down Expand Up @@ -369,7 +367,7 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) {
EditAction cutAction = new EditAction(StandardActions.CUT, () -> libraryTab, stateManager, undoManager);
EditAction deleteAction = new EditAction(StandardActions.DELETE_ENTRY, () -> libraryTab, stateManager, undoManager);
OpenUrlAction openUrlAction = new OpenUrlAction(dialogService, stateManager, preferences);
OpenExternalFileAction openExternalFileActionFileAction = new OpenExternalFileAction(dialogService, stateManager, preferences, taskExecutor);
OpenSelectedEntriesFilesAction openSelectedEntriesFilesActionFileAction = new OpenSelectedEntriesFilesAction(dialogService, stateManager, preferences, taskExecutor);
MergeWithFetchedEntryAction mergeWithFetchedEntryAction = new MergeWithFetchedEntryAction(dialogService, stateManager, taskExecutor, preferences, undoManager);
LookupIdentifierAction<DOI> lookupIdentifierAction = new LookupIdentifierAction<>(WebFetchers.getIdFetcherForIdentifier(DOI.class), stateManager, undoManager, dialogService, taskExecutor);

Expand Down Expand Up @@ -422,7 +420,7 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) {
event.consume();
break;
case OPEN_FILE:
openExternalFileActionFileAction.execute();
openSelectedEntriesFilesActionFileAction.execute();
event.consume();
break;
case MERGE_WITH_FETCHED_ENTRY:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.jabref.gui.maintable;

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

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;

public class OpenSelectedEntriesFilesAction extends SimpleCommand {

private static final int FILES_LIMIT = 10;

private final DialogService dialogService;
private final StateManager stateManager;
private final GuiPreferences preferences;
private final TaskExecutor taskExecutor;

public OpenSelectedEntriesFilesAction(DialogService dialogService,
StateManager stateManager,
GuiPreferences preferences,
TaskExecutor taskExecutor) {
this.dialogService = dialogService;
this.stateManager = stateManager;
this.preferences = preferences;
this.taskExecutor = taskExecutor;

this.executable.bind(ActionHelper.hasLinkedFileForSelectedEntries(stateManager)
.and(ActionHelper.needsEntriesSelected(stateManager)));
}

@Override
public void execute() {
stateManager.getActiveDatabase().ifPresent(databaseContext -> {
final List<BibEntry> selectedEntries = stateManager.getSelectedEntries();

if (selectedEntries.size() == 1) {
BibEntry entry = selectedEntries.getFirst();
List<LinkedFile> files = entry.getFiles();

if (files.size() == 1) {
new OpenSingleExternalFileAction(
dialogService,
preferences,
entry,
files.getFirst(),
taskExecutor,
databaseContext
).execute();
return;
}
}
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 for this IMHO. If you have a special reason, add Java comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this check because single-entry single-file cases were not opening correctly via right-click in the main table. This fallback ensures the expected behaviour. I’ve now also added a Java comment explaining this. If there's something i am missing, I would appreciate the clarification.

Copy link
Member

Choose a reason for hiding this comment

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

What about two entries having a file attached each? What about an entry having two files attached? Does that work?

(I don't know what "not correctly" means on your text. Nothing percieved while trying out, wrong file opened, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think it works correctly for two entries having a file attached each and also for an entry having two files attached, both of these open with OpenSelectedEntriesFileAction.java.
When I said single-entry single-file cases were not opening correctly, I meant that we have created two files, one for single entry and other for multiple entries but when i apply the condition to check for that it always was using execute function of OpenSelectedEntriesFileAction.java and shows error when i apply the check in RightClickMenu file. I hope it clarifies my logic. If i am missing something, I would appreciate the guidance.

Copy link
Member

Choose a reason for hiding this comment

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

shows error

Please outline what is shown.

It is very strange that it works for >= 2 files, but not for one.


List<LinkedFileViewModel> linkedFileViewModelList = new LinkedList<>();

for (BibEntry entry : selectedEntries) {
for (LinkedFile linkedFile : entry.getFiles()) {
LinkedFileViewModel viewModel = new LinkedFileViewModel(
linkedFile,
entry,
databaseContext,
taskExecutor,
dialogService,
preferences);

linkedFileViewModelList.add(viewModel);
}
}

if (linkedFileViewModelList.size() > FILES_LIMIT) {
boolean continueOpening = dialogService.showConfirmationDialogAndWait(
Localization.lang("Opening large number of files"),
Localization.lang("You are about to open %0 files. Continue?", linkedFileViewModelList.size()),
Localization.lang("Open all files"),
Localization.lang("Don't open")
);
if (!continueOpening) {
return;
}
}

linkedFileViewModelList.forEach(LinkedFileViewModel::open);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jabref.gui.maintable;

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;

public class OpenSingleExternalFileAction extends SimpleCommand {

private final DialogService dialogService;
private final GuiPreferences preferences;
private final BibEntry entry;
private final LinkedFile linkedFile;
private final TaskExecutor taskExecutor;
private final BibDatabaseContext databaseContext;

public OpenSingleExternalFileAction(DialogService dialogService,
GuiPreferences preferences,
BibEntry entry,
LinkedFile linkedFile,
TaskExecutor taskExecutor,
BibDatabaseContext databaseContext) {
this.dialogService = dialogService;
this.preferences = preferences;
this.entry = entry;
this.linkedFile = linkedFile;
this.taskExecutor = taskExecutor;
this.databaseContext = databaseContext;

this.setExecutable(true);
}

@Override
public void execute() {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
linkedFile,
entry,
databaseContext,
taskExecutor,
dialogService,
preferences);
linkedFileViewModel.open();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static ContextMenu create(BibEntryTableViewModel entry,
factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferences.getFilePreferences(), preferences.getExternalApplicationsPreferences())),
factory.createMenuItem(StandardActions.ATTACH_FILE_FROM_URL, new AttachFileFromURLAction(dialogService, stateManager, taskExecutor, preferences)),
factory.createMenuItem(StandardActions.OPEN_FOLDER, new OpenFolderAction(dialogService, stateManager, preferences, taskExecutor)),
factory.createMenuItem(StandardActions.OPEN_EXTERNAL_FILE, new OpenExternalFileAction(dialogService, stateManager, preferences, taskExecutor)),
factory.createMenuItem(StandardActions.OPEN_EXTERNAL_FILE, new OpenSelectedEntriesFilesAction(dialogService, stateManager, preferences, taskExecutor)),
extractFileReferencesOnline,
extractFileReferencesOffline,

Expand Down