Skip to content

Commit

Permalink
Try to mimic the native behaviour for the WebFileSavePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
besidev committed Nov 19, 2024
1 parent 7787760 commit 06816a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public final void setSelectedExtensionFilter(final ExtensionFilter filter) {
selectedExtensionFilterProperty().setValue(filter);
}

final ExtensionFilter findSelectedFilter() {
ExtensionFilter selectedFilter = getSelectedExtensionFilter();
if (selectedFilter == null || !extensionFilters.contains(selectedFilter)) {
return extensionFilters.isEmpty() ? null : extensionFilters.get(0);
} else {
return selectedFilter;
}
}

final void synchronizeSelectedExtensionFilter(FileChooser fileChooser) {
fileChooser.selectedExtensionFilterProperty()
.addListener(new WeakChangeListener<>(getNativeSelectedExtensionFilterChangeListener()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public final ObjectProperty<ExtensionFilter> selectedExtensionFilterProperty() {
@Override
final void showDialog() {
final String fileName = getInitialFileName() == null ? "filename" : getInitialFileName();
final ExtensionFilter fileExtension = getSelectedExtensionFilter();
final String fileType = fileExtension == null ? "" : fileExtension.extensions().get(0);
final ExtensionFilter extensionFilter = findSelectedFilter();
final String fileType = extensionFilter == null ? "" : extensionFilter.extensions().get(0);
final Function<File, CompletableFuture<Void>> onFileSelected = getOnFileSelected();
if (onFileSelected != null) {
try {
Expand Down

0 comments on commit 06816a1

Please sign in to comment.