-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod.rs
130 lines (116 loc) · 3.18 KB
/
mod.rs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#[derive(PartialEq, Eq, Hash)]
pub enum DocAction {
MergeMode,
}
#[derive(PartialEq, Eq, Hash)]
pub enum ViewModeAction {
Close,
Save,
SaveAs,
MergeFile,
ChangePassword,
Find,
Add(String),
}
#[derive(PartialEq, Eq, Hash)]
pub enum MergeModeAction {
UncheckAll,
Merge,
}
#[derive(PartialEq, Eq, Hash)]
pub enum RecordAction {
CopyName,
CopyPassword,
Edit,
Delete,
ConvertTo(String),
}
#[derive(PartialEq, Eq, Hash)]
pub enum PSActionGroup {
Doc,
ViewMode,
MergeMode,
Record,
}
#[derive(PartialEq, Eq, Hash)]
pub enum PSAction {
Doc(DocAction),
ViewMode(ViewModeAction),
MergeMode(MergeModeAction),
Record(RecordAction),
}
// impl
impl DocAction {
pub fn name(&self) -> String {
match *self {
DocAction::MergeMode => "merge-mode",
}
.to_string()
}
}
impl ViewModeAction {
pub fn name(&self) -> String {
match *self {
ViewModeAction::Close => "close".to_string(),
ViewModeAction::Save => "save".to_string(),
ViewModeAction::SaveAs => "save-as".to_string(),
ViewModeAction::MergeFile => "merge-file".to_string(),
ViewModeAction::ChangePassword => "change-password".to_string(),
ViewModeAction::Find => "find".to_string(),
ViewModeAction::Add(ref record_type) => format!("add-{}", record_type),
}
}
}
impl MergeModeAction {
pub fn name(&self) -> String {
match *self {
MergeModeAction::UncheckAll => "uncheck-all",
MergeModeAction::Merge => "merge",
}
.to_string()
}
}
impl RecordAction {
pub fn name(&self) -> String {
match *self {
RecordAction::CopyName => "copy-name".to_string(),
RecordAction::CopyPassword => "copy-password".to_string(),
RecordAction::Edit => "edit".to_string(),
RecordAction::Delete => "delete".to_string(),
RecordAction::ConvertTo(ref record_type) => format!("convert-to-{}", record_type),
}
}
}
impl PSActionGroup {
pub fn name(&self) -> &str {
match *self {
PSActionGroup::Doc => "doc",
PSActionGroup::ViewMode => "file",
PSActionGroup::MergeMode => "merge",
PSActionGroup::Record => "entry",
}
}
}
impl PSAction {
pub fn group(&self) -> PSActionGroup {
match *self {
PSAction::Doc(_) => PSActionGroup::Doc,
PSAction::ViewMode(_) => PSActionGroup::ViewMode,
PSAction::MergeMode(_) => PSActionGroup::MergeMode,
PSAction::Record(_) => PSActionGroup::Record,
}
}
pub fn name(&self) -> (String, String) {
let action_name = match *self {
PSAction::Doc(ref action) => action.name(),
PSAction::ViewMode(ref action) => action.name(),
PSAction::MergeMode(ref action) => action.name(),
PSAction::Record(ref action) => action.name(),
};
(self.group().name().to_string(), action_name)
}
pub fn full_name(&self) -> String {
let action_name = self.name();
format!("{}.{}", action_name.0, action_name.1)
}
}