reovim_plugin_notification/
command.rs

1//! Notification plugin events
2//!
3//! Events for showing/dismissing notifications and progress.
4
5use reovim_core::{declare_event_command, event_bus::Event};
6
7use crate::notification::NotificationLevel;
8
9/// Event to show a notification
10#[derive(Debug, Clone)]
11pub struct NotificationShow {
12    /// Severity level
13    pub level: NotificationLevel,
14    /// Message content
15    pub message: String,
16    /// Duration in milliseconds (None = use default)
17    pub duration_ms: Option<u64>,
18    /// Optional source label
19    pub source: Option<String>,
20}
21
22impl Event for NotificationShow {
23    fn priority(&self) -> u32 {
24        100
25    }
26}
27
28impl NotificationShow {
29    /// Create a new info notification
30    #[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    /// Create a new success notification
41    #[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    /// Create a new warning notification
52    #[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    /// Create a new error notification
63    #[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/// Event to dismiss a specific notification
75#[derive(Debug, Clone)]
76pub struct NotificationDismiss {
77    /// ID of the notification to dismiss
78    pub id: String,
79}
80
81impl Event for NotificationDismiss {
82    fn priority(&self) -> u32 {
83        100
84    }
85}
86
87// Dismiss all command
88declare_event_command! {
89    NotificationDismissAll,
90    id: "notification_dismiss_all",
91    description: "Dismiss all notifications",
92}
93
94/// Event to update progress
95#[derive(Debug, Clone)]
96pub struct ProgressUpdate {
97    /// Unique identifier for this progress
98    pub id: String,
99    /// Title of the operation
100    pub title: String,
101    /// Source of the progress
102    pub source: String,
103    /// Progress percentage (0-100) or None for spinner
104    pub progress: Option<u8>,
105    /// Optional detail text
106    pub detail: Option<String>,
107}
108
109impl Event for ProgressUpdate {
110    fn priority(&self) -> u32 {
111        100
112    }
113}
114
115impl ProgressUpdate {
116    /// Create a new progress update
117    #[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    /// Set the progress percentage
129    #[must_use]
130    pub const fn with_progress(mut self, progress: u8) -> Self {
131        self.progress = Some(progress);
132        self
133    }
134
135    /// Set the detail text
136    #[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/// Event to complete a progress
144#[derive(Debug, Clone)]
145pub struct ProgressComplete {
146    /// ID of the progress to complete
147    pub id: String,
148    /// Optional completion message (will show as success toast)
149    pub message: Option<String>,
150}
151
152impl Event for ProgressComplete {
153    fn priority(&self) -> u32 {
154        100
155    }
156}
157
158impl ProgressComplete {
159    /// Create a new progress complete event
160    #[must_use]
161    pub fn new(id: impl Into<String>) -> Self {
162        Self {
163            id: id.into(),
164            message: None,
165        }
166    }
167
168    /// Set the completion message
169    #[must_use]
170    pub fn with_message(mut self, message: impl Into<String>) -> Self {
171        self.message = Some(message.into());
172        self
173    }
174}