Implement MultiBuffer::save

This is still not integrated with `workspace::ItemView`.
This commit is contained in:
Antonio Scandurra 2021-12-17 16:11:18 +01:00
parent 7d2b74a93b
commit 6685d5aa7d

View file

@ -16,7 +16,7 @@ use std::{
ops::{Range, Sub}, ops::{Range, Sub},
str, str,
sync::Arc, sync::Arc,
time::{Duration, Instant, SystemTime}, time::{Duration, Instant},
}; };
use sum_tree::{Bias, Cursor, SumTree}; use sum_tree::{Bias, Cursor, SumTree};
use text::{ use text::{
@ -663,13 +663,18 @@ impl MultiBuffer {
cx.emit(event.clone()); cx.emit(event.clone());
} }
pub fn save( pub fn save(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
&mut self, let mut save_tasks = Vec::new();
cx: &mut ModelContext<Self>, for BufferState { buffer, .. } in self.buffers.values() {
) -> Result<Task<Result<(clock::Global, SystemTime)>>> { save_tasks.push(buffer.update(cx, |buffer, cx| buffer.save(cx))?);
self.as_singleton() }
.unwrap()
.update(cx, |buffer, cx| buffer.save(cx)) Ok(cx.spawn(|_, _| async move {
for save in save_tasks {
save.await?;
}
Ok(())
}))
} }
pub fn language<'a>(&self, cx: &'a AppContext) -> Option<&'a Arc<Language>> { pub fn language<'a>(&self, cx: &'a AppContext) -> Option<&'a Arc<Language>> {