Skip to content

Commit

Permalink
Allow directories to be opened via drag & drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Nianna committed Oct 20, 2024
1 parent 06d6226 commit 121cd88
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,24 @@ private boolean isATxtFile(File file) {

private void onDragOver(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasFiles() && db.getFiles().stream().anyMatch(this::isATxtFile)) {
if (db.hasFiles() && findDraggedTxtFileToOpen(db).isPresent()) {
event.acceptTransferModes(TransferMode.MOVE);
} else {
event.consume();
}
}

private Optional<File> findDraggedTxtFileToOpen(Dragboard db) {
return db.getFiles().stream()
.filter(File::exists)
.findFirst()
.flatMap(this::getTxtFileFromFile);
}

private void onDragDropped(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasFiles()) {
Optional<File> optFile = db.getFiles().stream().filter(this::isATxtFile).findFirst();
optFile.ifPresent(file -> {
findDraggedTxtFileToOpen(db).ifPresent(file -> {
Platform.runLater(() -> {
KarediApp.getInstance().saveChangesIfUserWantsTo();
txtContext.loadSongFile(file);
Expand Down

0 comments on commit 121cd88

Please sign in to comment.