Skip to content

Commit 8eb05bb

Browse files
committed
Fix drag-n-drop for app. Add drag-n-drop for RCM tab
1 parent 6b6bf83 commit 8eb05bb

File tree

7 files changed

+134
-64
lines changed

7 files changed

+134
-64
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import javafx.fxml.FXML;
77
import javafx.fxml.Initializable;
88
import javafx.scene.control.*;
9+
import javafx.scene.input.DragEvent;
10+
import javafx.scene.input.TransferMode;
911
import javafx.scene.layout.AnchorPane;
1012
import javafx.scene.layout.Region;
1113
import javafx.stage.DirectoryChooser;
@@ -285,6 +287,39 @@ private void stopBtnAction(){
285287
usbNetCommunications.cancel(false);
286288
}
287289
}
290+
/**
291+
* Drag-n-drop support (dragOver consumer)
292+
* */
293+
@FXML
294+
private void handleDragOver(DragEvent event){
295+
if (event.getDragboard().hasFiles())
296+
event.acceptTransferModes(TransferMode.ANY);
297+
event.consume();
298+
}
299+
/**
300+
* Drag-n-drop support (drop consumer)
301+
* */
302+
@FXML
303+
private void handleDrop(DragEvent event){
304+
if (MediatorControl.getInstance().getTransferActive()) {
305+
event.setDropCompleted(true);
306+
return;
307+
}
308+
List<File> filesDropped = event.getDragboard().getFiles();
309+
310+
if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport())
311+
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
312+
else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL()))
313+
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
314+
else
315+
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));
316+
317+
if ( ! filesDropped.isEmpty() )
318+
tableFilesListController.setFiles(filesDropped);
319+
320+
event.setDropCompleted(true);
321+
event.consume();
322+
}
288323
/**
289324
* This thing modify UI for reusing 'Upload to NS' button and make functionality set for "Stop transmission"
290325
* Called from mediator

src/main/java/nsusbloader/Controllers/NSLMainController.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import javafx.fxml.FXML;
66
import javafx.fxml.Initializable;
77
import javafx.scene.control.*;
8-
import javafx.scene.input.DragEvent;
9-
import javafx.scene.input.TransferMode;
108
import nsusbloader.*;
119
import nsusbloader.ModelControllers.UpdatesChecker;
1210

13-
import java.io.File;
1411
import java.net.*;
1512
import java.util.List;
1613
import java.util.ResourceBundle;
@@ -78,38 +75,6 @@ public ResourceBundle getResourceBundle() {
7875
* */
7976
public void setHostServices(HostServices hs ){ SettingsTabController.registerHostServices(hs);}
8077

