mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-25 16:34:48 +01:00
feat: added detach buffer and leave workspace
Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
parent
6e9727128d
commit
487422eb99
2 changed files with 47 additions and 1 deletions
|
@ -144,6 +144,12 @@ impl Client {
|
|||
Ok(ws)
|
||||
}
|
||||
|
||||
/// leaves a [Workspace] by name
|
||||
pub fn leave_workspace(&self, id: &str) -> bool {
|
||||
self.workspaces.remove(id).is_some()
|
||||
}
|
||||
|
||||
/// gets a [Workspace] by name
|
||||
pub fn get_workspace(&self, id: &str) -> Option<Workspace> {
|
||||
self.workspaces.get(id).map(|x| x.clone())
|
||||
}
|
||||
|
|
|
@ -166,6 +166,27 @@ impl Workspace {
|
|||
Ok(controller)
|
||||
}
|
||||
|
||||
/// detach from an active buffer
|
||||
///
|
||||
/// this option will be carried in background: [buffer::worker::BufferWorker] will be stopped and dropped. there
|
||||
/// may still be some events enqueued in buffers to poll, but the [buffer::Controller] itself won't be
|
||||
/// accessible anymore from [Workspace].
|
||||
///
|
||||
/// ### returns
|
||||
/// [DetachResult::NotAttached] if buffer wasn't attached in the first place
|
||||
/// [DetachResult::Detaching] if detach was correctly requested
|
||||
/// [DetachResult::AlreadyDetached] if worker is already stopped
|
||||
pub fn detach(&self, path: &str) -> DetachResult {
|
||||
match self.0.buffers.remove(path) {
|
||||
None => DetachResult::NotAttached,
|
||||
Some((_name, controller)) => if controller.stop() {
|
||||
DetachResult::Detaching
|
||||
} else {
|
||||
DetachResult::AlreadyDetached
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// fetch a list of all buffers in a workspace
|
||||
pub async fn fetch_buffers(&self) -> crate::Result<()> {
|
||||
let mut workspace_client = self.0.services.workspace.clone();
|
||||
|
@ -268,3 +289,22 @@ impl Workspace {
|
|||
self.0.filetree.iter().map(|f| f.clone()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WorkspaceInner {
|
||||
fn drop(&mut self) {
|
||||
for entry in self.buffers.iter() {
|
||||
if !entry.value().stop() {
|
||||
tracing::warn!("could not stop buffer worker {} for workspace {}", entry.value().name(), self.id);
|
||||
}
|
||||
}
|
||||
if !self.cursor.stop() {
|
||||
tracing::warn!("could not stop cursor worker for workspace {}", self.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum DetachResult {
|
||||
NotAttached,
|
||||
Detaching,
|
||||
AlreadyDetached,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue