use crate::action::ActionManager;
use crate::shortcut::Shortcut;
pub struct ActionRouter<'a> {
shortcut_mgr: &'a mut crate::shortcut::ShortcutManager,
action_mgr: &'a mut ActionManager,
}
impl<'a> ActionRouter<'a> {
pub fn new(
shortcut_mgr: &'a mut crate::shortcut::ShortcutManager,
action_mgr: &'a mut ActionManager,
) -> Self {
Self { shortcut_mgr, action_mgr }
}
pub fn connect(
&mut self,
action_id: impl Into<String>,
shortcut: Shortcut,
text: impl Into<String>,
) -> bool {
let action_id = action_id.into();
if !self.action_mgr.register_action(action_id.clone(), text) {
return false;
}
if !self.shortcut_mgr.register(action_id.clone(), shortcut.clone(), "") {
return false;
}
self.action_mgr.bind_shortcut_type(&shortcut, action_id)
}
pub fn bind_shortcut(&mut self, action_id: impl Into<String>, shortcut: Shortcut) -> bool {
let action_id = action_id.into();
if self.action_mgr.action(&action_id).is_none() {
return false;
}
if !self.shortcut_mgr.register(action_id.clone(), shortcut.clone(), "") {
return false;
}
self.action_mgr.bind_shortcut_type(&shortcut, action_id)
}
pub fn route_action_id(&mut self, action_id: &str) -> bool {
self.action_mgr.trigger_action(action_id)
}
}