reovim_plugin_settings_menu/
commands.rs1use reovim_core::{
4 command::traits::*,
5 declare_event_command,
6 event_bus::{DynEvent, Event},
7};
8
9#[derive(Debug, Clone, Copy, Default)]
16pub struct SettingsMenuOpen;
17
18impl CommandTrait for SettingsMenuOpen {
19 fn name(&self) -> &'static str {
20 "settings_menu_open"
21 }
22
23 fn description(&self) -> &'static str {
24 "Open the settings menu"
25 }
26
27 fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
28 CommandResult::EmitEvent(DynEvent::new(*self))
29 }
30
31 fn clone_box(&self) -> Box<dyn CommandTrait> {
32 Box::new(*self)
33 }
34
35 fn as_any(&self) -> &dyn std::any::Any {
36 self
37 }
38}
39
40impl Event for SettingsMenuOpen {
41 fn priority(&self) -> u32 {
42 50 }
44}
45
46#[derive(Debug, Clone, Copy, Default)]
48pub struct SettingsMenuClose;
49
50impl CommandTrait for SettingsMenuClose {
51 fn name(&self) -> &'static str {
52 "settings_menu_close"
53 }
54
55 fn description(&self) -> &'static str {
56 "Close the settings menu"
57 }
58
59 fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
60 CommandResult::EmitEvent(DynEvent::new(*self))
61 }
62
63 fn clone_box(&self) -> Box<dyn CommandTrait> {
64 Box::new(*self)
65 }
66
67 fn as_any(&self) -> &dyn std::any::Any {
68 self
69 }
70}
71
72impl Event for SettingsMenuClose {
73 fn priority(&self) -> u32 {
74 50 }
76}
77
78declare_event_command! {
79 SettingsMenuSelectNext,
80 id: "settings_menu_next",
81 description: "Select next item in settings menu",
82}
83
84declare_event_command! {
85 SettingsMenuSelectPrev,
86 id: "settings_menu_prev",
87 description: "Select previous item in settings menu",
88}
89
90declare_event_command! {
93 SettingsMenuToggle,
94 id: "settings_menu_toggle",
95 description: "Toggle current boolean setting",
96}
97
98declare_event_command! {
99 SettingsMenuCycleNext,
100 id: "settings_menu_cycle_next",
101 description: "Cycle to next choice option",
102}
103
104declare_event_command! {
105 SettingsMenuCyclePrev,
106 id: "settings_menu_cycle_prev",
107 description: "Cycle to previous choice option",
108}
109
110declare_event_command! {
111 SettingsMenuIncrement,
112 id: "settings_menu_increment",
113 description: "Increment current number setting",
114}
115
116declare_event_command! {
117 SettingsMenuDecrement,
118 id: "settings_menu_decrement",
119 description: "Decrement current number setting",
120}
121
122declare_event_command! {
123 SettingsMenuExecuteAction,
124 id: "settings_menu_execute",
125 description: "Execute current action item",
126}
127
128#[derive(Debug, Clone, Copy)]
132pub struct SettingsMenuQuickSelect {
133 pub number: u8,
135}
136
137impl SettingsMenuQuickSelect {
138 #[must_use]
140 pub const fn new(number: u8) -> Self {
141 Self { number }
142 }
143}
144
145impl CommandTrait for SettingsMenuQuickSelect {
146 fn name(&self) -> &'static str {
147 "settings_menu_quick_select"
148 }
149
150 fn description(&self) -> &'static str {
151 "Quick select option by number"
152 }
153
154 fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
155 CommandResult::EmitEvent(DynEvent::new(*self))
156 }
157
158 fn clone_box(&self) -> Box<dyn CommandTrait> {
159 Box::new(*self)
160 }
161
162 fn as_any(&self) -> &dyn std::any::Any {
163 self
164 }
165}
166
167impl Event for SettingsMenuQuickSelect {
168 fn priority(&self) -> u32 {
169 100
170 }
171}
172
173macro_rules! quick_select_command {
177 ($name:ident, $num:literal, $cmd_name:literal) => {
178 #[derive(Debug, Clone, Copy)]
179 pub struct $name;
180
181 impl CommandTrait for $name {
182 fn name(&self) -> &'static str {
183 $cmd_name
184 }
185
186 fn description(&self) -> &'static str {
187 concat!("Quick select option ", stringify!($num))
188 }
189
190 fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
191 CommandResult::EmitEvent(DynEvent::new(SettingsMenuQuickSelect::new($num)))
192 }
193
194 fn clone_box(&self) -> Box<dyn CommandTrait> {
195 Box::new(*self)
196 }
197
198 fn as_any(&self) -> &dyn std::any::Any {
199 self
200 }
201 }
202 };
203}
204
205quick_select_command!(SettingsMenuQuick1, 1, "settings_menu_quick_1");
206quick_select_command!(SettingsMenuQuick2, 2, "settings_menu_quick_2");
207quick_select_command!(SettingsMenuQuick3, 3, "settings_menu_quick_3");
208quick_select_command!(SettingsMenuQuick4, 4, "settings_menu_quick_4");
209quick_select_command!(SettingsMenuQuick5, 5, "settings_menu_quick_5");
210quick_select_command!(SettingsMenuQuick6, 6, "settings_menu_quick_6");
211quick_select_command!(SettingsMenuQuick7, 7, "settings_menu_quick_7");
212quick_select_command!(SettingsMenuQuick8, 8, "settings_menu_quick_8");
213quick_select_command!(SettingsMenuQuick9, 9, "settings_menu_quick_9");