dock: Keep invalid panel state info avoid missing the state. (#267)

Fix #257
This commit is contained in:
Jason Lee 2024-09-23 22:43:02 +08:00 committed by GitHub
parent dc3dc4a9ec
commit 3fc0b70639
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View file

@ -5,18 +5,20 @@ use gpui::{
use crate::theme::ActiveTheme as _;
use super::{Panel, PanelEvent};
use super::{DockItemInfo, DockItemState, Panel, PanelEvent};
pub(crate) struct InvalidPanel {
name: SharedString,
focus_handle: FocusHandle,
info: DockItemInfo,
}
impl InvalidPanel {
pub(crate) fn new(name: &str, cx: &mut WindowContext) -> Self {
pub(crate) fn new(name: &str, info: DockItemInfo, cx: &mut WindowContext) -> Self {
Self {
focus_handle: cx.focus_handle(),
name: SharedString::from(name.to_owned()),
info,
}
}
}
@ -24,6 +26,12 @@ impl Panel for InvalidPanel {
fn panel_name(&self) -> &'static str {
"InvalidPanel"
}
fn dump(&self, _cx: &AppContext) -> super::DockItemState {
let mut state = DockItemState::new(&self.name);
state.info = self.info.clone();
state
}
}
impl EventEmitter<PanelEvent> for InvalidPanel {}
impl FocusableView for InvalidPanel {

View file

@ -205,8 +205,6 @@ impl DockItemState {
}
pub fn to_item(&self, dock_area: WeakView<DockArea>, cx: &mut WindowContext) -> DockItem {
// TODO: Use the empty panel if the panel is not registered, for the compatibility.
let info = self.info.clone();
let items: Vec<DockItem> = self
@ -252,7 +250,9 @@ impl DockItemState {
f(dock_area.clone(), info.clone(), cx)
} else {
// Show an invalid panel if the panel is not registered.
Box::new(cx.new_view(|cx| InvalidPanel::new(&self.panel_name, cx)))
Box::new(
cx.new_view(|cx| InvalidPanel::new(&self.panel_name, info.clone(), cx)),
)
};
DockItem::tabs(vec![view.into()], None, &dock_area, cx)