From f0e8d74fd56857c18e51657e6e4c7f68618b3dd7 Mon Sep 17 00:00:00 2001 From: gabenogu Date: Fri, 1 Nov 2024 13:35:57 -0400 Subject: [PATCH] Changes to FileColumn allowing mouse click access to multiple files(.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 --- .../gui/maintable/MainTableColumnFactory.java | 2 +- .../gui/maintable/columns/FileColumn.java | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index d4d9b8fb576..94a3362ac29 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -120,12 +120,12 @@ public MainTableColumnFactory(BibDatabaseContext database, } } break; - default: case NORMALFIELD: if (!column.getQualifier().isBlank()) { returnColumn = createFieldColumn(column, tooltip); } break; + default: } return returnColumn; } diff --git a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java index ce1fc758ef3..974b5fd111e 100644 --- a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java +++ b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java @@ -98,8 +98,35 @@ public FileColumn(MainTableColumnModel model, .getGraphicNode()); new ValueTableCellFactory>() - .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 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); }