1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use gtk::prelude::ToVariant;
pub trait ActionGroupName {
fn group_name() -> &'static str;
}
pub trait EmptyType {}
impl EmptyType for () {}
pub trait ActionName {
type Group: ActionGroupName;
type Target;
type State;
fn name() -> &'static str;
fn action_name() -> String {
format!("{}.{}", Self::Group::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);
}
}