dock: Keep invalid panel state info avoid missing the state. (#267)
Fix #257
This commit is contained in:
parent
dc3dc4a9ec
commit
3fc0b70639
2 changed files with 13 additions and 5 deletions
|
|
@ -5,18 +5,20 @@ use gpui::{
|
||||||
|
|
||||||
use crate::theme::ActiveTheme as _;
|
use crate::theme::ActiveTheme as _;
|
||||||
|
|
||||||
use super::{Panel, PanelEvent};
|
use super::{DockItemInfo, DockItemState, Panel, PanelEvent};
|
||||||
|
|
||||||
pub(crate) struct InvalidPanel {
|
pub(crate) struct InvalidPanel {
|
||||||
name: SharedString,
|
name: SharedString,
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
|
info: DockItemInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InvalidPanel {
|
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 {
|
Self {
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
name: SharedString::from(name.to_owned()),
|
name: SharedString::from(name.to_owned()),
|
||||||
|
info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,6 +26,12 @@ impl Panel for InvalidPanel {
|
||||||
fn panel_name(&self) -> &'static str {
|
fn panel_name(&self) -> &'static str {
|
||||||
"InvalidPanel"
|
"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 EventEmitter<PanelEvent> for InvalidPanel {}
|
||||||
impl FocusableView for InvalidPanel {
|
impl FocusableView for InvalidPanel {
|
||||||
|
|
|
||||||
|
|
@ -205,8 +205,6 @@ impl DockItemState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_item(&self, dock_area: WeakView<DockArea>, cx: &mut WindowContext) -> DockItem {
|
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 info = self.info.clone();
|
||||||
|
|
||||||
let items: Vec<DockItem> = self
|
let items: Vec<DockItem> = self
|
||||||
|
|
@ -252,7 +250,9 @@ impl DockItemState {
|
||||||
f(dock_area.clone(), info.clone(), cx)
|
f(dock_area.clone(), info.clone(), cx)
|
||||||
} else {
|
} else {
|
||||||
// Show an invalid panel if the panel is not registered.
|
// 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)
|
DockItem::tabs(vec![view.into()], None, &dock_area, cx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue