Add focusable view and restore workspace deserialization. Partially restore split and tab functions

This commit is contained in:
Mikayla 2023-11-15 16:36:43 -08:00
parent e905ababcd
commit 78cea69172
No known key found for this signature in database
14 changed files with 173 additions and 110 deletions

View file

@ -185,6 +185,10 @@ impl Drop for FocusHandle {
}
}
pub trait FocusableView: Render {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
}
// Holds the state for a specific window.
pub struct Window {
pub(crate) handle: AnyWindowHandle,
@ -1550,6 +1554,12 @@ impl VisualContext for WindowContext<'_> {
self.window.root_view = Some(view.clone().into());
view
}
fn focus_view<V: crate::FocusableView>(&mut self, view: &View<V>) -> Self::Result<()> {
self.update_view(view, |view, cx| {
view.focus_handle(cx).clone().focus(cx);
})
}
}
impl<'a> std::ops::Deref for WindowContext<'a> {
@ -2213,9 +2223,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
.set_input_handler(Box::new(input_handler));
}
}
}
impl<V> ViewContext<'_, V> {
pub fn emit<Evt>(&mut self, event: Evt)
where
Evt: 'static,
@ -2228,6 +2236,13 @@ impl<V> ViewContext<'_, V> {
event: Box::new(event),
});
}
pub fn focus_self(&mut self)
where
V: FocusableView,
{
self.defer(|view, cx| view.focus_handle(cx).focus(cx))
}
}
impl<V> Context for ViewContext<'_, V> {
@ -2303,6 +2318,10 @@ impl<V: 'static> VisualContext for ViewContext<'_, V> {
{
self.window_cx.replace_root_view(build_view)
}
fn focus_view<W: FocusableView>(&mut self, view: &View<W>) -> Self::Result<()> {
self.window_cx.focus_view(view)
}
}
impl<'a, V> std::ops::Deref for ViewContext<'a, V> {