FileSelector needs to update the value after selecting a file (#2095)

* FileSelector needs to update the value after selecting a file

* update
This commit is contained in:
Glavo 2023-02-11 00:14:51 +08:00 committed by GitHub
parent 5ba8bdad10
commit ae3e135e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,7 @@ import java.io.File;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class FileSelector extends HBox { public class FileSelector extends HBox {
private StringProperty value = new SimpleStringProperty(); private final StringProperty value = new SimpleStringProperty();
private String chooserTitle = i18n("selector.choose_file"); private String chooserTitle = i18n("selector.choose_file");
private boolean directory = false; private boolean directory = false;
private final ObservableList<FileChooser.ExtensionFilter> extensionFilters = FXCollections.observableArrayList(); private final ObservableList<FileChooser.ExtensionFilter> extensionFilters = FXCollections.observableArrayList();
@ -87,15 +87,21 @@ public class FileSelector extends HBox {
DirectoryChooser chooser = new DirectoryChooser(); DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle(chooserTitle); chooser.setTitle(chooserTitle);
File dir = chooser.showDialog(Controllers.getStage()); File dir = chooser.showDialog(Controllers.getStage());
if (dir != null) if (dir != null) {
customField.setText(dir.getAbsolutePath()); String path = dir.getAbsolutePath();
customField.setText(path);
value.setValue(path);
}
} else { } else {
FileChooser chooser = new FileChooser(); FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(getExtensionFilters()); chooser.getExtensionFilters().addAll(getExtensionFilters());
chooser.setTitle(chooserTitle); chooser.setTitle(chooserTitle);
File file = chooser.showOpenDialog(Controllers.getStage()); File file = chooser.showOpenDialog(Controllers.getStage());
if (file != null) if (file != null) {
customField.setText(file.getAbsolutePath()); String path = file.getAbsolutePath();
customField.setText(path);
value.setValue(path);
}
} }
}); });