Make theme selector eagerly display the selected theme

This commit is contained in:
Keith Simmons 2022-03-08 18:42:31 -08:00
parent 03aa906068
commit b440a51675
3 changed files with 78 additions and 18 deletions

View file

@ -754,20 +754,26 @@ impl Workspace {
})
}
pub fn toggle_modal<V, F>(&mut self, cx: &mut ViewContext<Self>, add_view: F)
// Returns the model that was toggled closed if it was open
pub fn toggle_modal<V, F>(&mut self, cx: &mut ViewContext<Self>, add_view: F) -> Option<ViewHandle<V>>
where
V: 'static + View,
F: FnOnce(&mut ViewContext<Self>, &mut Self) -> ViewHandle<V>,
{
if self.modal.as_ref().map_or(false, |modal| modal.is::<V>()) {
self.modal.take();
cx.notify();
// Whatever modal was visible is getting clobbered. If its the same type as V, then return
// it. Otherwise, create a new modal and set it as active.
let already_open_modal = self.modal.take()
.and_then(|modal| modal.downcast::<V>());
if let Some(already_open_modal) = already_open_modal {
cx.focus_self();
Some(already_open_modal)
} else {
let modal = add_view(cx, self);
cx.focus(&modal);
self.modal = Some(modal.into());
None
}
cx.notify();
}
pub fn modal(&self) -> Option<&AnyViewHandle> {