1use gtk::prelude::ToVariant;
2
3pub trait ActionGroupName {
5 const NAME: &'static str;
7}
8
9pub trait EmptyType {}
11
12impl EmptyType for () {}
13
14pub trait ActionName {
16 type Group: ActionGroupName;
18
19 type Target;
23
24 type State;
28
29 const NAME: &'static str;
31
32 #[must_use]
34 fn action_name() -> String {
35 format!("{}.{}", Self::Group::NAME, Self::NAME)
36 }
37}
38
39pub trait ActionablePlus {
41 fn set_action<A: ActionName>(&self, value: A::Target)
43 where
44 A::Target: ToVariant;
45
46 fn set_stateless_action<A: ActionName>(&self, unit_type: &())
48 where
49 A::Target: EmptyType;
50}
51
52impl<W: gtk::prelude::ActionableExt> ActionablePlus for W {
53 fn set_action<A: ActionName>(&self, value: A::Target)
54 where
55 A::Target: ToVariant,
56 {
57 self.set_action_name(Some(A::action_name().as_str()));
58 self.set_action_target_value(Some(&value.to_variant()));
59 }
60
61 fn set_stateless_action<A: ActionName>(&self, _unit_type: &())
62 where
63 A::Target: EmptyType,
64 {
65 self.set_action_name(Some(A::action_name().as_str()));
66 }
67}
68
69pub trait AccelsPlus {
71 fn set_accelerators_for_action<A: ActionName>(&self, value: &[&str])
73 where
74 A::Target: EmptyType;
75}
76
77impl<W: gtk::prelude::GtkApplicationExt> AccelsPlus for W {
78 fn set_accelerators_for_action<A: ActionName>(&self, accel_codes: &[&str])
79 where
80 A::Target: EmptyType,
81 {
82 self.set_accels_for_action(A::action_name().as_str(), accel_codes);
83 }
84}