Skip to content

Implemented multiple selection for gtk backend #2081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2021

Conversation

Psykopear
Copy link
Contributor

@Psykopear Psykopear commented Dec 7, 2021

As noted in #1067 the multiple selection is not actually implemented in the backends.
This PR implements the multiple selection dialog for the GTK backend.

I think I might have broken other backends, but I'm opening a PR so we can discuss if this is the right solution and if needed implement it for other platforms.

The CI passed, so I suppose I didn't breake other backends

format: None,
// If result is an error, return an empty vector,
// otherwise return a vec of FileInfos
.map_or(vec![], |f| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the same behavior as before, but it does seem like the errors from get_file_dialog_path should get logged, at least...

Copy link
Contributor Author

@Psykopear Psykopear Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll add a log here

@@ -80,6 +80,8 @@ struct DialogInfo {
id: WindowId,
/// The command to send if the dialog is accepted.
accept_cmd: Selector<FileInfo>,
/// The command to send if the dialog is accepted with multiple files.
accept_multiple_cmd: Option<Selector<Vec<FileInfo>>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary for this to be an Option? I mean, I see that it's not used for save dialogs, but then save dialogs shouldn't get configured for multi-selection anyway...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't an Option in my first implementation, I made it so to avoid having the field in save dialogs as you noticed.
If you think this isn't a problem though, having it always set makes the code nicer elsewhere, so I'm going to change this.

@Psykopear Psykopear requested a review from jneem December 8, 2021 21:32
filenames if filenames.is_empty() => Err(anyhow!("No path received for filename")),
// This really shouldn't happen, unless there is a bug
// when setting the dialog options
filenames if filenames.len() > 1 && !options.multi_selection => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last corner case that I noticed because of the unwrap below: if they pass FileDialogType::Save and options.multi_selection = true (which they shouldn't but I don't think we prevent it), then we correctly handle that combination on line 62 (by ignoring multi selection) but we don't check here that we only got one file back. Ok, maybe that's a bit paranoid, but I don't think it's any more paranoid than the existing checks that we have here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you mean:

if they pass FileDialogType::Save and options.multi_selection = true, then we correctly handle that combination on line 62 but we don't check here that we only got one file back

We do check that the we only got one file back (filenames.is_empty and filenames.len() > 1), and return an Err if that is not true.

Do you mean that since we ignored the option in the case of a Save dialog, we should not return an error, but the whole filenames vec (essentially avoid this check)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was: in the case of a Save dialog, we should return an error if there's more than one filename, even if options.multi_selection is true. (This is what the unwrap at line 945 assumes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, so instead of checking for && !options.multi_selection we should do:

            filenames if filenames.len() > 1 && action == FileChooserAction::Save => {

to uphold what we write later in the other comment, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you will need to check both the action and options.multi_selection because we still need to handle the case of open dialogs that expect a single file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixing it now

@@ -927,7 +940,9 @@ impl WindowState {
)
.ok()
.map(|s| FileInfo {
path: s.into(),
// `get_file_dialog_path` should make sure one and only one
// file is passed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be confident here :) "get_file_dialog_path guarantees that save dialogs only return one path", or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm going to change the comment

@jneem jneem merged commit 2f5beb8 into linebender:master Dec 12, 2021
@jneem
Copy link
Collaborator

jneem commented Dec 12, 2021

Thanks!

@Psykopear
Copy link
Contributor Author

Thanks!

Thank you for the review :)

@Psykopear Psykopear deleted the multiple-selection branch December 13, 2021 09:48
restitux pushed a commit to restitux/druid that referenced this pull request Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants