1010import javafx .application .Platform ;
1111import javafx .event .ActionEvent ;
1212import javafx .fxml .FXML ;
13- import javafx .scene .control .Button ;
14- import javafx .scene .control .ComboBox ;
15- import javafx .scene .control .Label ;
16- import javafx .scene .control .TextField ;
13+ import javafx .scene .control .*;
1714import javafx .stage .Stage ;
1815import org .kordamp .ikonli .javafx .FontIcon ;
1916
2926
3027public class SingleDownload implements QueueObserver {
3128
29+ @ FXML
30+ private CheckBox lastLocationCheck ;
3231 @ FXML
3332 private Label sizeLabel , resumableLabel , errorLabel ;
3433 @ FXML
@@ -78,6 +77,7 @@ public void initialize(URL location, ResourceBundle resources) {
7877 refreshBtn .setGraphic (new FontIcon ());
7978 refreshBtn .setDisable (true );
8079 refreshBtn .setVisible (false );
80+ lastLocationCheck .setDisable (true );
8181 refreshBtn .setOnAction (e -> {
8282 refreshBtn .setDisable (true );
8383 refreshBtn .setVisible (false );
@@ -162,14 +162,14 @@ private void autoFillLocationAndSizeAndName() {
162162 var connection = DownloadUtils .connect (url );
163163 var executor = Executors .newVirtualThreadPerTaskExecutor ();
164164 var fileNameLocationFuture =
165- DownloadUtils .prepareFileNameAndFieldsAsync (connection , url , nameField , executor )
165+ DownloadUtils .prepareFileNameAndFieldsAsync (connection , url , nameField , dm , executor )
166166 .thenAccept (this ::setLocation );
167167 var sizeFuture = DownloadUtils .prepareFileSizeAndFieldsAsync (connection ,
168168 urlField , sizeLabel , resumableLabel , speedField , chunksField , bytesField , dm , executor );
169169 CompletableFuture .allOf (fileNameLocationFuture , sizeFuture )
170170 .whenComplete ((unused , throwable ) -> {
171171 DownloadUtils .handleError (() -> DownloadUtils .checkIfFileIsOKToSave (locationField .getText (),
172- nameField .getText (), downloadBtn , addBtn , refreshBtn ), errorLabel );
172+ nameField .getText (), downloadBtn , addBtn , refreshBtn , lastLocationCheck ), errorLabel );
173173 executor .shutdown ();
174174 })
175175 .exceptionally (throwable -> {
@@ -195,7 +195,15 @@ private void onSelectLocation(ActionEvent e) {
195195 if (path != null )
196196 locationField .setText (path );
197197 DownloadUtils .handleError (() -> DownloadUtils .checkIfFileIsOKToSave (locationField .getText (),
198- nameField .getText (), downloadBtn , addBtn , refreshBtn ), errorLabel );
198+ nameField .getText (), downloadBtn , addBtn , refreshBtn , lastLocationCheck ), errorLabel );
199+ }
200+
201+ @ FXML
202+ private void onLastLocationCheck () {
203+ if (lastLocationCheck .isSelected ())
204+ locationField .setText (AppConfigs .lastSavedDir );
205+ else
206+ setLocation (dm .getName ());
199207 }
200208
201209 @ FXML
@@ -314,7 +322,7 @@ private void onQueueChanged() {
314322
315323 private void onOfflineFieldsChanged () {
316324 DownloadUtils .handleError (() -> DownloadUtils .onOfflineFieldsChanged (locationField , nameField .getText (), dm , queueCombo ,
317- downloadBtn , addBtn , openLocation , refreshBtn ), errorLabel );
325+ downloadBtn , addBtn , openLocation , refreshBtn , lastLocationCheck ), errorLabel );
318326 }
319327
320328
@@ -323,4 +331,5 @@ public void setUrlModel(SingleURLModel urlModel) {
323331 initAfterUrlModel ();
324332 }
325333
334+
326335}
0 commit comments