use gtk::prelude::ToVariant;
pub trait ActionGroupName {
const NAME: &'static str;
}
pub trait EmptyType {}
impl EmptyType for () {}
pub trait ActionName {
type Group: ActionGroupName;
type Target;
type State;
const NAME: &'static str;
#[must_use]
fn action_name() -> String {
format!("{}.{}", Self::Group::NAME, Self::NAME)
}
}
pub trait ActionablePlus {
fn set_action<A: ActionName>(&self, value: A::Target)
where
A::Target: ToVariant;
fn set_stateless_action<A: ActionName>(&self, unit_type: &())
where
A::Target: EmptyType;
}
impl<W: gtk::prelude::ActionableExt> ActionablePlus for W {
fn set_action<A: ActionName>(&self, value: A::Target)
where
A::Target: ToVariant,
{
self.set_action_name(Some(A::action_name().as_str()));
self.set_action_target_value(Some(&value.to_variant()));
}
fn set_stateless_action<A: ActionName>(&self, _unit_type: &())
where
A::Target: EmptyType,
{
self.set_action_name(Some(A::action_name().as_str()));
}
}
pub trait AccelsPlus {
fn set_accelerators_for_action<A: ActionName>(&self, value: &[&str])
where
A::Target: EmptyType;
}
impl<W: gtk::prelude::GtkApplicationExt> AccelsPlus for W {
fn set_accelerators_for_action<A: ActionName>(&self, accel_codes: &[&str])
where
A::Target: EmptyType,
{
self.set_accels_for_action(A::action_name().as_str(), accel_codes);
}
}