fluxxcode / egui-file-dialog

Full featured and customizable file dialog for egui
MIT License
77 stars 10 forks source link

Extension filter and default filename for save dialog #138

Open David-OConnor opened 1 month ago

David-OConnor commented 1 month ago

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 commented 1 month ago

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.

David-OConnor commented 1 month ago

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