use std::path::PathBuf;
use std::sync::Mutex;
#[derive(Clone, Debug)]
pub enum DropEvent {
Hovered(Vec<PathBuf>),
Dropped(Vec<PathBuf>),
Cancelled,
}
type DropCallback = Box<dyn Fn(DropEvent) + Send + Sync>;
static DROP_HANDLER: Mutex<Option<DropCallback>> = Mutex::new(None);
pub fn on_file_drop<F>(callback: F)
where
F: Fn(DropEvent) + Send + Sync + 'static,
{
*DROP_HANDLER.lock().unwrap() = Some(Box::new(callback));
}
pub fn clear_file_drop_handler() {
*DROP_HANDLER.lock().unwrap() = None;
}
pub(crate) fn dispatch_drop_event(event: DropEvent) {
if let Ok(guard) = DROP_HANDLER.lock() {
if let Some(ref handler) = *guard {
handler(event);
}
}
}