fluxxcode / egui-file-dialog

Full featured and customizable file dialog for egui
MIT License
86 stars 11 forks source link

Implement persistent storage #104

Closed fluxxcode closed 6 months ago

fluxxcode commented 6 months ago

Implemented persistent storage with FileDialog::storage_mut to save and load the pinned folders.

This requires the new persistence feature, which implements serde::Serialize and serde::Deserialize for the objects to be saved.

Example:

struct MyApp {
    file_dialog: FileDialog,
}

impl MyApp {
    pub fn new(cc: &eframe::CreationContext) -> Self {
        let mut file_dialog = FileDialog::new();

        // Load the file dialog storage
        if let Some(storage) = cc.storage {
            *file_dialog.storage_mut() =
                 eframe::get_value(storage, "file_dialog_storage").unwrap_or_default()
        }

        Self {
            file_dialog,
        }
    }
}

impl eframe::App for MyApp {
    fn save(&mut self, storage: &mut dyn eframe::Storage) {
        // Save the file dialog storage
        eframe::set_value(storage, "file_dialog_storage", self.file_dialog.storage_mut());
    }

Ref: https://github.com/fluxxcode/egui-file-dialog/issues/42