Barugon / egui_file

File dialog for egui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FileDialog::open resets FileDialog::default_filename

DannyStoll1 opened this issue · comments

It appears to me that the intended way to use FileDialog::default_filename is prior to calling FileDialog::open, e.g. as follows:

let mut dialog = FileDialog::save_file(None)
    .default_filename("config.toml");
dialog.open();

Unfortunately, since dialog.open() calls dialog.refresh(), which in turn calls dialog.select(None), the above resets the default filename. This can be worked around by setting the default filename after opening the dialog, but the type signatures make this rather non-ergonomic.

I propose modifying FileDialog::select so that filename_edit is not modified if the input is None:

  fn select(&mut self, file: Option<FileInfo>) {
    if let Some(info) = &file {
      self.filename_edit = get_file_name(info).to_owned();
    }
    self.selected_file = file;
  }