Implement activate_workspace_for_project

This commit is contained in:
Antonio Scandurra 2023-10-30 14:50:50 +01:00
parent bd750fbbe2
commit e2ee9a28bf
5 changed files with 146 additions and 49 deletions

View file

@ -1,6 +1,6 @@
use crate::{
AnyWindowHandle, AppContext, Context, Executor, Handle, MainThread, ModelContext, Result, Task,
WindowContext,
AnyWindowHandle, AppContext, Component, Context, Executor, Handle, MainThread, ModelContext,
Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle,
};
use anyhow::Context as _;
use derive_more::{Deref, DerefMut};
@ -78,6 +78,19 @@ impl AsyncAppContext {
app_context.update_window(handle, update)
}
pub fn update_window_root<V, R>(
&mut self,
handle: &WindowHandle<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> R,
) -> Result<R>
where
V: 'static,
{
let app = self.app.upgrade().context("app was released")?;
let mut app_context = app.lock();
app_context.update_window_root(handle, update)
}
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut + Send + 'static) -> Task<R>
where
Fut: Future<Output = R> + Send + 'static,
@ -245,6 +258,32 @@ impl Context for AsyncWindowContext {
}
}
impl VisualContext for AsyncWindowContext {
type ViewContext<'a, 'w, V> = ViewContext<'a, 'w, V>;
fn build_view<E, V>(
&mut self,
build_entity: impl FnOnce(&mut Self::ViewContext<'_, '_, V>) -> V,
render: impl Fn(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static,
) -> Self::Result<View<V>>
where
E: Component<V>,
V: 'static + Send,
{
self.app
.update_window(self.window, |cx| cx.build_view(build_entity, render))
}
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, '_, V>) -> R,
) -> Self::Result<R> {
self.app
.update_window(self.window, |cx| cx.update_view(view, update))
}
}
#[cfg(test)]
mod tests {
use super::*;