Drag-n-drop support

master
Dmitry Isaenko 2019-03-14 23:41:17 +03:00
parent 00db6984d9
commit 4cfd651667
5 changed files with 71 additions and 6 deletions

View File

@ -69,6 +69,10 @@ If you use different MacOS (not Mojave) - check release section for another JAR
Table 'Status' = 'Uploaded' does not means that file installed. It means that it has been sent to NS without any issues! That's what this app about.
Handling successful/failed installation is a purpose of the other side application (TinFoil/GoldLeaf). (And they don't provide any feedback interfaces so I can't detect success/failure.)
## Translators! Traducteurs! Traductores! Übersetzer! Թարգմանիչներ!
If you want to see this app translated to your language, go grab [this file](https://github.com/developersu/ns-usbloader/blob/master/src/main/resources/locale.properties) and translate it.
Upload somewhere (pastebin? google drive? whatever else). [Create new issue](https://github.com/developersu/ns-usbloader/issues) and post a link. I'll grab it and add.
## TODO:
- [x] macOS QA v0.1 (Mojave)
- [x] macOS QA v0.2.2 (Mojave)

View File

@ -5,6 +5,8 @@ import javafx.collections.ObservableList;
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.Pane;
import javafx.scene.layout.Region;
import javafx.stage.FileChooser;
@ -15,6 +17,7 @@ import nsusbloader.USB.UsbCommunications;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
@ -136,7 +139,7 @@ public class NSLMainController implements Initializable {
private void uploadBtnAction(){
if (usbThread == null || !usbThread.isAlive()){
List<File> nspToUpload;
if ((nspToUpload = tableFilesListController.getFiles()) == null) {
if ((nspToUpload = tableFilesListController.getFilesForUpload()) == null) {
logArea.setText(resourceBundle.getString("logsNoFolderFileSelected"));
return;
}else {
@ -188,6 +191,51 @@ public class NSLMainController implements Initializable {
uploadStopBtn.getStyleClass().add("buttonUp");
}
}
/**
* 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){
List<File> filesDropped = new ArrayList<>();
try {
for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.getName().toLowerCase().endsWith(".nsp"))
filesDropped.add(fileOrDir);
else if (fileOrDir.isDirectory())
for (File file : fileOrDir.listFiles())
if (file.getName().toLowerCase().endsWith(".nsp"))
filesDropped.add(file);
}
}
catch (SecurityException se){
se.printStackTrace();
}
if (!filesDropped.isEmpty()) {
List<File> filesAlreadyInTable;
if ((filesAlreadyInTable = tableFilesListController.getFiles()) != null) {
filesDropped.removeAll(filesAlreadyInTable); // Get what we already have and add new file(s)
if (!filesDropped.isEmpty()) {
filesDropped.addAll(tableFilesListController.getFiles());
tableFilesListController.setFiles(filesDropped);
}
}
else {
tableFilesListController.setFiles(filesDropped);
uploadStopBtn.setDisable(false);
}
}
event.setDropCompleted(true);
}
/**
* Save preferences before exit
* */

View File

@ -124,12 +124,27 @@ public class NSTableViewController implements Initializable {
rowsObsLst.get(0).setMarkForUpload(true);
}
}
/**
* Return all files no matter how they're marked
* */
public List<File> getFiles(){
List<File> files = new ArrayList<>();
if (rowsObsLst.isEmpty())
return null;
else
for (NSLRowModel model: rowsObsLst)
files.add(model.getNspFile());
if (!files.isEmpty())
return files;
else
return null;
}
/**
* Return files ready for upload. Requested from NSLMainController only -> uploadBtnAction() //TODO: set undefined
* @return null if no files marked for upload
* List<File> if there are files
* */
public List<File> getFiles(){
public List<File> getFilesForUpload(){
List<File> files = new ArrayList<>();
if (rowsObsLst.isEmpty())
return null;

View File

@ -18,10 +18,8 @@ public class NSLMain extends Application {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/NSLMain.fxml"));
ResourceBundle rb;
Locale userLocale = new Locale(Locale.getDefault().getISO3Language()); // NOTE: user locale based on ISO3 Language codes
rb = ResourceBundle.getBundle("locale", userLocale);
ResourceBundle rb = ResourceBundle.getBundle("locale", userLocale);
loader.setResources(rb);
Parent root = loader.load();

View File

@ -17,7 +17,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.SVGPath?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="nsusbloader.Controllers.NSLMainController">
<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">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>