From 2e0d5839633ed0f907981c992ea43b4c9d37d62d Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Tue, 11 Feb 2020 00:42:43 +0300 Subject: [PATCH] Add drag-n-drop for Split'n'merge tab. Fix minor issues. --- .../Controllers/FrontController.java | 6 +-- .../Controllers/RcmController.java | 40 ++++++++++--------- .../Controllers/SplitMergeController.java | 39 ++++++++++++++++-- .../nsusbloader/Utilities/SplitMergeTool.java | 4 +- src/main/resources/SplitMergeTab.fxml | 2 +- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/src/main/java/nsusbloader/Controllers/FrontController.java b/src/main/java/nsusbloader/Controllers/FrontController.java index f686b23..16f6d44 100644 --- a/src/main/java/nsusbloader/Controllers/FrontController.java +++ b/src/main/java/nsusbloader/Controllers/FrontController.java @@ -292,7 +292,7 @@ public class FrontController implements Initializable { * */ @FXML private void handleDragOver(DragEvent event){ - if (event.getDragboard().hasFiles()) + if (event.getDragboard().hasFiles() && ! MediatorControl.getInstance().getTransferActive()) event.acceptTransferModes(TransferMode.ANY); event.consume(); } @@ -301,10 +301,6 @@ public class FrontController implements Initializable { * */ @FXML private void handleDrop(DragEvent event){ - if (MediatorControl.getInstance().getTransferActive()) { - event.setDropCompleted(true); - return; - } List filesDropped = event.getDragboard().getFiles(); if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport()) diff --git a/src/main/java/nsusbloader/Controllers/RcmController.java b/src/main/java/nsusbloader/Controllers/RcmController.java index 2ebfd39..6ac8869 100644 --- a/src/main/java/nsusbloader/Controllers/RcmController.java +++ b/src/main/java/nsusbloader/Controllers/RcmController.java @@ -231,26 +231,28 @@ public class RcmController implements Initializable { ); File payloadFile = fileChooser.showOpenDialog(payloadFPathLbl1.getScene().getWindow()); - if (payloadFile != null) { - final String fullFileName = payloadFile.getAbsolutePath(); - final Node btn = (Node)event.getSource(); - switch (btn.getId()){ - case "selPldBtn1": - setPayloadFile(1, fullFileName); - break; - case "selPldBtn2": - setPayloadFile(2, fullFileName); - break; - case "selPldBtn3": - setPayloadFile(3, fullFileName); - break; - case "selPldBtn4": - setPayloadFile(4, fullFileName); - break; - case "selPldBtn5": - setPayloadFile(5, fullFileName); - } + if (payloadFile == null) + return; + + final String fullFileName = payloadFile.getAbsolutePath(); + final Node btn = (Node)event.getSource(); + + switch (btn.getId()){ + case "selPldBtn1": + setPayloadFile(1, fullFileName); + break; + case "selPldBtn2": + setPayloadFile(2, fullFileName); + break; + case "selPldBtn3": + setPayloadFile(3, fullFileName); + break; + case "selPldBtn4": + setPayloadFile(4, fullFileName); + break; + case "selPldBtn5": + setPayloadFile(5, fullFileName); } } @FXML diff --git a/src/main/java/nsusbloader/Controllers/SplitMergeController.java b/src/main/java/nsusbloader/Controllers/SplitMergeController.java index d0fa894..59c0787 100644 --- a/src/main/java/nsusbloader/Controllers/SplitMergeController.java +++ b/src/main/java/nsusbloader/Controllers/SplitMergeController.java @@ -3,7 +3,10 @@ package nsusbloader.Controllers; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.Node; import javafx.scene.control.*; +import javafx.scene.input.DragEvent; +import javafx.scene.input.TransferMode; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; @@ -101,7 +104,6 @@ public class SplitMergeController implements Initializable { if (fileFile == null) return; fileFolderActualPathLbl.setText(fileFile.getAbsolutePath()); - convertBtn.setDisable(false); } else{ DirectoryChooser dc = new DirectoryChooser(); @@ -120,14 +122,14 @@ public class SplitMergeController implements Initializable { if (folderFile == null) return; fileFolderActualPathLbl.setText(folderFile.getAbsolutePath()); - convertBtn.setDisable(false); } + convertBtn.setDisable(false); }); convertBtn.setOnAction(actionEvent -> setConvertBtnAction()); } - public void notifySmThreadStarted(boolean isStart, EModule type){ + public void notifySmThreadStarted(boolean isStart, EModule type){ // todo: refactor: remove everything, place to separate container and just disable. if (! type.equals(EModule.SPLIT_MERGE_TOOL)){ smToolPane.setDisable(isStart); return; @@ -176,7 +178,10 @@ public class SplitMergeController implements Initializable { private void setConvertBtnAction(){ statusLbl.setText(""); if (MediatorControl.getInstance().getTransferActive()) { - ServiceWindow.getErrorNotification(resourceBundle.getString("windowTitleError"), resourceBundle.getString("windowBodyPleaseFinishTransfersFirst")); + ServiceWindow.getErrorNotification( + resourceBundle.getString("windowTitleError"), + resourceBundle.getString("windowBodyPleaseFinishTransfersFirst") + ); return; } @@ -195,6 +200,32 @@ public class SplitMergeController implements Initializable { smThread.setDaemon(true); smThread.start(); } + /** + * Drag-n-drop support (dragOver consumer) + * */ + @FXML + private void handleDragOver(DragEvent event){ + if (event.getDragboard().hasFiles() && ! MediatorControl.getInstance().getTransferActive()) + event.acceptTransferModes(TransferMode.ANY); + event.consume(); + } + /** + * Drag-n-drop support (drop consumer) + * */ + @FXML + private void handleDrop(DragEvent event) { + Node sourceNode = (Node) event.getSource(); + File fileDrpd = event.getDragboard().getFiles().get(0); + + if (fileDrpd.isDirectory()) + mergeRad.fire(); + else + splitRad.fire(); + fileFolderActualPathLbl.setText(fileDrpd.getAbsolutePath()); + convertBtn.setDisable(false); + event.setDropCompleted(true); + event.consume(); + } /** * Save application settings on exit * */ diff --git a/src/main/java/nsusbloader/Utilities/SplitMergeTool.java b/src/main/java/nsusbloader/Utilities/SplitMergeTool.java index 9481fad..574e19c 100644 --- a/src/main/java/nsusbloader/Utilities/SplitMergeTool.java +++ b/src/main/java/nsusbloader/Utilities/SplitMergeTool.java @@ -175,7 +175,7 @@ class MergeTask extends Task { } @Override protected Boolean call() { - logPrinter.print("Merge file: "+filePath, EMsgType.INFO); + logPrinter.print("Merge file: "+filePath, EMsgType.INFO); File folder = new File(filePath); @@ -183,7 +183,7 @@ class MergeTask extends Task { File[] chunkFiles = folder.listFiles((file, s) -> s.matches("^[0-9][0-9]$")); - if (chunkFiles == null){ + if (chunkFiles == null || chunkFiles.length == 0){ logPrinter.print("Selected folder doesn't have any chunks. Nothing to do here.", EMsgType.FAIL); logPrinter.close(); return false; diff --git a/src/main/resources/SplitMergeTab.fxml b/src/main/resources/SplitMergeTab.fxml index 5792d84..0032e02 100644 --- a/src/main/resources/SplitMergeTab.fxml +++ b/src/main/resources/SplitMergeTab.fxml @@ -14,7 +14,7 @@ - +