61 lines
2.2 KiB
Java
61 lines
2.2 KiB
Java
package envoy.client.ui.settings;
|
|
|
|
import javafx.geometry.Insets;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.stage.DirectoryChooser;
|
|
|
|
import envoy.client.data.Context;
|
|
|
|
/**
|
|
* Displays options for downloading {@link envoy.data.Attachment}s.
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public final class DownloadSettingsPane extends SettingsPane {
|
|
|
|
/**
|
|
* Constructs a new {@code DownloadSettingsPane}.
|
|
*
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public DownloadSettingsPane() {
|
|
super("Download");
|
|
setSpacing(15);
|
|
setPadding(new Insets(15));
|
|
|
|
// Checkbox to disable asking
|
|
final var checkBox = new CheckBox(settings.getItems().get("autoSaveDownloads").getUserFriendlyName());
|
|
checkBox.setSelected(settings.isDownloadSavedWithoutAsking());
|
|
checkBox.setTooltip(new Tooltip("Determines whether a \"Select save location\" - dialogue will be shown when saving attachments."));
|
|
checkBox.setOnAction(e -> settings.setDownloadSavedWithoutAsking(checkBox.isSelected()));
|
|
getChildren().add(checkBox);
|
|
|
|
// Displaying the default path to save to
|
|
final var pathLabel = new Label(settings.getItems().get("downloadLocation").getDescription() + ":");
|
|
pathLabel.setWrapText(true);
|
|
getChildren().add(pathLabel);
|
|
final var hbox = new HBox(20);
|
|
Tooltip.install(hbox, new Tooltip("Determines the location where attachments will be saved to."));
|
|
final var currentPath = new Label(settings.getDownloadLocation().getAbsolutePath());
|
|
hbox.getChildren().add(currentPath);
|
|
|
|
// Setting the default path
|
|
final var button = new Button("Select");
|
|
button.setOnAction(e -> {
|
|
final var directoryChooser = new DirectoryChooser();
|
|
directoryChooser.setTitle("Select the directory where attachments should be saved to");
|
|
directoryChooser.setInitialDirectory(settings.getDownloadLocation());
|
|
final var selectedDirectory = directoryChooser.showDialog(Context.getInstance().getSceneContext().getStage());
|
|
|
|
if (selectedDirectory != null) {
|
|
currentPath.setText(selectedDirectory.getAbsolutePath());
|
|
settings.setDownloadLocation(selectedDirectory);
|
|
}
|
|
});
|
|
hbox.getChildren().add(button);
|
|
getChildren().add(hbox);
|
|
}
|
|
}
|