use std::collections::HashMap;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Action(pub &'static str);
#[macro_export]
macro_rules! actions {
($($name:ident = $id:literal $(=> $label:literal)?;)*) => {
$( pub const $name: $crate::core::Action = $crate::core::Action($id); )*
pub const ALL: &[$crate::core::Action] = &[$($name,)*];
pub const PALETTE: &[(&str, $crate::core::Action)] = &[$($(($label, $name),)?)*];
};
}
pub use crate::actions;
#[derive(Default)]
pub struct ActionRegistry {
bindings: HashMap<String, Action>,
}
impl ActionRegistry {
pub fn bind(&mut self, keystroke: impl Into<String>, action: Action) {
self.bindings.insert(keystroke.into(), action);
}
pub fn resolve(&self, keystroke: &str) -> Option<Action> {
self.bindings.get(keystroke).copied()
}
}