Skip to content

Commit 22edb63

Browse files
xStromcovercash2
authored andcommitted
Fix GTK folder selection with filters. (linebender#957)
1 parent 863da27 commit 22edb63

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ You can find its changes [documented below](#060---2020-06-01).
1919

2020
### Fixed
2121

22+
- GTK: Directory selection now properly ignores file filters. ([#957] by [@xStrom])
23+
2224
### Visual
2325

2426
- `TextBox` stroke remains inside its `paint_rect`. ([#1007] by [@jneem])
@@ -296,6 +298,7 @@ Last release without a changelog :(
296298
[#951]: https://github.com/xi-editor/druid/pull/951
297299
[#953]: https://github.com/xi-editor/druid/pull/953
298300
[#954]: https://github.com/xi-editor/druid/pull/954
301+
[#957]: https://github.com/xi-editor/druid/pull/957
299302
[#959]: https://github.com/xi-editor/druid/pull/959
300303
[#961]: https://github.com/xi-editor/druid/pull/961
301304
[#963]: https://github.com/xi-editor/druid/pull/963

druid-shell/src/platform/gtk/dialog.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,35 @@ pub(crate) fn get_file_dialog_path(
5353

5454
dialog.set_show_hidden(options.show_hidden);
5555

56-
dialog.set_select_multiple(options.multi_selection);
57-
58-
let mut found_default_filter = false;
59-
if let Some(file_types) = &options.allowed_types {
60-
for f in file_types {
61-
let filter = file_filter(f);
62-
dialog.add_filter(&filter);
63-
64-
if let Some(default) = &options.default_type {
65-
if default == f {
66-
// Note that we're providing the same FileFilter object to
67-
// add_filter and set_filter, because gtk checks them for
68-
// identity, not structural equality.
69-
dialog.set_filter(&filter);
70-
found_default_filter = true;
56+
if action != FileChooserAction::Save {
57+
dialog.set_select_multiple(options.multi_selection);
58+
}
59+
60+
// Don't set the filters when showing the folder selection dialog,
61+
// because then folder traversing won't work.
62+
if action != FileChooserAction::SelectFolder {
63+
let mut found_default_filter = false;
64+
if let Some(file_types) = &options.allowed_types {
65+
for f in file_types {
66+
let filter = file_filter(f);
67+
dialog.add_filter(&filter);
68+
69+
if let Some(default) = &options.default_type {
70+
if default == f {
71+
// Note that we're providing the same FileFilter object to
72+
// add_filter and set_filter, because gtk checks them for
73+
// identity, not structural equality.
74+
dialog.set_filter(&filter);
75+
found_default_filter = true;
76+
}
7177
}
7278
}
7379
}
74-
}
7580

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

0 commit comments

Comments
 (0)