Skip to content

Commit 2e0d583

Browse files
committed
Add drag-n-drop for Split'n'merge tab. Fix minor issues.
1 parent 8eb05bb commit 2e0d583

File tree

5 files changed

+60
-31
lines changed

5 files changed

+60
-31
lines changed

src/main/java/nsusbloader/Controllers/FrontController.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private void stopBtnAction(){
292292
* */
293293
@FXML
294294
private void handleDragOver(DragEvent event){
295-
if (event.getDragboard().hasFiles())
295+
if (event.getDragboard().hasFiles() && ! MediatorControl.getInstance().getTransferActive())
296296
event.acceptTransferModes(TransferMode.ANY);
297297
event.consume();
298298
}
@@ -301,10 +301,6 @@ private void handleDragOver(DragEvent event){
301301
* */
302302
@FXML
303303
private void handleDrop(DragEvent event){
304-
if (MediatorControl.getInstance().getTransferActive()) {
305-
event.setDropCompleted(true);
306-
return;
307-
}
308304
List<File> filesDropped = event.getDragboard().getFiles();
309305

310306
if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport())

src/main/java/nsusbloader/Controllers/RcmController.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,28 @@ private void bntSelectPayloader(ActionEvent event){
231231
);
232232

233233
File payloadFile = fileChooser.showOpenDialog(payloadFPathLbl1.getScene().getWindow());
234-
if (payloadFile != null) {
235-
final String fullFileName = payloadFile.getAbsolutePath();
236-
final Node btn = (Node)event.getSource();
237234

238-
switch (btn.getId()){
239-
case "selPldBtn1":
240-
setPayloadFile(1, fullFileName);
241-
break;
242-
case "selPldBtn2":
243-
setPayloadFile(2, fullFileName);
244-
break;
245-
case "selPldBtn3":
246-
setPayloadFile(3, fullFileName);
247-
break;
248-
case "selPldBtn4":
249-
setPayloadFile(4, fullFileName);
250-
break;
251-
case "selPldBtn5":
252-
setPayloadFile(5, fullFileName);
253-
}
235+
if (payloadFile == null)
236+
return;
237+
238+
final String fullFileName = payloadFile.getAbsolutePath();
239+
final Node btn = (Node)event.getSource();
240+
241+
switch (btn.getId()){
242+
case "selPldBtn1":
243+
setPayloadFile(1, fullFileName);
244+
break;
245+
case "selPldBtn2":
246+
setPayloadFile(2, fullFileName);
247+
break;
248+
case "selPldBtn3":
249+
setPayloadFile(3, fullFileName);
250+
break;
251+
case "selPldBtn4":
252+
setPayloadFile(4, fullFileName);
253+
break;
254+
case "selPldBtn5":
255+
setPayloadFile(5, fullFileName);
254256
}
255257
}
256258
@FXML

src/main/java/nsusbloader/Controllers/SplitMergeController.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import javafx.concurrent.Task;
44
import javafx.fxml.FXML;
55
import javafx.fxml.Initializable;
6+
import javafx.scene.Node;
67
import javafx.scene.control.*;
8+
import javafx.scene.input.DragEvent;
9+
import javafx.scene.input.TransferMode;
710
import javafx.scene.layout.Region;
811
import javafx.scene.layout.VBox;
912
import javafx.stage.DirectoryChooser;
@@ -101,7 +104,6 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
101104
if (fileFile == null)
102105
return;
103106
fileFolderActualPathLbl.setText(fileFile.getAbsolutePath());
104-
convertBtn.setDisable(false);
105107
}
106108
else{
107109
DirectoryChooser dc = new DirectoryChooser();
@@ -120,14 +122,14 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
120122
if (folderFile == null)
121123
return;
122124
fileFolderActualPathLbl.setText(folderFile.getAbsolutePath());
123-
convertBtn.setDisable(false);
124125
}
126+
convertBtn.setDisable(false);
125127
});
126128

127129
convertBtn.setOnAction(actionEvent -> setConvertBtnAction());
128130
}
129131

130-
public void notifySmThreadStarted(boolean isStart, EModule type){
132+
public void notifySmThreadStarted(boolean isStart, EModule type){ // todo: refactor: remove everything, place to separate container and just disable.
131133
if (! type.equals(EModule.SPLIT_MERGE_TOOL)){
132134
smToolPane.setDisable(isStart);
133135
return;
@@ -176,7 +178,10 @@ private void stopBtnAction(){
176178
private void setConvertBtnAction(){
177179
statusLbl.setText("");
178180
if (MediatorControl.getInstance().getTransferActive()) {
179-
ServiceWindow.getErrorNotification(resourceBundle.getString("windowTitleError"), resourceBundle.getString("windowBodyPleaseFinishTransfersFirst"));
181+
ServiceWindow.getErrorNotification(
182+
resourceBundle.getString("windowTitleError"),
183+
resourceBundle.getString("windowBodyPleaseFinishTransfersFirst")
184+
);
180185
return;
181186
}
182187

@@ -195,6 +200,32 @@ private void setConvertBtnAction(){
195200
smThread.setDaemon(true);
196201
smThread.start();
197202
}
203+
/**
204+
* Drag-n-drop support (dragOver consumer)
205+
* */
206+
@FXML
207+
private void handleDragOver(DragEvent event){
208+
if (event.getDragboard().hasFiles() && ! MediatorControl.getInstance().getTransferActive())
209+
event.acceptTransferModes(TransferMode.ANY);
210+
event.consume();
211+
}
212+
/**
213+
* Drag-n-drop support (drop consumer)
214+
* */
215+
@FXML
216+
private void handleDrop(DragEvent event) {
217+
Node sourceNode = (Node) event.getSource();
218+
File fileDrpd = event.getDragboard().getFiles().get(0);
219+
220+
if (fileDrpd.isDirectory())
221+
mergeRad.fire();
222+
else
223+
splitRad.fire();
224+
fileFolderActualPathLbl.setText(fileDrpd.getAbsolutePath());
225+
convertBtn.setDisable(false);
226+
event.setDropCompleted(true);
227+
event.consume();
228+
}
198229
/**
199230
* Save application settings on exit
200231
* */

src/main/java/nsusbloader/Utilities/SplitMergeTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ class MergeTask extends Task<Boolean> {
175175
}
176176
@Override
177177
protected Boolean call() {
178-
logPrinter.print("Merge file: "+filePath, EMsgType.INFO);
178+
logPrinter.print("Merge file: "+filePath, EMsgType.INFO);
179179

180180
File folder = new File(filePath);
181181

182182
long cnkTotalSize = 0;
183183

184184
File[] chunkFiles = folder.listFiles((file, s) -> s.matches("^[0-9][0-9]$"));
185185

186-
if (chunkFiles == null){
186+
if (chunkFiles == null || chunkFiles.length == 0){
187187
logPrinter.print("Selected folder doesn't have any chunks. Nothing to do here.", EMsgType.FAIL);
188188
logPrinter.close();
189189
return false;

src/main/resources/SplitMergeTab.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<?import javafx.scene.layout.VBox?>
1515
<?import javafx.scene.text.Font?>
1616

17-
<VBox fx:id="smToolPane" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.SplitMergeController">
17+
<VBox fx:id="smToolPane" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.SplitMergeController">
1818
<VBox spacing="15.0">
1919
<children>
2020
<Pane minHeight="-Infinity" prefHeight="10.0" style="-fx-background-color: linear-gradient(from 41px 34px to 50px 50px, reflect, #00c8fc 40%, transparent 45%);" />

0 commit comments

Comments
 (0)