Add Modal::has_focus and introduce a ModalHandle trait object

This commit is contained in:
Antonio Scandurra 2023-07-05 09:39:56 +02:00
parent 25564ea058
commit a8602b2a0c
3 changed files with 38 additions and 0 deletions

View file

@ -97,9 +97,25 @@ lazy_static! {
}
pub trait Modal: View {
fn has_focus(&self) -> bool;
fn dismiss_on_event(event: &Self::Event) -> bool;
}
trait ModalHandle {
fn as_any(&self) -> &AnyViewHandle;
fn has_focus(&self, cx: &WindowContext) -> bool;
}
impl<T: Modal> ModalHandle for ViewHandle<T> {
fn as_any(&self) -> &AnyViewHandle {
self
}
fn has_focus(&self, cx: &WindowContext) -> bool {
self.read(cx).has_focus()
}
}
#[derive(Clone, PartialEq)]
pub struct RemoveWorktreeFromProject(pub WorktreeId);