Skip to content

Commit

Permalink
Add drag and drop support for loading files.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkevilmac committed Jul 28, 2024
1 parent 59da290 commit 069220c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/com/tridevmc/dolphintortcmap/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ public void start(Stage stage) throws IOException {
stage.setScene(scene);

// Check if a file was passed as an argument, if it was then tell the LinkerMapToRTCMapController to load it.
if(!getParameters().getRaw().isEmpty()) {
if (!getParameters().getRaw().isEmpty()) {
File file = new File(getParameters().getRaw().getFirst());
LinkerMapToRTCMapController controller = fxmlLoader.getController();
controller.loadFile(file);
}

// Add a drag and drop listener that will load the file when a file is dropped onto the window.
scene.setOnDragOver(event -> {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(javafx.scene.input.TransferMode.COPY);
}
event.consume();
});

scene.setOnDragDropped(event -> {
var db = event.getDragboard();
if (db.hasFiles()) {
File file = db.getFiles().getFirst();
LinkerMapToRTCMapController controller = fxmlLoader.getController();
controller.loadFile(file);
}
event.setDropCompleted(true);
event.consume();
});

stage.show();
}

Expand Down

0 comments on commit 069220c

Please sign in to comment.