Skip to content
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

Extension filter and default filename for save dialog #138

Open
David-OConnor opened this issue Aug 10, 2024 · 2 comments
Open

Extension filter and default filename for save dialog #138

David-OConnor opened this issue Aug 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@David-OConnor
Copy link

David-OConnor commented Aug 10, 2024

Hi! This library is awesome (including compared to other EGUI file dialogs I've seen).

I notice that the save dialog looks like this:
image

Is there a way to A: Give it a default filename and extension, and B: Offer an extension filter/automatic extension if not entered, like in open, and system file dialogs? Thank you!

Example of desired behavior, from a system dialog:
image

@fluxxcode
Copy link
Owner

Hi, you can use FileDialog::default_file_name to set the default name of the file when saving.

Point B is not yet implemented. But I think it's a good idea. I'll mark the ticket as an enhancement. But I don't have time to implement the feature in the next few weeks.

@fluxxcode fluxxcode added the enhancement New feature or request label Aug 10, 2024
@David-OConnor
Copy link
Author

David-OConnor commented Aug 10, 2024

Ty! That worked for A! I'll take a look as well re point B, although am not familiar with this codebase at this time.

edit: Is there a way to do A dynamically? I was able to get it to work when initializing, but is there a non-builder-pattern approach, or a way to use the builder pattern here? (This may be something I can easily PR A/R)

fn save_button(
    dialog: &mut FileDialog,
    ui: &mut Ui,
) {
    if ui.button(text).on_hover_text(hover_text).clicked() {
       // ...
        *dialog = dialog.default_file_name(&filename);
        dialog.save_file();
    }
}

Error:

*dialog = dialog.default_file_name(&filename);
   |       ^^^^^^ move occurs because `*dialog` has type `FileDialog`, which does not implement the `Copy` trait

I guess, something like dialog.set_default_name(&filename) would do it, where it mutates itself instead of returning a new copy. Or maybe there is a way to do that using the builder pattern. edit: PR in; verified working.

Edit: Resolved in the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants