Add file filtering to gtk dialogs.#903
Add file filtering to gtk dialogs.#903xStrom merged 3 commits intolinebender:masterfrom jneem:gtk-dialog
Conversation
xStrom
left a comment
There was a problem hiding this comment.
Generally looks good, just a few things. Also, please add a changelog entry.
druid/examples/open_save.rs
Outdated
| .allowed_types(vec![txt, other]) | ||
| .default_type(txt); |
There was a problem hiding this comment.
Let's reverse the vector to [other, txt] so that this sample can show the default type working. Does it work for you? On my Ubuntu 19.10 it doesn't seem to actually choose the text file if other is first in the vector.
There was a problem hiding this comment.
Indeed, it wasn't working with the other order. I've added some extra checks in dialog.rs, and now all the combinations I've tried seem to work.
| // 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"); |
There was a problem hiding this comment.
This warning should be removed, because there is an explictly documented behavior for this case.
If it's None or not present in allowed_types then the first entry in allowed_types will be used as default.
There was a problem hiding this comment.
But it seems unreasonable for the user to provide a default that is not even available.
If this happens, it most definitely seems to be an accident and should log a warning (on all platforms), at least I think so.
There was a problem hiding this comment.
I guess that's reasonable. We can keep the warning then.
There was a problem hiding this comment.
Note that (and I can change this if it isn't desired druid behavior), if allowed_types is empty then the default type is allowed to be present: it applies a filter that cannot be changed.
There was a problem hiding this comment.
Just to be clear, my previous comment is about gtk's behavior.
There was a problem hiding this comment.
So if I interpret that code correctly, on Windows Some(default_type) is ignored if allowed_types is None. On mac the default type seems to be ignored all together.
I'm not sure what the 'correct' behavior would be (at least not the mac one).
Maybe we should allow having default be Some while allowed is None?
Fixes GTK part of #390.