BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-component / src / dock / invalid_panel.rs

invalid_panel.rs

invalid_panel.rs 1.9 KiB Download Raw
1use gpui::{
2 App, Context, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement as _, Render,
3 SharedString, Styled as _, Window, div,
4};
5use gpui_base::dock::{PanelEvent, PanelState};
6
7use crate::{ActiveTheme as _, dock::Panel};
8
9/// Stands in for a panel this build cannot construct — one whose
10/// `panel_name` no [`PanelRegistry`](gpui_base::dock::PanelRegistry) builder
11/// answers to.
12///
13/// It reports the original [`PanelState`] from
14/// [`dump`](gpui_base::dock::Panel::dump), so a layout written by a build that
15/// knows the panel survives a load and a save here rather than losing it.
16pub(crate) struct InvalidPanel {
17 name: SharedString,
18 focus_handle: FocusHandle,
19 old_state: PanelState,
20}
21
22impl InvalidPanel {
23 pub(crate) fn new(
24 name: impl Into<SharedString>,
25 state: PanelState,
26 cx: &mut Context<Self>,
27 ) -> Self {
28 Self {
29 focus_handle: cx.focus_handle(),
30 name: name.into(),
31 old_state: state,
32 }
33 }
34}
35
36impl gpui_base::dock::Panel for InvalidPanel {
37 fn panel_name(&self) -> &'static str {
38 "InvalidPanel"
39 }
40
41 fn dump(&self, _: &App) -> PanelState {
42 self.old_state.clone()
43 }
44}
45
46impl Panel for InvalidPanel {}
47
48impl EventEmitter<PanelEvent> for InvalidPanel {}
49
50impl Focusable for InvalidPanel {
51 fn focus_handle(&self, _: &App) -> FocusHandle {
52 self.focus_handle.clone()
53 }
54}
55
56impl Render for InvalidPanel {
57 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
58 div()
59 .size_full()
60 .my_6()
61 .flex()
62 .flex_col()
63 .items_center()
64 .justify_center()
65 .text_color(cx.theme().muted_foreground)
66 .child(format!(
67 "The `{}` panel type is not registered in PanelRegistry.",
68 self.name.clone()
69 ))
70 }
71}