codemp/src/api/event.rs

35 lines
1.1 KiB
Rust
Raw Normal View History

2024-09-04 21:37:35 +02:00
//! # Event
//! Real time notification of changes in a workspace, to either users or buffers
use codemp_proto::workspace::workspace_event::Event as WorkspaceEventInner;
2024-09-04 21:37:35 +02:00
/// Event in a [crate::Workspace]
2024-08-15 20:15:37 +02:00
#[derive(Debug, Clone)]
#[cfg_attr(feature = "python", pyo3::pyclass)]
pub enum Event {
2024-09-04 21:37:35 +02:00
/// Fired when the file tree changes
/// containes the modified buffer path (deleted or created or renamed)
FileTreeUpdated(String),
2024-09-04 21:37:35 +02:00
/// Fired when an user joins the current workspace
UserJoin(String),
2024-09-04 21:37:35 +02:00
/// Fired when an user leaves the current workspace
UserLeave(String),
}
2024-08-22 00:57:24 +02:00
impl From<WorkspaceEventInner> for Event {
fn from(event: WorkspaceEventInner) -> Self {
match event {
2024-08-22 00:57:24 +02:00
WorkspaceEventInner::Join(e) => Self::UserJoin(e.user.name),
WorkspaceEventInner::Leave(e) => Self::UserLeave(e.user.name),
WorkspaceEventInner::Create(e) => Self::FileTreeUpdated(e.path),
WorkspaceEventInner::Delete(e) => Self::FileTreeUpdated(e.path),
WorkspaceEventInner::Rename(e) => Self::FileTreeUpdated(e.after),
}
}
}
2024-08-22 00:57:24 +02:00
impl From<&WorkspaceEventInner> for Event {
fn from(event: &WorkspaceEventInner) -> Self {
Self::from(event.clone())
}
}