use super::{DialogBackend, DialogReply, DialogResult, FileDialog};
use std::sync::Arc;
#[derive(Default)]
pub struct MemoryDialogs {
opened: Vec<(FileDialog, DialogReply)>,
}
impl MemoryDialogs {
pub fn new() -> Self {
Self::default()
}
pub fn opened(&self) -> impl Iterator<Item = &FileDialog> {
self.opened.iter().map(|(dialog, _)| dialog)
}
pub fn pending(&self) -> usize {
self.opened
.iter()
.filter(|(_, reply)| !reply.is_answered())
.count()
}
pub fn answer(&mut self, result: DialogResult) -> bool {
self.opened
.iter()
.find(|(_, reply)| !reply.is_answered())
.is_some_and(|(_, reply)| reply.send(result))
}
}
impl DialogBackend for MemoryDialogs {
fn launch(
&mut self,
dialog: &FileDialog,
_parent: Option<&Arc<winit::window::Window>>,
reply: DialogReply,
) {
self.opened.push((dialog.clone(), reply));
}
}