forked from j62/ctbrec
1
0
Fork 0

Fix: allow empty input / deletion of post-processing script

This commit is contained in:
0xboobface 2018-12-16 20:29:48 +01:00
parent d74737113a
commit 910d21463a
4 changed files with 44 additions and 27 deletions

View File

@ -6,9 +6,10 @@ import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.StringUtil;
import ctbrec.ui.AutosizeAlert;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ObjectPropertyBase;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Point2D;
import javafx.scene.Node;
@ -29,18 +30,20 @@ import javafx.stage.FileChooser;
public abstract class AbstractFileSelectionBox extends HBox {
private static final transient Logger LOG = LoggerFactory.getLogger(AbstractFileSelectionBox.class);
private ObjectProperty<File> fileProperty = new ObjectPropertyBase<File>() {
@Override
public Object getBean() {
return null;
}
@Override
public String getName() {
return "file";
}
};
// private ObjectProperty<File> fileProperty = new ObjectPropertyBase<File>() {
// @Override
// public Object getBean() {
// return null;
// }
//
// @Override
// public String getName() {
// return "file";
// }
// };
private StringProperty fileProperty = new SimpleStringProperty();
protected TextField fileInput;
protected boolean allowEmptyValue = false;
private Tooltip validationError = new Tooltip();
public AbstractFileSelectionBox() {
@ -67,8 +70,14 @@ public abstract class AbstractFileSelectionBox extends HBox {
private ChangeListener<? super String> textListener() {
return (obs, o, n) -> {
String input = fileInput.getText();
File program = new File(input);
setFile(program);
if(StringUtil.isBlank(input) && allowEmptyValue) {
fileProperty.set("");
hideValidationHints();
return;
} else {
File program = new File(input);
setFile(program);
}
};
}
@ -83,13 +92,17 @@ public abstract class AbstractFileSelectionBox extends HBox {
validationError.show(getScene().getWindow(), p.getX(), p.getY() + fileInput.getHeight() + 4);
}
} else {
fileInput.setBorder(Border.EMPTY);
fileInput.setTooltip(null);
fileProperty.set(file);
validationError.hide();
fileProperty.set(file.getAbsolutePath());
hideValidationHints();
}
}
private void hideValidationHints() {
fileInput.setBorder(Border.EMPTY);
fileInput.setTooltip(null);
validationError.hide();
}
protected String validate(File file) {
if (file == null || !file.exists()) {
return "File does not exist";
@ -98,6 +111,10 @@ public abstract class AbstractFileSelectionBox extends HBox {
}
}
public void allowEmptyValue() {
this.allowEmptyValue = true;
}
private Button createBrowseButton() {
Button button = new Button("Select");
button.setOnAction((e) -> {
@ -123,7 +140,7 @@ public abstract class AbstractFileSelectionBox extends HBox {
}
}
public ObjectProperty<File> fileProperty() {
public StringProperty fileProperty() {
return fileProperty;
}
}

View File

@ -12,7 +12,7 @@ public class DirectorySelectionBox extends AbstractFileSelectionBox {
@Override
protected void choose() {
DirectoryChooser chooser = new DirectoryChooser();
File currentDir = fileProperty().get();
File currentDir = new File(fileProperty().get());
if (currentDir.exists() && currentDir.isDirectory()) {
chooser.setInitialDirectory(currentDir);
}

View File

@ -173,7 +173,7 @@ public class ActionSettingsPanel extends TitledPane {
if(playSound.isSelected()) {
ActionConfiguration ac = new ActionConfiguration();
ac.setType(PlaySound.class.getName());
File file = sound.fileProperty().get();
File file = new File(sound.fileProperty().get());
ac.getConfiguration().put("file", file.getAbsolutePath());
ac.setName("play " + file.getName());
config.getActions().add(ac);
@ -181,7 +181,7 @@ public class ActionSettingsPanel extends TitledPane {
if(executeProgram.isSelected()) {
ActionConfiguration ac = new ActionConfiguration();
ac.setType(ExecuteProgram.class.getName());
File file = program.fileProperty().get();
File file = new File(program.fileProperty().get());
ac.getConfiguration().put("file", file.getAbsolutePath());
ac.setName("execute " + file.getName());
config.getActions().add(ac);

View File

@ -238,7 +238,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
recordingsDirectory = new DirectorySelectionBox(Config.getInstance().getSettings().recordingsDir);
recordingsDirectory.prefWidth(400);
recordingsDirectory.fileProperty().addListener((obs, o, n) -> {
String path = n.getAbsolutePath();
String path = n;
if(!Objects.equals(path, Config.getInstance().getSettings().recordingsDir)) {
Config.getInstance().getSettings().recordingsDir = path;
saveConfig();
@ -310,10 +310,10 @@ public class SettingsTab extends Tab implements TabSelectionListener {
GridPane.setMargin(maxResolution, new Insets(0, 0, 0, CHECKBOX_MARGIN));
layout.add(new Label("Post-Processing"), 0, row);
// TODO allow empty strings to remove post-processing scripts
postProcessing = new ProgramSelectionBox(Config.getInstance().getSettings().postProcessing);
postProcessing.allowEmptyValue();
postProcessing.fileProperty().addListener((obs, o, n) -> {
String path = n.getAbsolutePath();
String path = n;
if(!Objects.equals(path, Config.getInstance().getSettings().postProcessing)) {
Config.getInstance().getSettings().postProcessing = path;
saveConfig();
@ -395,7 +395,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
layout.add(new Label("Player"), 0, row);
mediaPlayer = new ProgramSelectionBox(Config.getInstance().getSettings().mediaPlayer);
mediaPlayer.fileProperty().addListener((obs, o, n) -> {
String path = n.getAbsolutePath();
String path = n;
if (!Objects.equals(path, Config.getInstance().getSettings().mediaPlayer)) {
Config.getInstance().getSettings().mediaPlayer = path;
saveConfig();