From a58f59d1b20e91ab5c29093d951e8e89f7a3019f Mon Sep 17 00:00:00 2001 From: Runemoro Date: Sun, 21 Apr 2019 21:14:16 -0400 Subject: [PATCH] Allow adding multiple jars at once --- src/matcher/gui/Gui.java | 15 +++++++++++++++ src/matcher/gui/menu/NewProjectPane.java | 10 ++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/matcher/gui/Gui.java b/src/matcher/gui/Gui.java index 777bab12..605ae7d3 100644 --- a/src/matcher/gui/Gui.java +++ b/src/matcher/gui/Gui.java @@ -12,6 +12,7 @@ import java.util.concurrent.Executors; import java.util.function.Consumer; import java.util.function.DoubleConsumer; +import java.util.stream.Collectors; import javafx.application.Application; import javafx.application.Platform; @@ -306,6 +307,20 @@ public static Path requestFile(String title, Window parent, List requestFiles(String title, Window parent, List extensionFilters) { + FileChooser fileChooser = new FileChooser(); + + fileChooser.setTitle(title); + fileChooser.getExtensionFilters().addAll(extensionFilters); + if (lastChooserFile != null) fileChooser.setInitialDirectory(lastChooserFile); + + List files = fileChooser.showOpenMultipleDialog(parent); + + if (!files.isEmpty()) lastChooserFile = files.get(0).getParentFile(); + + return files.stream().map(File::toPath).collect(Collectors.toList()); + } + public static Path requestDir(String title, Window parent) { DirectoryChooser fileChooser = new DirectoryChooser(); diff --git a/src/matcher/gui/menu/NewProjectPane.java b/src/matcher/gui/menu/NewProjectPane.java index 2556f4b1..80f50049 100644 --- a/src/matcher/gui/menu/NewProjectPane.java +++ b/src/matcher/gui/menu/NewProjectPane.java @@ -176,10 +176,12 @@ private Node createFilesSelectionPane(String name, ObservableList entries, Button button = new Button("add"); footer.getChildren().add(button); - button.setOnAction(event -> { - Path path = Gui.requestFile("Select file to add", window, getInputLoadExtensionFilters(), true); - if (path != null && !list.getItems().contains(path)) list.getItems().add(path); - }); + button.setOnAction(event -> + Gui.requestFiles("Select files to add", window, getInputLoadExtensionFilters()) + .stream() + .filter(path -> !list.getItems().contains(path)) + .forEach(path -> list.getItems().add(path)) + ); Button removeButton = new Button("remove"); footer.getChildren().add(removeButton);