mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Remove ViewContext::is_child
This commit is contained in:
parent
5157442703
commit
9e8f852afb
@ -2833,16 +2833,6 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_child(&self, view: impl Into<AnyViewHandle>) -> bool {
|
||||
let view = view.into();
|
||||
if self.window_id != view.window_id {
|
||||
return false;
|
||||
}
|
||||
self.ancestors(view.view_id)
|
||||
.skip(1) // Skip self id
|
||||
.any(|parent| parent == self.view_id)
|
||||
}
|
||||
|
||||
pub fn blur(&mut self) {
|
||||
let window_id = self.window_id;
|
||||
self.window_context.focus(window_id, None);
|
||||
|
@ -178,11 +178,7 @@ impl Dock {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.set_active(false, cx);
|
||||
});
|
||||
let pane_id = pane.id();
|
||||
cx.subscribe(&pane, move |workspace, _, event, cx| {
|
||||
workspace.handle_pane_event(pane_id, event, cx);
|
||||
})
|
||||
.detach();
|
||||
cx.subscribe(&pane, Workspace::handle_pane_event).detach();
|
||||
|
||||
Self {
|
||||
pane,
|
||||
|
@ -134,6 +134,7 @@ pub enum Event {
|
||||
RemoveItem { item_id: usize },
|
||||
Split(SplitDirection),
|
||||
ChangeItemTitle,
|
||||
Focus,
|
||||
}
|
||||
|
||||
pub struct Pane {
|
||||
@ -1797,6 +1798,7 @@ impl View for Pane {
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(Event::Focus);
|
||||
self.toolbar.update(cx, |toolbar, cx| {
|
||||
toolbar.pane_focus_update(true, cx);
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ use crate::{
|
||||
persistence::model::{SerializedPane, SerializedPaneGroup, SerializedWorkspace},
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, warn};
|
||||
use log::warn;
|
||||
use notifications::{NotificationHandle, NotifyResultExt};
|
||||
pub use pane::*;
|
||||
pub use pane_group::*;
|
||||
@ -524,11 +524,7 @@ impl Workspace {
|
||||
|
||||
let center_pane = cx
|
||||
.add_view(|cx| Pane::new(weak_handle.clone(), None, app_state.background_actions, cx));
|
||||
let pane_id = center_pane.id();
|
||||
cx.subscribe(¢er_pane, move |this, _, event, cx| {
|
||||
this.handle_pane_event(pane_id, event, cx)
|
||||
})
|
||||
.detach();
|
||||
cx.subscribe(¢er_pane, Self::handle_pane_event).detach();
|
||||
cx.focus(¢er_pane);
|
||||
cx.emit(Event::PaneAdded(center_pane.clone()));
|
||||
let dock = Dock::new(
|
||||
@ -1420,11 +1416,7 @@ impl Workspace {
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let pane_id = pane.id();
|
||||
cx.subscribe(&pane, move |this, _, event, cx| {
|
||||
this.handle_pane_event(pane_id, event, cx)
|
||||
})
|
||||
.detach();
|
||||
cx.subscribe(&pane, Self::handle_pane_event).detach();
|
||||
self.panes.push(pane.clone());
|
||||
cx.focus(&pane);
|
||||
cx.emit(Event::PaneAdded(pane.clone()));
|
||||
@ -1621,11 +1613,10 @@ impl Workspace {
|
||||
|
||||
fn handle_pane_event(
|
||||
&mut self,
|
||||
pane_id: usize,
|
||||
pane: ViewHandle<Pane>,
|
||||
event: &pane::Event,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
if let Some(pane) = self.pane(pane_id) {
|
||||
let is_dock = &pane == self.dock.pane();
|
||||
match event {
|
||||
pane::Event::Split(direction) if !is_dock => {
|
||||
@ -1655,13 +1646,13 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
}
|
||||
pane::Event::Focus => {
|
||||
self.handle_pane_focused(pane.clone(), cx);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.serialize_workspace(cx);
|
||||
} else if self.dock.visible_pane().is_none() {
|
||||
error!("pane {} not found", pane_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn split_pane(
|
||||
@ -1760,10 +1751,6 @@ impl Workspace {
|
||||
&self.panes
|
||||
}
|
||||
|
||||
fn pane(&self, pane_id: usize) -> Option<ViewHandle<Pane>> {
|
||||
self.panes.iter().find(|pane| pane.id() == pane_id).cloned()
|
||||
}
|
||||
|
||||
pub fn active_pane(&self) -> &ViewHandle<Pane> {
|
||||
&self.active_pane
|
||||
}
|
||||
@ -2783,17 +2770,9 @@ impl View for Workspace {
|
||||
.into_any_named("workspace")
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
if cx.is_self_focused() {
|
||||
cx.focus(&self.active_pane);
|
||||
} else {
|
||||
for pane in self.panes() {
|
||||
let view = view.clone();
|
||||
if pane.update(cx, |_, cx| view.id() == cx.view_id() || cx.is_child(view)) {
|
||||
self.handle_pane_focused(pane.clone(), cx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user