reovim_plugin_notification/
command.rs1use reovim_core::{declare_event_command, event_bus::Event};
6
7use crate::notification::NotificationLevel;
8
9#[derive(Debug, Clone)]
11pub struct NotificationShow {
12 pub level: NotificationLevel,
14 pub message: String,
16 pub duration_ms: Option<u64>,
18 pub source: Option<String>,
20}
21
22impl Event for NotificationShow {
23 fn priority(&self) -> u32 {
24 100
25 }
26}
27
28impl NotificationShow {
29 #[must_use]
31 pub fn info(message: impl Into<String>) -> Self {
32 Self {
33 level: NotificationLevel::Info,
34 message: message.into(),
35 duration_ms: None,
36 source: None,
37 }
38 }
39
40 #[must_use]
42 pub fn success(message: impl Into<String>) -> Self {
43 Self {
44 level: NotificationLevel::Success,
45 message: message.into(),
46 duration_ms: None,
47 source: None,
48 }
49 }
50
51 #[must_use]
53 pub fn warning(message: impl Into<String>) -> Self {
54 Self {
55 level: NotificationLevel::Warning,
56 message: message.into(),
57 duration_ms: None,
58 source: None,
59 }
60 }
61
62 #[must_use]
64 pub fn error(message: impl Into<String>) -> Self {
65 Self {
66 level: NotificationLevel::Error,
67 message: message.into(),
68 duration_ms: None,
69 source: None,
70 }
71 }
72}
73
74#[derive(Debug, Clone)]
76pub struct NotificationDismiss {
77 pub id: String,
79}
80
81impl Event for NotificationDismiss {
82 fn priority(&self) -> u32 {
83 100
84 }
85}
86
87declare_event_command! {
89 NotificationDismissAll,
90 id: "notification_dismiss_all",
91 description: "Dismiss all notifications",
92}
93
94#[derive(Debug, Clone)]
96pub struct ProgressUpdate {
97 pub id: String,
99 pub title: String,
101 pub source: String,
103 pub progress: Option<u8>,
105 pub detail: Option<String>,
107}
108
109impl Event for ProgressUpdate {
110 fn priority(&self) -> u32 {
111 100
112 }
113}
114
115impl ProgressUpdate {
116 #[must_use]
118 pub fn new(id: impl Into<String>, title: impl Into<String>, source: impl Into<String>) -> Self {
119 Self {
120 id: id.into(),
121 title: title.into(),
122 source: source.into(),
123 progress: None,
124 detail: None,
125 }
126 }
127
128 #[must_use]
130 pub const fn with_progress(mut self, progress: u8) -> Self {
131 self.progress = Some(progress);
132 self
133 }
134
135 #[must_use]
137 pub fn with_detail(mut self, detail: impl Into<String>) -> Self {
138 self.detail = Some(detail.into());
139 self
140 }
141}
142
143#[derive(Debug, Clone)]
145pub struct ProgressComplete {
146 pub id: String,
148 pub message: Option<String>,
150}
151
152impl Event for ProgressComplete {
153 fn priority(&self) -> u32 {
154 100
155 }
156}
157
158impl ProgressComplete {
159 #[must_use]
161 pub fn new(id: impl Into<String>) -> Self {
162 Self {
163 id: id.into(),
164 message: None,
165 }
166 }
167
168 #[must_use]
170 pub fn with_message(mut self, message: impl Into<String>) -> Self {
171 self.message = Some(message.into());
172 self
173 }
174}