Fix drag-n-drop for app. Add drag-n-drop for RCM tab
This commit is contained in:
parent
6b6bf8320f
commit
8eb05bb1b5
7 changed files with 134 additions and 64 deletions
|
@ -6,6 +6,8 @@ import javafx.concurrent.Task;
|
|||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.DragEvent;
|
||||
import javafx.scene.input.TransferMode;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
|
@ -285,6 +287,39 @@ public class FrontController implements Initializable {
|
|||
usbNetCommunications.cancel(false);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Drag-n-drop support (dragOver consumer)
|
||||
* */
|
||||
@FXML
|
||||
private void handleDragOver(DragEvent event){
|
||||
if (event.getDragboard().hasFiles())
|
||||
event.acceptTransferModes(TransferMode.ANY);
|
||||
event.consume();
|
||||
}
|
||||
/**
|
||||
* Drag-n-drop support (drop consumer)
|
||||
* */
|
||||
@FXML
|
||||
private void handleDrop(DragEvent event){
|
||||
if (MediatorControl.getInstance().getTransferActive()) {
|
||||
event.setDropCompleted(true);
|
||||
return;
|
||||
}
|
||||
List<File> filesDropped = event.getDragboard().getFiles();
|
||||
|
||||
if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport())
|
||||
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
|
||||
else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL()))
|
||||
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
|
||||
else
|
||||
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));
|
||||
|
||||
if ( ! filesDropped.isEmpty() )
|
||||
tableFilesListController.setFiles(filesDropped);
|
||||
|
||||
event.setDropCompleted(true);
|
||||
event.consume();
|
||||
}
|
||||
/**
|
||||
* This thing modify UI for reusing 'Upload to NS' button and make functionality set for "Stop transmission"
|
||||
* Called from mediator
|
||||
|
|
|
@ -5,12 +5,9 @@ import javafx.concurrent.Task;
|
|||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.DragEvent;
|
||||
import javafx.scene.input.TransferMode;
|
||||
import nsusbloader.*;
|
||||
import nsusbloader.ModelControllers.UpdatesChecker;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.*;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -78,38 +75,6 @@ public class NSLMainController implements Initializable {
|
|||
* */
|
||||
public void setHostServices(HostServices hs ){ SettingsTabController.registerHostServices(hs);}
|
||||
|
||||
|
||||
/**
|
||||
* Drag-n-drop support (dragOver consumer)
|
||||
* */
|
||||
@FXML
|
||||
private void handleDragOver(DragEvent event){
|
||||
if (event.getDragboard().hasFiles())
|
||||
event.acceptTransferModes(TransferMode.ANY);
|
||||
}
|
||||
/**
|
||||
* Drag-n-drop support (drop consumer)
|
||||
* */
|
||||
@FXML
|
||||
private void handleDrop(DragEvent event){
|
||||
if (MediatorControl.getInstance().getTransferActive()) {
|
||||
event.setDropCompleted(true);
|
||||
return;
|
||||
}
|
||||
List<File> filesDropped = event.getDragboard().getFiles();
|
||||
|
||||
if (FrontTabController.getSelectedProtocol().equals("TinFoil") && SettingsTabController.getTfXciNszXczSupport())
|
||||
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
|
||||
else if (FrontTabController.getSelectedProtocol().equals("GoldLeaf") && (! SettingsTabController.getNSPFileFilterForGL()))
|
||||
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
|
||||
else
|
||||
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));
|
||||
|
||||
if ( ! filesDropped.isEmpty() )
|
||||
FrontTabController.tableFilesListController.setFiles(filesDropped);
|
||||
|
||||
event.setDropCompleted(true);
|
||||
}
|
||||
/**
|
||||
* Get 'Settings' controller
|
||||
* Used by FrontController
|
||||
|
|
|
@ -9,7 +9,9 @@ import javafx.scene.control.Button;
|
|||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.input.DragEvent;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.TransferMode;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.FileChooser;
|
||||
import nsusbloader.AppPreferences;
|
||||
|
@ -50,7 +52,7 @@ public class RcmController implements Initializable {
|
|||
private Label statusLbl;
|
||||
|
||||
private ResourceBundle rb;
|
||||
|
||||
private String myRegexp;
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
this.rb = resourceBundle;
|
||||
|
@ -66,12 +68,11 @@ public class RcmController implements Initializable {
|
|||
String recentRcm3 = AppPreferences.getInstance().getRecentRcm(3);
|
||||
String recentRcm4 = AppPreferences.getInstance().getRecentRcm(4);
|
||||
String recentRcm5 = AppPreferences.getInstance().getRecentRcm(5);
|
||||
|
||||
String myRegexp;
|
||||
|
||||
if (File.separator.equals("/"))
|
||||
myRegexp = "^.+/";
|
||||
this.myRegexp = "^.+/";
|
||||
else
|
||||
myRegexp = "^.+\\\\";
|
||||
this.myRegexp = "^.+\\\\";
|
||||
|
||||
if (! recentRcm1.isEmpty()) {
|
||||
payloadFNameLbl1.setText(recentRcm1.replaceAll(myRegexp, ""));
|
||||
|
@ -98,6 +99,81 @@ public class RcmController implements Initializable {
|
|||
injectPldBtn.setOnAction(actionEvent -> smash());
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag-n-drop support (dragOver consumer)
|
||||
* */
|
||||
@FXML
|
||||
private void handleDragOver(DragEvent event){
|
||||
if (event.getDragboard().hasFiles())
|
||||
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()){
|
||||
event.setDropCompleted(true);
|
||||
event.consume();
|
||||
return;
|
||||
}
|
||||
|
||||
String fileNameDrpd = fileDrpd.getAbsolutePath();
|
||||
|
||||
switch (sourceNode.getId()){
|
||||
case "plHbox1":
|
||||
setPayloadFile( 1, fileNameDrpd);
|
||||
break;
|
||||
case "plHbox2":
|
||||
setPayloadFile( 2, fileNameDrpd);
|
||||
break;
|
||||
case "plHbox3":
|
||||
setPayloadFile( 3, fileNameDrpd);
|
||||
break;
|
||||
case "plHbox4":
|
||||
setPayloadFile( 4, fileNameDrpd);
|
||||
break;
|
||||
case "plHbox5":
|
||||
setPayloadFile( 5, fileNameDrpd);
|
||||
}
|
||||
event.setDropCompleted(true);
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void setPayloadFile(int RcmBoxNo, String fileName){
|
||||
String fileNameShort = fileName.replaceAll(myRegexp, "");
|
||||
switch (RcmBoxNo){
|
||||
case 1:
|
||||
payloadFNameLbl1.setText(fileNameShort);
|
||||
payloadFPathLbl1.setText(fileName);
|
||||
rcmToggleGrp.selectToggle(pldrRadio1);
|
||||
break;
|
||||
case 2:
|
||||
payloadFNameLbl2.setText(fileNameShort);
|
||||
payloadFPathLbl2.setText(fileName);
|
||||
rcmToggleGrp.selectToggle(pldrRadio2);
|
||||
break;
|
||||
case 3:
|
||||
payloadFNameLbl3.setText(fileNameShort);
|
||||
payloadFPathLbl3.setText(fileName);
|
||||
rcmToggleGrp.selectToggle(pldrRadio3);
|
||||
break;
|
||||
case 4:
|
||||
payloadFNameLbl4.setText(fileNameShort);
|
||||
payloadFPathLbl4.setText(fileName);
|
||||
rcmToggleGrp.selectToggle(pldrRadio4);
|
||||
break;
|
||||
case 5:
|
||||
payloadFNameLbl5.setText(fileNameShort);
|
||||
payloadFPathLbl5.setText(fileName);
|
||||
rcmToggleGrp.selectToggle(pldrRadio5);
|
||||
}
|
||||
}
|
||||
|
||||
private void smash(){
|
||||
statusLbl.setText("");
|
||||
if (MediatorControl.getInstance().getTransferActive()) {
|
||||
|
@ -149,37 +225,31 @@ public class RcmController implements Initializable {
|
|||
else
|
||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
|
||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("bin", "*.bin"));
|
||||
fileChooser.getExtensionFilters().addAll(
|
||||
new FileChooser.ExtensionFilter("bin", "*.bin"),
|
||||
new FileChooser.ExtensionFilter("Any file", "*.*")
|
||||
);
|
||||
|
||||
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":
|
||||
payloadFNameLbl1.setText(payloadFile.getName());
|
||||
payloadFPathLbl1.setText(payloadFile.getAbsolutePath());
|
||||
rcmToggleGrp.selectToggle(pldrRadio1);
|
||||
setPayloadFile(1, fullFileName);
|
||||
break;
|
||||
case "selPldBtn2":
|
||||
payloadFNameLbl2.setText(payloadFile.getName());
|
||||
payloadFPathLbl2.setText(payloadFile.getAbsolutePath());
|
||||
rcmToggleGrp.selectToggle(pldrRadio2);
|
||||
setPayloadFile(2, fullFileName);
|
||||
break;
|
||||
case "selPldBtn3":
|
||||
payloadFNameLbl3.setText(payloadFile.getName());
|
||||
payloadFPathLbl3.setText(payloadFile.getAbsolutePath());
|
||||
rcmToggleGrp.selectToggle(pldrRadio3);
|
||||
setPayloadFile(3, fullFileName);
|
||||
break;
|
||||
case "selPldBtn4":
|
||||
payloadFNameLbl4.setText(payloadFile.getName());
|
||||
payloadFPathLbl4.setText(payloadFile.getAbsolutePath());
|
||||
rcmToggleGrp.selectToggle(pldrRadio4);
|
||||
setPayloadFile(4, fullFileName);
|
||||
break;
|
||||
case "selPldBtn5":
|
||||
payloadFNameLbl5.setText(payloadFile.getName());
|
||||
payloadFPathLbl5.setText(payloadFile.getAbsolutePath());
|
||||
rcmToggleGrp.selectToggle(pldrRadio5);
|
||||
setPayloadFile(5, fullFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ public class RcmTask extends Task<Boolean> {
|
|||
totalSize += 4096;
|
||||
// Double-check
|
||||
if (totalSize > 0x30298){
|
||||
logPrinter.print("File size of the payload is too bit. Comparing to maximum size, it's greater to "+(totalSize - 0x30298)+" bytes!"+
|
||||
logPrinter.print("File size of the payload is too big. Comparing to maximum size, it's greater to "+(totalSize - 0x30298)+" bytes!"+
|
||||
"\n 1. Double-check that you're using the right payload." +
|
||||
"\n 2. Please report this issue in case you're sure that you're doing everything right." +
|
||||
"\n\n Nothing has been sent to NS. Execution stopped.", EMsgType.FAIL); // Occurs: never. I'm too lazy to check.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.SVGPath?>
|
||||
|
||||
<AnchorPane fx:id="usbNetPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.FrontController">
|
||||
<AnchorPane fx:id="usbNetPane" onDragDropped="#handleDrop" onDragOver="#handleDragOver" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.FrontController">
|
||||
<children>
|
||||
<VBox layoutX="10.0" layoutY="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.SVGPath?>
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onDragDropped="#handleDrop" onDragOver="#handleDragOver" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.NSLMainController">
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.NSLMainController">
|
||||
<children>
|
||||
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<VBox spacing="8.0">
|
||||
<children>
|
||||
<Label text="Payload: " />
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<HBox fx:id="plHbox1" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
|
||||
<children>
|
||||
<RadioButton fx:id="pldrRadio1" mnemonicParsing="false">
|
||||
<toggleGroup>
|
||||
|
@ -76,7 +76,7 @@
|
|||
</children>
|
||||
</HBox>
|
||||
<Separator prefWidth="200.0" />
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<HBox fx:id="plHbox2" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
|
||||
<children>
|
||||
<RadioButton fx:id="pldrRadio2" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
|
||||
<VBox fx:id="pldPane2" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
|
||||
|
@ -105,7 +105,7 @@
|
|||
</children>
|
||||
</HBox>
|
||||
<Separator prefWidth="200.0" />
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<HBox fx:id="plHbox3" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
|
||||
<children>
|
||||
<RadioButton fx:id="pldrRadio3" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
|
||||
<VBox fx:id="pldPane3" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
|
||||
|
@ -134,7 +134,7 @@
|
|||
</children>
|
||||
</HBox>
|
||||
<Separator prefWidth="200.0" />
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<HBox fx:id="plHbox4" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
|
||||
<children>
|
||||
<RadioButton fx:id="pldrRadio4" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
|
||||
<VBox fx:id="pldPane4" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
|
||||
|
@ -163,7 +163,7 @@
|
|||
</children>
|
||||
</HBox>
|
||||
<Separator prefWidth="200.0" />
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<HBox fx:id="plHbox5" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
|
||||
<children>
|
||||
<RadioButton fx:id="pldrRadio5" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
|
||||
<VBox fx:id="pldPane5" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
|
||||
|
|
Loading…
Reference in a new issue