Skip to content

Commit

Permalink
Fix GTK folder selection with filters. (linebender#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom authored and covercash2 committed Jun 12, 2020
1 parent 863da27 commit 22edb63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ You can find its changes [documented below](#060---2020-06-01).

### Fixed

- GTK: Directory selection now properly ignores file filters. ([#957] by [@xStrom])

### Visual

- `TextBox` stroke remains inside its `paint_rect`. ([#1007] by [@jneem])
Expand Down Expand Up @@ -296,6 +298,7 @@ Last release without a changelog :(
[#951]: https://github.com/xi-editor/druid/pull/951
[#953]: https://github.com/xi-editor/druid/pull/953
[#954]: https://github.com/xi-editor/druid/pull/954
[#957]: https://github.com/xi-editor/druid/pull/957
[#959]: https://github.com/xi-editor/druid/pull/959
[#961]: https://github.com/xi-editor/druid/pull/961
[#963]: https://github.com/xi-editor/druid/pull/963
Expand Down
50 changes: 25 additions & 25 deletions druid-shell/src/platform/gtk/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,35 @@ pub(crate) fn get_file_dialog_path(

dialog.set_show_hidden(options.show_hidden);

dialog.set_select_multiple(options.multi_selection);

let mut found_default_filter = false;
if let Some(file_types) = &options.allowed_types {
for f in file_types {
let filter = file_filter(f);
dialog.add_filter(&filter);

if let Some(default) = &options.default_type {
if default == f {
// Note that we're providing the same FileFilter object to
// add_filter and set_filter, because gtk checks them for
// identity, not structural equality.
dialog.set_filter(&filter);
found_default_filter = true;
if action != FileChooserAction::Save {
dialog.set_select_multiple(options.multi_selection);
}

// Don't set the filters when showing the folder selection dialog,
// because then folder traversing won't work.
if action != FileChooserAction::SelectFolder {
let mut found_default_filter = false;
if let Some(file_types) = &options.allowed_types {
for f in file_types {
let filter = file_filter(f);
dialog.add_filter(&filter);

if let Some(default) = &options.default_type {
if default == f {
// Note that we're providing the same FileFilter object to
// add_filter and set_filter, because gtk checks them for
// identity, not structural equality.
dialog.set_filter(&filter);
found_default_filter = true;
}
}
}
}
}

if let Some(default_file_type) = &options.default_type {
if options.allowed_types.is_some() && !found_default_filter {
// It's ok to set a default file filter without providing a list of
// allowed filters, but it's not ok (or at least, doesn't work in gtk)
// to provide a default filter that isn't in the (present) list
// of allowed filters.
log::warn!("default file type not found in allowed types");
} else if !found_default_filter {
dialog.set_filter(&file_filter(default_file_type));
if let Some(dt) = &options.default_type {
if !found_default_filter {
log::warn!("The default type {:?} is not present in allowed types.", dt);
}
}
}

Expand Down

0 comments on commit 22edb63

Please sign in to comment.