Skip to content

Commit

Permalink
Changes to FileColumn allowing mouse click access to multiple files(.…
Browse files Browse the repository at this point in the history
…md, .png, etc.) (#12085)

* Made changes to FileColumn allowing for specific files to be accesed by mouse click.

* Made minor changes to 'case EXTRAFILE' for readability.

* ran rewriteRun

* remove checkstyle and sort case

---------

Co-authored-by: Siedlerchr <[email protected]>
  • Loading branch information
gabenogu and Siedlerchr authored Nov 1, 2024
1 parent 9bde037 commit f0e8d74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public MainTableColumnFactory(BibDatabaseContext database,
}
}
break;
default:
case NORMALFIELD:
if (!column.getQualifier().isBlank()) {
returnColumn = createFieldColumn(column, tooltip);
}
break;
default:
}
return returnColumn;
}
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/org/jabref/gui/maintable/columns/FileColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,35 @@ public FileColumn(MainTableColumnModel model,
.getGraphicNode());

new ValueTableCellFactory<BibEntryTableViewModel, List<LinkedFile>>()
.withGraphic((entry, linkedFiles) -> createFileIcon(entry, linkedFiles.stream().filter(linkedFile ->
linkedFile.getFileType().equalsIgnoreCase(fileType)).collect(Collectors.toList())))
.withGraphic((entry, linkedFiles) -> createFileIcon(entry, linkedFiles.stream()
.filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(fileType))
.collect(Collectors.toList())))
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
List<LinkedFile> filteredFiles = linkedFiles.stream()
.filter(linkedFile -> linkedFile.getFileType().equalsIgnoreCase(fileType))
.collect(Collectors.toList());

if (event.getButton() == MouseButton.PRIMARY) {
if (filteredFiles.size() == 1) {
// Only one file - open directly
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(filteredFiles.getFirst(),
entry.getEntry(), database, taskExecutor, dialogService, preferences);
linkedFileViewModel.open();
} else if (filteredFiles.size() > 1) {
// Multiple files - show context menu to choose file
ContextMenu contextMenu = new ContextMenu();
for (LinkedFile linkedFile : filteredFiles) {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile,
entry.getEntry(), database, taskExecutor, dialogService, preferences);
MenuItem menuItem = new MenuItem(linkedFileViewModel.getTruncatedDescriptionAndLink(),
linkedFileViewModel.getTypeIcon().getGraphicNode());
menuItem.setOnAction(e -> linkedFileViewModel.open());
contextMenu.getItems().add(menuItem);
}
contextMenu.show(((Node) event.getSource()), event.getScreenX(), event.getScreenY());
}
}
})
.install(this);
}

Expand Down

0 comments on commit f0e8d74

Please sign in to comment.