81-
82-
/**
83-
* Drag-n-drop support (dragOver consumer)
84-
* */
85-
@FXML
86-
private void handleDragOver(DragEvent event){
87-
if (event.getDragboard().hasFiles())
88-
event.acceptTransferModes(TransferMode.ANY);
89-
}
90-
/**
91-
* Drag-n-drop support (drop consumer)
92-
* */
93-
@FXML
94-
private void handleDrop(DragEvent event){
95-
if (MediatorControl.getInstance().getTransferActive()) {
96-
event.setDropCompleted(true);
97-
return;
98-
}
99-
List<File> filesDropped = event.getDragboard().getFiles();
100-
101-
if (FrontTabController.getSelectedProtocol().equals("TinFoil") && SettingsTabController.getTfXciNszXczSupport())
102-
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
103-
else if (FrontTabController.getSelectedProtocol().equals("GoldLeaf") && (! SettingsTabController.getNSPFileFilterForGL()))
104-
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
105-
else
106-
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));
107-
108-
if ( ! filesDropped.isEmpty() )
109-
FrontTabController.tableFilesListController.setFiles(filesDropped);
110-
111-
event.setDropCompleted(true);
112-
}
11378
/**
11479
* Get 'Settings' controller
11580
* Used by FrontController

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

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import javafx.scene.control.Label;
1010
import javafx.scene.control.RadioButton;
1111
import javafx.scene.control.ToggleGroup;
12+
import javafx.scene.input.DragEvent;
1213
import javafx.scene.input.MouseEvent;
14+
import javafx.scene.input.TransferMode;
1315
import javafx.scene.layout.VBox;
1416
import javafx.stage.FileChooser;
1517
import nsusbloader.AppPreferences;
@@ -50,7 +52,7 @@ public class RcmController implements Initializable {
5052
private Label statusLbl;
5153

5254
private ResourceBundle rb;
53-
55+
private String myRegexp;
5456
@Override
5557
public void initialize(URL url, ResourceBundle resourceBundle) {
5658
this.rb = resourceBundle;
@@ -66,12 +68,11 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
6668
String recentRcm3 = AppPreferences.getInstance().getRecentRcm(3);
6769
String recentRcm4 = AppPreferences.getInstance().getRecentRcm(4);
6870
String recentRcm5 = AppPreferences.getInstance().getRecentRcm(5);
69-
70-
String myRegexp;
71+
7172
if (File.separator.equals("/"))
72-
myRegexp = "^.+/";
73+
this.myRegexp = "^.+/";
7374
else
74-
myRegexp = "^.+\\\\";
75+
this.myRegexp = "^.+\\\\";
7576

7677
if (! recentRcm1.isEmpty()) {
7778
payloadFNameLbl1.setText(recentRcm1.replaceAll(myRegexp, ""));
@@ -98,6 +99,81 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
9899
injectPldBtn.setOnAction(actionEvent -> smash());
99100
}
100101

102+
/**
103+
* Drag-n-drop support (dragOver consumer)
104+
* */
105+
@FXML
106+
private void handleDragOver(DragEvent event){
107+
if (event.getDragboard().hasFiles())
108+
event.acceptTransferModes(TransferMode.ANY);
109+
event.consume();
110+
}
111+
/**
112+
* Drag-n-drop support (drop consumer)
113+
* */
114+
@FXML
115+
private void handleDrop(DragEvent event){
116+
Node sourceNode = (Node) event.getSource();
117+
File fileDrpd = event.getDragboard().getFiles().get(0);
118+
119+
if (fileDrpd.isDirectory()){
120+
event.setDropCompleted(true);
121+
event.consume();
122+
return;
123+
}
124+
125+
String fileNameDrpd = fileDrpd.getAbsolutePath();
126+
127+
switch (sourceNode.getId()){
128+
case "plHbox1":
129+
setPayloadFile( 1, fileNameDrpd);
130+
break;
131+
case "plHbox2":
132+
setPayloadFile( 2, fileNameDrpd);
133+
break;
134+
case "plHbox3":
135+
setPayloadFile( 3, fileNameDrpd);
136+
break;
137+
case "plHbox4":
138+
setPayloadFile( 4, fileNameDrpd);
139+
break;
140+
case "plHbox5":
141+
setPayloadFile( 5, fileNameDrpd);
142+
}
143+
event.setDropCompleted(true);
144+
event.consume();
145+
}
146+
147+
private void setPayloadFile(int RcmBoxNo, String fileName){
148+
String fileNameShort = fileName.replaceAll(myRegexp, "");
149+
switch (RcmBoxNo){
150+
case 1:
151+
payloadFNameLbl1.setText(fileNameShort);
152+
payloadFPathLbl1.setText(fileName);
153+
rcmToggleGrp.selectToggle(pldrRadio1);
154+
break;
155+
case 2:
156+
payloadFNameLbl2.setText(fileNameShort);
157+
payloadFPathLbl2.setText(fileName);
158+
rcmToggleGrp.selectToggle(pldrRadio2);
159+
break;
160+
case 3:
161+
payloadFNameLbl3.setText(fileNameShort);
162+
payloadFPathLbl3.setText(fileName);
163+
rcmToggleGrp.selectToggle(pldrRadio3);
164+
break;
165+
case 4:
166+
payloadFNameLbl4.setText(fileNameShort);
167+
payloadFPathLbl4.setText(fileName);
168+
rcmToggleGrp.selectToggle(pldrRadio4);
169+
break;
170+
case 5:
171+
payloadFNameLbl5.setText(fileNameShort);
172+
payloadFPathLbl5.setText(fileName);
173+
rcmToggleGrp.selectToggle(pldrRadio5);
174+
}
175+
}
176+
101177
private void smash(){
102178
statusLbl.setText("");
103179
if (MediatorControl.getInstance().getTransferActive()) {
@@ -149,37 +225,31 @@ private void bntSelectPayloader(ActionEvent event){
149225
else
150226
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
151227

152-
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("bin", "*.bin"));
228+
fileChooser.getExtensionFilters().addAll(
229+
new FileChooser.ExtensionFilter("bin", "*.bin"),
230+
new FileChooser.ExtensionFilter("Any file", "*.*")
231+
);
153232

154233
File payloadFile = fileChooser.showOpenDialog(payloadFPathLbl1.getScene().getWindow());
155234
if (payloadFile != null) {
235+
final String fullFileName = payloadFile.getAbsolutePath();
156236
final Node btn = (Node)event.getSource();
157237

158238
switch (btn.getId()){
159239
case "selPldBtn1":
160-
payloadFNameLbl1.setText(payloadFile.getName());
161-
payloadFPathLbl1.setText(payloadFile.getAbsolutePath());
162-
rcmToggleGrp.selectToggle(pldrRadio1);
240+
setPayloadFile(1, fullFileName);
163241
break;
164242
case "selPldBtn2":
165-
payloadFNameLbl2.setText(payloadFile.getName());
166-
payloadFPathLbl2.setText(payloadFile.getAbsolutePath());
167-
rcmToggleGrp.selectToggle(pldrRadio2);
243+
setPayloadFile(2, fullFileName);
168244
break;
169245
case "selPldBtn3":
170-
payloadFNameLbl3.setText(payloadFile.getName());
171-
payloadFPathLbl3.setText(payloadFile.getAbsolutePath());
172-
rcmToggleGrp.selectToggle(pldrRadio3);
246+
setPayloadFile(3, fullFileName);
173247
break;
174248
case "selPldBtn4":
175-
payloadFNameLbl4.setText(payloadFile.getName());
176-
payloadFPathLbl4.setText(payloadFile.getAbsolutePath());
177-
rcmToggleGrp.selectToggle(pldrRadio4);
249+
setPayloadFile(4, fullFileName);
178250
break;
179251
case "selPldBtn5":
180-
payloadFNameLbl5.setText(payloadFile.getName());
181-
payloadFPathLbl5.setText(payloadFile.getAbsolutePath());
182-
rcmToggleGrp.selectToggle(pldrRadio5);
252+
setPayloadFile(5, fullFileName);
183253
}
184254
}
185255
}

src/main/java/nsusbloader/Utilities/RcmTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private boolean preparePayload(){
179179
totalSize += 4096;
180180
// Double-check
181181
if (totalSize > 0x30298){
182-
logPrinter.print("File size of the payload is too bit. Comparing to maximum size, it's greater to "+(totalSize - 0x30298)+" bytes!"+
182+
logPrinter.print("File size of the payload is too big. Comparing to maximum size, it's greater to "+(totalSize - 0x30298)+" bytes!"+
183183
"\n 1. Double-check that you're using the right payload." +
184184
"\n 2. Please report this issue in case you're sure that you're doing everything right." +
185185
"\n\n Nothing has been sent to NS. Execution stopped.", EMsgType.FAIL); // Occurs: never. I'm too lazy to check.

src/main/resources/FrontTab.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<?import javafx.scene.layout.VBox?>
1717
<?import javafx.scene.shape.SVGPath?>
1818

19-
<AnchorPane fx:id="usbNetPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.FrontController">
19+
<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">
2020
<children>
2121
<VBox layoutX="10.0" layoutY="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
2222
<children>

src/main/resources/NSLMain.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<?import javafx.scene.layout.VBox?>
1010
<?import javafx.scene.shape.SVGPath?>
1111

12-
<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">
12+
<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">
1313
<children>
1414
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
1515
<children>

src/main/resources/RcmTab.fxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<VBox spacing="8.0">
4545
<children>
4646
<Label text="Payload: " />
47-
<HBox alignment="CENTER_LEFT" spacing="5.0">
47+
<HBox fx:id="plHbox1" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
4848
<children>
4949
<RadioButton fx:id="pldrRadio1" mnemonicParsing="false">
5050
<toggleGroup>
@@ -76,7 +76,7 @@
7676
</children>
7777
</HBox>
7878
<Separator prefWidth="200.0" />
79-
<HBox alignment="CENTER_LEFT" spacing="5.0">
79+
<HBox fx:id="plHbox2" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
8080
<children>
8181
<RadioButton fx:id="pldrRadio2" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
8282
<VBox fx:id="pldPane2" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
@@ -105,7 +105,7 @@
105105
</children>
106106
</HBox>
107107
<Separator prefWidth="200.0" />
108-
<HBox alignment="CENTER_LEFT" spacing="5.0">
108+
<HBox fx:id="plHbox3" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
109109
<children>
110110
<RadioButton fx:id="pldrRadio3" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
111111
<VBox fx:id="pldPane3" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
@@ -134,7 +134,7 @@
134134
</children>
135135
</HBox>
136136
<Separator prefWidth="200.0" />
137-
<HBox alignment="CENTER_LEFT" spacing="5.0">
137+
<HBox fx:id="plHbox4" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
138138
<children>
139139
<RadioButton fx:id="pldrRadio4" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
140140
<VBox fx:id="pldPane4" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">
@@ -163,7 +163,7 @@
163163
</children>
164164
</HBox>
165165
<Separator prefWidth="200.0" />
166-
<HBox alignment="CENTER_LEFT" spacing="5.0">
166+
<HBox fx:id="plHbox5" alignment="CENTER_LEFT" onDragDropped="#handleDrop" onDragOver="#handleDragOver" spacing="5.0">
167167
<children>
168168
<RadioButton fx:id="pldrRadio5" mnemonicParsing="false" toggleGroup="$rcmToggleGrp" />
169169
<VBox fx:id="pldPane5" onMouseClicked="#selectPldrPane" HBox.hgrow="ALWAYS">

0 commit comments

Comments
 (0)