Seperate open and zoom bits conceptually for new panels

co-authored-by: max <max@zed.dev>
This commit is contained in:
Mikayla Maki 2023-05-30 11:52:14 -07:00
parent 1fc9103b61
commit 84f98f13c4
No known key found for this signature in database
2 changed files with 131 additions and 31 deletions

View file

@ -180,7 +180,7 @@ impl Dock {
}
pub fn has_focus(&self, cx: &WindowContext) -> bool {
self.active_panel()
self.visible_panel()
.map_or(false, |panel| panel.has_focus(cx))
}
@ -259,7 +259,7 @@ impl Dock {
cx.focus(&panel);
}
} else if T::should_close_on_event(event)
&& this.active_panel().map_or(false, |p| p.id() == panel.id())
&& this.visible_panel().map_or(false, |p| p.id() == panel.id())
{
this.set_open(false, cx);
}
@ -315,12 +315,16 @@ impl Dock {
}
}
pub fn active_panel(&self) -> Option<&Rc<dyn PanelHandle>> {
let entry = self.active_entry()?;
pub fn visible_panel(&self) -> Option<&Rc<dyn PanelHandle>> {
let entry = self.visible_entry()?;
Some(&entry.panel)
}
fn active_entry(&self) -> Option<&PanelEntry> {
pub fn active_panel(&self) -> Option<&Rc<dyn PanelHandle>> {
Some(&self.panel_entries.get(self.active_panel_index)?.panel)
}
fn visible_entry(&self) -> Option<&PanelEntry> {
if self.is_open {
self.panel_entries.get(self.active_panel_index)
} else {
@ -329,7 +333,7 @@ impl Dock {
}
pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Rc<dyn PanelHandle>> {
let entry = self.active_entry()?;
let entry = self.visible_entry()?;
if entry.panel.is_zoomed(cx) {
Some(entry.panel.clone())
} else {
@ -362,7 +366,7 @@ impl Dock {
}
pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {
if let Some(active_entry) = self.active_entry() {
if let Some(active_entry) = self.visible_entry() {
Empty::new()
.into_any()
.contained()
@ -399,7 +403,7 @@ impl View for Dock {
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(active_entry) = self.active_entry() {
if let Some(active_entry) = self.visible_entry() {
let style = self.style(cx);
ChildView::new(active_entry.panel.as_any(), cx)
.contained()
@ -417,7 +421,7 @@ impl View for Dock {
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
if cx.is_self_focused() {
if let Some(active_entry) = self.active_entry() {
if let Some(active_entry) = self.visible_entry() {
cx.focus(active_entry.panel.as_any());
} else {
cx.focus_parent();