Do not panic when focusing empty dock
This commit is contained in:
parent
ea708c50f0
commit
75324abbb5
2 changed files with 17 additions and 8 deletions
|
@ -133,13 +133,13 @@ pub struct Dock {
|
||||||
panel_entries: Vec<PanelEntry>,
|
panel_entries: Vec<PanelEntry>,
|
||||||
is_open: bool,
|
is_open: bool,
|
||||||
active_panel_index: usize,
|
active_panel_index: usize,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
focus_subscription: Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FocusableView for Dock {
|
impl FocusableView for Dock {
|
||||||
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
|
fn focus_handle(&self, _: &AppContext) -> FocusHandle {
|
||||||
self.panel_entries[self.active_panel_index]
|
self.focus_handle.clone()
|
||||||
.panel
|
|
||||||
.focus_handle(cx)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,12 +190,20 @@ pub struct PanelButtons {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dock {
|
impl Dock {
|
||||||
pub fn new(position: DockPosition) -> Self {
|
pub fn new(position: DockPosition, cx: &mut ViewContext<'_, Self>) -> Self {
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| {
|
||||||
|
if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) {
|
||||||
|
active_entry.panel.focus_handle(cx).focus(cx)
|
||||||
|
}
|
||||||
|
});
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
panel_entries: Default::default(),
|
panel_entries: Default::default(),
|
||||||
active_panel_index: 0,
|
active_panel_index: 0,
|
||||||
is_open: false,
|
is_open: false,
|
||||||
|
focus_handle,
|
||||||
|
focus_subscription,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +215,7 @@ impl Dock {
|
||||||
self.is_open
|
self.is_open
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo!()
|
||||||
// pub fn has_focus(&self, cx: &WindowContext) -> bool {
|
// pub fn has_focus(&self, cx: &WindowContext) -> bool {
|
||||||
// self.visible_panel()
|
// self.visible_panel()
|
||||||
// .map_or(false, |panel| panel.has_focus(cx))
|
// .map_or(false, |panel| panel.has_focus(cx))
|
||||||
|
|
|
@ -566,9 +566,9 @@ impl Workspace {
|
||||||
|
|
||||||
cx.emit(Event::WorkspaceCreated(weak_handle.clone()));
|
cx.emit(Event::WorkspaceCreated(weak_handle.clone()));
|
||||||
|
|
||||||
let left_dock = cx.build_view(|_| Dock::new(DockPosition::Left));
|
let left_dock = cx.build_view(|cx| Dock::new(DockPosition::Left, cx));
|
||||||
let bottom_dock = cx.build_view(|_| Dock::new(DockPosition::Bottom));
|
let bottom_dock = cx.build_view(|cx| Dock::new(DockPosition::Bottom, cx));
|
||||||
let right_dock = cx.build_view(|_| Dock::new(DockPosition::Right));
|
let right_dock = cx.build_view(|cx| Dock::new(DockPosition::Right, cx));
|
||||||
let left_dock_buttons =
|
let left_dock_buttons =
|
||||||
cx.build_view(|cx| PanelButtons::new(left_dock.clone(), weak_handle.clone(), cx));
|
cx.build_view(|cx| PanelButtons::new(left_dock.clone(), weak_handle.clone(), cx));
|
||||||
let bottom_dock_buttons =
|
let bottom_dock_buttons =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue