Disable focus when disconnecting from host
This commit is contained in:
parent
8273865fa3
commit
390ccbc6ad
2 changed files with 13 additions and 2 deletions
|
@ -273,6 +273,7 @@ pub struct Window {
|
||||||
pub(crate) drawing: bool,
|
pub(crate) drawing: bool,
|
||||||
activation_observers: SubscriberSet<(), AnyObserver>,
|
activation_observers: SubscriberSet<(), AnyObserver>,
|
||||||
pub(crate) focus: Option<FocusId>,
|
pub(crate) focus: Option<FocusId>,
|
||||||
|
focus_enabled: bool,
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub(crate) focus_invalidated: bool,
|
pub(crate) focus_invalidated: bool,
|
||||||
|
@ -420,6 +421,7 @@ impl Window {
|
||||||
drawing: false,
|
drawing: false,
|
||||||
activation_observers: SubscriberSet::new(),
|
activation_observers: SubscriberSet::new(),
|
||||||
focus: None,
|
focus: None,
|
||||||
|
focus_enabled: true,
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
focus_invalidated: false,
|
focus_invalidated: false,
|
||||||
|
@ -496,7 +498,7 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Move focus to the element associated with the given `FocusHandle`.
|
/// Move focus to the element associated with the given `FocusHandle`.
|
||||||
pub fn focus(&mut self, handle: &FocusHandle) {
|
pub fn focus(&mut self, handle: &FocusHandle) {
|
||||||
if self.window.focus == Some(handle.id) {
|
if !self.window.focus_enabled || self.window.focus == Some(handle.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,10 +518,19 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Remove focus from all elements within this context's window.
|
/// Remove focus from all elements within this context's window.
|
||||||
pub fn blur(&mut self) {
|
pub fn blur(&mut self) {
|
||||||
|
if !self.window.focus_enabled {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.window.focus = None;
|
self.window.focus = None;
|
||||||
self.notify();
|
self.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn disable_focus(&mut self) {
|
||||||
|
self.blur();
|
||||||
|
self.window.focus_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dispatch_action(&mut self, action: Box<dyn Action>) {
|
pub fn dispatch_action(&mut self, action: Box<dyn Action>) {
|
||||||
let focus_handle = self.focused();
|
let focus_handle = self.focused();
|
||||||
|
|
||||||
|
|
|
@ -502,7 +502,7 @@ impl Workspace {
|
||||||
|
|
||||||
project::Event::DisconnectedFromHost => {
|
project::Event::DisconnectedFromHost => {
|
||||||
this.update_window_edited(cx);
|
this.update_window_edited(cx);
|
||||||
cx.blur();
|
cx.disable_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
project::Event::Closed => {
|
project::Event::Closed => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue